Skip to content

Commit

Permalink
Fix E2E Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSteinert committed Dec 13, 2023
1 parent 9bf6625 commit ba381ef
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Mercedes-Benz Tech Innovation GmbH - Sample workflow test
* Fraunhofer Institute for Software and Systems Engineering - use current ids instead of placeholder
*
*/

Expand All @@ -19,7 +20,7 @@
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -32,11 +33,7 @@
import static org.assertj.core.api.Assertions.fail;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath;
import static org.eclipse.edc.samples.common.NegotiationCommon.createAsset;
import static org.eclipse.edc.samples.common.NegotiationCommon.createContractDefinition;
import static org.eclipse.edc.samples.common.NegotiationCommon.createPolicy;
import static org.eclipse.edc.samples.common.NegotiationCommon.getContractAgreementId;
import static org.eclipse.edc.samples.common.NegotiationCommon.negotiateContract;
import static org.eclipse.edc.samples.common.NegotiationCommon.*;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.runPrerequisites;
import static org.eclipse.edc.samples.util.TransferUtil.checkTransferStatus;
import static org.eclipse.edc.samples.util.TransferUtil.startTransfer;
Expand All @@ -46,13 +43,14 @@
public class Advanced01openTelemetryTest {

private static final String DOCKER_COMPOSE_YAML = "advanced/advanced-01-open-telemetry/docker-compose.yaml";
private static final String FETCH_DATASET_FROM_CATALOG_FILE_PATH = "advanced/advanced-01-open-telemetry/resources/get-dataset.json";
private static final String NEGOTIATE_CONTRACT_FILE_PATH = "advanced/advanced-01-open-telemetry/resources/negotiate-contract.json";
private static final String START_TRANSFER_FILE_PATH = "advanced/advanced-01-open-telemetry/resources/start-transfer.json";
private static final String JAEGER_URL = "http://localhost:16686";

@Container
public static DockerComposeContainer<?> environment =
new DockerComposeContainer<>(getFileFromRelativePath(DOCKER_COMPOSE_YAML))
public static ComposeContainer environment =
new ComposeContainer(getFileFromRelativePath(DOCKER_COMPOSE_YAML))
.withLocalCompose(true)
.waitingFor("consumer", Wait.forLogMessage(".*ready.*", 1));

Expand All @@ -67,7 +65,8 @@ void runSampleSteps() {
createAsset();
createPolicy();
createContractDefinition();
var contractNegotiationId = negotiateContract(NEGOTIATE_CONTRACT_FILE_PATH);
var catalogDatasetId = fetchDatasetFromCatalog(FETCH_DATASET_FROM_CATALOG_FILE_PATH);
var contractNegotiationId = negotiateContract(NEGOTIATE_CONTRACT_FILE_PATH, catalogDatasetId);
var contractAgreementId = getContractAgreementId(contractNegotiationId);
var transferProcessId = startTransfer(getFileContentFromRelativePath(START_TRANSFER_FILE_PATH), contractAgreementId);
checkTransferStatus(transferProcessId, TransferProcessStates.STARTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Mercedes-Benz Tech Innovation GmbH - Initial implementation
* Fraunhofer Institute for Software and Systems Engineering - use current ids instead of placeholder
*
*/

Expand All @@ -33,12 +34,14 @@ public class NegotiationCommon {
private static final String V2_POLICY_DEFINITIONS_PATH = "/v2/policydefinitions";
private static final String CREATE_CONTRACT_DEFINITION_FILE_PATH = "transfer/transfer-01-negotiation/resources/create-contract-definition.json";
private static final String V2_CONTRACT_DEFINITIONS_PATH = "/v2/contractdefinitions";
private static final String FETCH_CATALOG_FILE_PATH = "transfer/transfer-01-negotiation/resources/fetch-catalog.json";
private static final String V2_CATALOG_REQUEST_PATH = "/v2/catalog/request";
private static final String V2_CATALOG_DATASET_REQUEST_PATH = "/v2/catalog/dataset/request";
private static final String FETCH_DATASET_FROM_CATALOG_FILE_PATH = "transfer/transfer-01-negotiation/resources/get-dataset.json";
private static final String CATALOG_DATASET_ID = "\"odrl:hasPolicy\".'@id'";
private static final String NEGOTIATE_CONTRACT_FILE_PATH = "transfer/transfer-01-negotiation/resources/negotiate-contract.json";
private static final String V2_CONTRACT_NEGOTIATIONS_PATH = "/v2/contractnegotiations/";
private static final String CONTRACT_NEGOTIATION_ID = "@id";
private static final String CONTRACT_AGREEMENT_ID = "contractAgreementId";
private static final String CONTRACT_NEGOTIATION_ID_KEY = "\\{\\{contract-negotiation-id\\}\\}";

public static void createAsset() {
post(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V3_ASSETS_PATH, getFileContentFromRelativePath(CREATE_ASSET_FILE_PATH));
Expand All @@ -52,20 +55,28 @@ public static void createContractDefinition() {
post(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V2_CONTRACT_DEFINITIONS_PATH, getFileContentFromRelativePath(CREATE_CONTRACT_DEFINITION_FILE_PATH));
}

public static void fetchCatalog() {
post(PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CATALOG_REQUEST_PATH, getFileContentFromRelativePath(FETCH_CATALOG_FILE_PATH));
public static String fetchDatasetFromCatalog(String fetchDatasetFromCatalogFilePath) {
var catalogDatasetId = post(
PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CATALOG_DATASET_REQUEST_PATH,
getFileContentFromRelativePath(fetchDatasetFromCatalogFilePath),
CATALOG_DATASET_ID
);
assertThat(catalogDatasetId).isNotEmpty();
return catalogDatasetId;
}

public static String negotiateContract(String negotiateContractFilePath) {
var contractNegotiationId = post(PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CONTRACT_NEGOTIATIONS_PATH, getFileContentFromRelativePath(negotiateContractFilePath), CONTRACT_NEGOTIATION_ID);
public static String negotiateContract(String negotiateContractFilePath, String catalogDatasetId) {
var requestBody = getFileContentFromRelativePath(negotiateContractFilePath)
.replaceAll(CONTRACT_NEGOTIATION_ID_KEY, catalogDatasetId);
var contractNegotiationId = post(
PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CONTRACT_NEGOTIATIONS_PATH,
requestBody,
CONTRACT_NEGOTIATION_ID
);
assertThat(contractNegotiationId).isNotEmpty();
return contractNegotiationId;
}

public static String negotiateContract() {
return negotiateContract(NEGOTIATE_CONTRACT_FILE_PATH);
}

public static String getContractAgreementId(String contractNegotiationId) {
String url = PrerequisitesCommon.CONSUMER_MANAGEMENT_URL + V2_CONTRACT_NEGOTIATIONS_PATH + contractNegotiationId;
return await()
Expand All @@ -78,8 +89,8 @@ public static String runNegotiation() {
createAsset();
createPolicy();
createContractDefinition();
fetchCatalog();
var contractNegotiationId = negotiateContract();
var catalogDatasetId = fetchDatasetFromCatalog(FETCH_DATASET_FROM_CATALOG_FILE_PATH);
var contractNegotiationId = negotiateContract(NEGOTIATE_CONTRACT_FILE_PATH, catalogDatasetId);
return getContractAgreementId(contractNegotiationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Mercedes-Benz Tech Innovation GmbH - Sample workflow test
* Fraunhofer Institute for Software and Systems Engineering - use current ids instead of placeholder
*
*/

Expand All @@ -23,7 +24,7 @@
import static org.eclipse.edc.samples.common.NegotiationCommon.createAsset;
import static org.eclipse.edc.samples.common.NegotiationCommon.createContractDefinition;
import static org.eclipse.edc.samples.common.NegotiationCommon.createPolicy;
import static org.eclipse.edc.samples.common.NegotiationCommon.fetchCatalog;
import static org.eclipse.edc.samples.common.NegotiationCommon.fetchDatasetFromCatalog;
import static org.eclipse.edc.samples.common.NegotiationCommon.getContractAgreementId;
import static org.eclipse.edc.samples.common.NegotiationCommon.negotiateContract;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.getConsumer;
Expand All @@ -39,14 +40,17 @@ public class Transfer01negotiationTest {
@RegisterExtension
static EdcRuntimeExtension consumer = getConsumer();

private static final String NEGOTIATE_CONTRACT_FILE_PATH = "transfer/transfer-01-negotiation/resources/negotiate-contract.json";
private static final String FETCH_DATASET_FROM_CATALOG_FILE_PATH = "transfer/transfer-01-negotiation/resources/get-dataset.json";

@Test
void runSampleSteps() {
runPrerequisites();
createAsset();
createPolicy();
createContractDefinition();
fetchCatalog();
var contractNegotiationId = negotiateContract();
var catalogDatasetId = fetchDatasetFromCatalog(FETCH_DATASET_FROM_CATALOG_FILE_PATH);
var contractNegotiationId = negotiateContract(NEGOTIATE_CONTRACT_FILE_PATH, catalogDatasetId);
var contractAgreementId = getContractAgreementId(contractNegotiationId);
assertThat(contractAgreementId).isNotEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Mercedes-Benz Tech Innovation GmbH - Initial implementation
* Fraunhofer Institute for Software and Systems Engineering - use current ids instead of placeholder
*
*/

Expand All @@ -35,7 +36,7 @@ public class TransferUtil {
public static final Duration POLL_INTERVAL = Duration.ofMillis(500);

private static final String TRANSFER_PROCESS_ID = "@id";
private static final String CONTRACT_AGREEMENT_ID_KEY = "<contract agreement id>";
private static final String CONTRACT_AGREEMENT_ID_KEY = "\\{\\{contract-agreement-id\\}\\}";
private static final String V2_TRANSFER_PROCESSES_PATH = "/v2/transferprocesses/";
private static final String EDC_STATE = "state";

Expand Down
2 changes: 1 addition & 1 deletion transfer/transfer-01-negotiation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ state, the negotiation is finished. We can now use the UUID to check the current
negotiation using an endpoint on the consumer side.

```bash
curl -X GET "http://localhost:29193/management/v2/contractnegotiations/<contract negotiation id, returned by the negotiation call>" \
curl -X GET "http://localhost:29193/management/v2/contractnegotiations/{{contract-negotiation-id}}" \
--header 'Content-Type: application/json' \
-s | jq
```
Expand Down
7 changes: 7 additions & 0 deletions transfer/transfer-01-negotiation/resources/get-dataset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@context": { "@vocab": "https://w3id.org/edc/v0.0.1/ns/" },
"@type": "DatasetRequest",
"@id": "assetId",
"counterPartyAddress": "http://localhost:19194/protocol",
"protocol": "dataspace-protocol-http"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"protocol": "dataspace-protocol-http",
"policy": {
"@context": "http://www.w3.org/ns/odrl.jsonld",
"@id": "MQ==:YXNzZXRJZA==:YTc4OGEwYjMtODRlZi00NWYwLTgwOWQtMGZjZTMwMGM3Y2Ey",
"@id": "{{contract-negotiation-id}}",
"@type": "Set",
"permission": [],
"prohibition": [],
Expand Down
2 changes: 1 addition & 1 deletion transfer/transfer-02-consumer-pull/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ to get the data from the provider:
"id": "591bb609-1edb-4a6b-babe-50f1eca3e1e9",
"endpoint": "http://localhost:29291/public/",
"authKey": "Authorization",
"authCode": "<auth code>",
"authCode": "{{auth-code}}",
"properties": {
"cid": "1:1e47895f-9025-49e1-971d-eb865c38d540"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@type": "TransferRequestDto",
"connectorId": "provider",
"counterPartyAddress": "http://localhost:19194/protocol",
"contractId": "<contract agreement id>",
"contractId": "{{contract-agreement-id}}",
"assetId": "assetId",
"protocol": "dataspace-protocol-http",
"dataDestination": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@type": "TransferRequestDto",
"connectorId": "provider",
"counterPartyAddress": "http://localhost:19194/protocol",
"contractId": "<contract agreement id>",
"contractId": "{{contract-agreement-id}}",
"assetId": "assetId",
"protocol": "dataspace-protocol-http",
"dataDestination": {
Expand Down
2 changes: 1 addition & 1 deletion transfer/transfer-04-event-consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ curl -d @transfer/transfer-01-negotiation/resources/negotiate-contract.json \
### 3. Get the contract agreement id

```bash
curl -X GET "http://localhost:29193/management/v2/contractnegotiations/<contract negotiation id, returned by the negotiation call>" \
curl -X GET "http://localhost:29193/management/v2/contractnegotiations/{{contract-negotiation-id}}" \
--header 'Content-Type: application/json' \
-s | jq
```
Expand Down

0 comments on commit ba381ef

Please sign in to comment.