From 1d55b7c2ef109a7b94a9ae2ea124e79ea6fbeb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= <2605803+klumbe@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:13:36 +0100 Subject: [PATCH] fix: add missing json fields for sample streaming http-to-http (#335) * fix: add missing assigner to contract request #244 * fix: add missing transferType to transfer request #334 * fix: use json in test case for streaming01 * fix: checksytle for Streaming01 test --- .../streaming/Streaming01httpToHttpTest.java | 26 ++++++---- .../streaming/StreamingParticipant.java | 47 +++++++++++++++++++ .../negotiate-contract.json | 15 +++--- .../streaming-01-http-to-http/transfer.json | 3 +- 4 files changed, 74 insertions(+), 17 deletions(-) diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java index 8068c5f7..58cc538f 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.samples.transfer.streaming; -import jakarta.json.Json; import okhttp3.mockwebserver.MockWebServer; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; @@ -97,14 +96,23 @@ void streamData() throws IOException { PROVIDER.createPolicyDefinition(getFileContentFromRelativePath(SAMPLE_FOLDER + "/policy-definition.json")); PROVIDER.createContractDefinition(getFileContentFromRelativePath(SAMPLE_FOLDER + "/contract-definition.json")); - var destination = Json.createObjectBuilder() - .add("type", "HttpData") - .add("baseUrl", "http://localhost:" + httpReceiverPort) - .build(); - var transferProcessId = CONSUMER.requestAssetFrom("stream-asset", PROVIDER) - .withDestination(destination) - .withTransferType("HttpData-PUSH") - .execute(); + var catalogDatasetId = CONSUMER.fetchDatasetFromCatalog(getFileContentFromRelativePath(SAMPLE_FOLDER + "/get-dataset.json")); + var negotiateContractBody = getFileContentFromRelativePath(SAMPLE_FOLDER + "/negotiate-contract.json") + .replace("{{offerId}}", catalogDatasetId); + + var contractNegotiationId = CONSUMER.negotiateContract(negotiateContractBody); + + await().atMost(TIMEOUT).untilAsserted(() -> { + var contractAgreementId = CONSUMER.getContractAgreementId(contractNegotiationId); + assertThat(contractAgreementId).isNotNull(); + }); + var contractAgreementId = CONSUMER.getContractAgreementId(contractNegotiationId); + + var requestBody = getFileContentFromRelativePath(SAMPLE_FOLDER + "/transfer.json") + .replace("{{contract-agreement-id}}", contractAgreementId) + .replace("4000", "" + httpReceiverPort); + + var transferProcessId = CONSUMER.startTransfer(requestBody); await().atMost(TIMEOUT).untilAsserted(() -> { var state = CONSUMER.getTransferProcessState(transferProcessId); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java index 8325a345..c1f8718a 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java @@ -70,6 +70,53 @@ public String createContractDefinition(String requestBody) { .extract().jsonPath().getString(ID); } + public String fetchDatasetFromCatalog(String requestBody) { + return managementEndpoint.baseRequest() + .contentType(JSON) + .body(requestBody) + .when() + .post("/v3/catalog/dataset/request") + .then() + .statusCode(200) + .contentType(JSON) + .extract().jsonPath().getString("'odrl:hasPolicy'.@id"); + } + + public String negotiateContract(String requestBody) { + return managementEndpoint.baseRequest() + .contentType(JSON) + .body(requestBody) + .when() + .post("/v3/contractnegotiations/") + .then() + .statusCode(200) + .contentType(JSON) + .extract().jsonPath().getString(ID); + } + + public String getContractAgreementId(String contractNegotiationId) { + return managementEndpoint.baseRequest() + .contentType(JSON) + .when() + .get("/v3/contractnegotiations/" + contractNegotiationId) + .then() + .statusCode(200) + .contentType(JSON) + .extract().jsonPath().getString("contractAgreementId"); + } + + public String startTransfer(String requestBody) { + return managementEndpoint.baseRequest() + .contentType(JSON) + .body(requestBody) + .when() + .post("/v3/transferprocesses") + .then() + .statusCode(200) + .contentType(JSON) + .extract().jsonPath().getString(ID); + } + public static class Builder

> extends Participant.Builder { protected Builder(P participant) { diff --git a/transfer/streaming/streaming-01-http-to-http/negotiate-contract.json b/transfer/streaming/streaming-01-http-to-http/negotiate-contract.json index 43c42a2e..1eef8295 100644 --- a/transfer/streaming/streaming-01-http-to-http/negotiate-contract.json +++ b/transfer/streaming/streaming-01-http-to-http/negotiate-contract.json @@ -1,18 +1,19 @@ { "@context": { - "@vocab": "https://w3id.org/edc/v0.0.1/ns/", - "odrl": "http://www.w3.org/ns/odrl/2/" + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" }, "@type": "ContractRequest", "counterPartyAddress": "http://localhost:18182/protocol", "providerId": "provider", "protocol": "dataspace-protocol-http", "policy": { + "@context": "http://www.w3.org/ns/odrl.jsonld", "@id": "{{offerId}}", "@type": "Offer", - "odrl:permission": [], - "odrl:prohibition": [], - "odrl:obligation": [], - "odrl:target": "stream-asset" -} + "permission": [], + "prohibition": [], + "obligation": [], + "assigner": "provider", + "target": "stream-asset" + } } diff --git a/transfer/streaming/streaming-01-http-to-http/transfer.json b/transfer/streaming/streaming-01-http-to-http/transfer.json index dbbd2692..5d89d89d 100644 --- a/transfer/streaming/streaming-01-http-to-http/transfer.json +++ b/transfer/streaming/streaming-01-http-to-http/transfer.json @@ -11,5 +11,6 @@ "assetId": "stream-asset", "contractId": "{{contract-agreement-id}}", "connectorId": "provider", - "counterPartyAddress": "http://localhost:18182/protocol" + "counterPartyAddress": "http://localhost:18182/protocol", + "transferType": "HttpData-PUSH" }