Skip to content

Commit

Permalink
fix: add missing json fields for sample streaming http-to-http (#335)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
klumbe authored Nov 11, 2024
1 parent 6ee7c3e commit 1d55b7c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<P extends StreamingParticipant, B extends Builder<P, B>> extends Participant.Builder<P, B> {

protected Builder(P participant) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 2 additions & 1 deletion transfer/streaming/streaming-01-http-to-http/transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 1d55b7c

Please sign in to comment.