Skip to content

Commit

Permalink
fix: use json in test case for streaming01
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Nov 7, 2024
1 parent 4b0d194 commit 2f00b9d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 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,24 @@ 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);
//assertThat(catalogDatasetId).isEqualTo("test", 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 @@ -18,6 +18,7 @@

import static io.restassured.http.ContentType.JSON;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.hamcrest.Matchers.theInstance;

/**
* Essentially a wrapper around the management API enabling to test interactions with other participants, eg. catalog, transfer...
Expand Down Expand Up @@ -70,6 +71,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

0 comments on commit 2f00b9d

Please sign in to comment.