Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing json fields for sample streaming http-to-http #335

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
Loading