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: working sample 04 #92

Closed
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
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jupiter = "5.10.0"
openTelemetry = "1.18.0"
restAssured = "5.3.1"
rsApi = "3.1.0"
testcontainers = "1.18.3"


[libraries]
Expand Down Expand Up @@ -61,6 +62,8 @@ junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", vers
junit-pioneer = { module = "org.junit-pioneer:junit-pioneer", version.ref = "junit-pioneer" }
opentelemetry-annotations = { module = "io.opentelemetry:opentelemetry-extension-annotations", version.ref = "openTelemetry" }
restAssured = { module = "io.rest-assured:rest-assured", version.ref = "restAssured" }
testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" }
testcontainers-junit-jupiter = { module = "org.testcontainers:junit-jupiter", version.ref = "testcontainers" }

[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
4 changes: 4 additions & 0 deletions system-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {

testImplementation(libs.awaitility)
testImplementation(libs.restAssured)
testImplementation(libs.testcontainers)
testImplementation(libs.testcontainers.junit.jupiter)

// runtimes
testCompileOnly(project(":basic:basic-01-basic-connector"))
Expand All @@ -31,4 +33,6 @@ dependencies {
testCompileOnly(project(":transfer:transfer-01-file-transfer:file-transfer-provider"))
testCompileOnly(project(":transfer:transfer-02-file-transfer-listener:file-transfer-listener-consumer"))
testCompileOnly(project(":transfer:transfer-03-modify-transferprocess:modify-transferprocess-consumer"))
testCompileOnly(project(":transfer:transfer-04-open-telemetry:open-telemetry-consumer"))
testCompileOnly(project(":transfer:transfer-04-open-telemetry:open-telemetry-provider"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ void assertTransferProcessStatusConsumerSide(String transferProcessId) {
* This method corresponds to the command in the sample: {@code curl -X POST -H "Content-Type: application/json" -H "X-Api-Key: password" -d @transfer/transfer-01-file-transfer/contractoffer.json "http://localhost:9192/management/v2/contractnegotiations"}
*/
void initiateContractNegotiation() {
initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
}

void initiateContractNegotiation(String contractOfferFilePath) {
contractNegotiationId = given()
.headers(API_KEY_HEADER_KEY, API_KEY_HEADER_VALUE)
.contentType(ContentType.JSON)
.body(new File(TestUtils.findBuildRoot(), CONTRACT_OFFER_FILE_PATH))
.body(new File(TestUtils.findBuildRoot(), contractOfferFilePath))
.when()
.post(MANAGEMENT_API_URL + "/v2/contractnegotiations")
.then()
Expand Down Expand Up @@ -167,8 +171,8 @@ void lookUpContractAgreementId() {
*
* @throws IOException Thrown if there was an error accessing the transfer request file defined in {@link FileTransferSampleTestCommon#TRANSFER_FILE_PATH}.
*/
String requestTransferFile() throws IOException {
var transferJsonFile = getFileFromRelativePath(TRANSFER_FILE_PATH);
String requestTransferFile(String transferFilePath) throws IOException {
var transferJsonFile = getFileFromRelativePath(transferFilePath);
var requestBody = readAndUpdateDataRequestFromJsonFile(transferJsonFile, contractAgreementId);

var jsonPath = given()
Expand All @@ -191,6 +195,10 @@ String requestTransferFile() throws IOException {
return transferProcessId;
}

String requestTransferFile() throws IOException {
return requestTransferFile(TRANSFER_FILE_PATH);
}

/**
* Reads a transfer request file with changed value for contract agreement ID and file destination path.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2023 imec
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* imec
*
*/

package org.eclipse.edc.samples.transfer;

import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Testcontainers;



@EndToEndTest
@Testcontainers
public class Transfer04openTelemetryTest {

private static final String SAMPLE_FOLDER = "transfer/transfer-04-open-telemetry";
static final String CONTRACT_OFFER_FILE_PATH = SAMPLE_FOLDER + "/contractoffer.json";

static final String TRANSFER_FILE_PATH = SAMPLE_FOLDER + "/filetransfer.json";

static final String SAMPLE_ASSET_FILE_PATH = SAMPLE_FOLDER + "/README.md";
static final String DESTINATION_FILE_PATH = "transfer/requested.test.txt";
final FileTransferSampleTestCommon testUtils = new FileTransferSampleTestCommon(SAMPLE_ASSET_FILE_PATH, DESTINATION_FILE_PATH);

@ClassRule
public static DockerComposeContainer environment =
new DockerComposeContainer(FileTransferSampleTestCommon.getFileFromRelativePath("transfer/transfer-04-open-telemetry/docker-compose.yaml")).withLocalCompose(true)
.waitingFor("consumer", Wait.forLogMessage(".*ready.*", 1));

@BeforeAll
static void setUp() {
environment.start();
}

@Test
void runSampleSteps() throws Exception {
testUtils.assertTestPrerequisites();
testUtils.initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
testUtils.lookUpContractAgreementId();
var transferProcessId = testUtils.requestTransferFile(TRANSFER_FILE_PATH);
testUtils.assertDestinationFileContent();
// next one fails with "No checker found for process error (related to https://github.com/eclipse-edc/Connector/issues/3334 ?)
// testUtils.assertTransferProcessStatusConsumerSide(transferProcessId);
}

@AfterEach
protected void tearDown() {
testUtils.cleanTemporaryTestFiles();
}
}
49 changes: 14 additions & 35 deletions transfer/transfer-04-open-telemetry/contractoffer.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
{
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/",
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@type": "NegotiationInitiateRequestDto",
"connectorId": "provider",
"consumerId": "consumer",
"providerId": "provider",
"connectorAddress": "http://provider:8282/protocol",
"protocol": "dataspace-protocol-http",
"offer": {
"offerId": "1:3a75736e-001d-4364-8bd4-9888490edb58",
"offerId": "1:test-document:3a75736e-001d-4364-8bd4-9888490edb58",
"assetId": "test-document",
"policy": {
"uid": "956e172f-2de1-4501-8881-057a57fd0e69",
"permissions": [
{
"edctype": "dataspaceconnector:permission",
"uid": null,
"target": "test-document",
"action": {
"type": "USE",
"includedIn": null,
"constraint": null
},
"assignee": null,
"assigner": null,
"constraints": [],
"duties": []
}
],
"prohibitions": [],
"obligations": [],
"extensibleProperties": {},
"inheritsFrom": null,
"assigner": null,
"assignee": null,
"target": null,
"@type": {
"@policytype": "set"
}
},
"asset": {
"properties": {
"ids:byteSize": null,
"asset:prop:id": "test-document",
"ids:fileName": null
}
"@id": "1:test-document:13dce0f1-52ed-4554-a194-e83e92733ee5",
"@type": "set",
"odrl:permission": [],
"odrl:prohibition": [],
"odrl:obligation": [],
"odrl:target": "test-document"
}
}
}
16 changes: 10 additions & 6 deletions transfer/transfer-04-open-telemetry/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ services:
WEB_HTTP_PATH: /api
WEB_HTTP_MANAGEMENT_PORT: 9192
WEB_HTTP_MANAGEMENT_PATH: /management
WEB_HTTP_IDS_PORT: 9292
WEB_HTTP_IDS_PATH: /protocol
IDS_WEBHOOK_ADDRESS: http://consumer:9292
WEB_HTTP_PROTOCOL_PORT: 9292
WEB_HTTP_PROTOCOL_PATH: /protocol
EDC_DSP_CALLBACK_ADDRESS: http://consumer:9292/protocol
EDC_PARTICIPANT_ID: consumer
EDC_API_AUTH_KEY: password
volumes:
- ../:/samples
Expand All @@ -37,8 +38,11 @@ services:
WEB_HTTP_PATH: /api
WEB_HTTP_MANAGEMENT_PORT: 8182
WEB_HTTP_MANAGEMENT_PATH: /management
IDS_WEBHOOK_ADDRESS: http://provider:8282
EDC_SAMPLES_TRANSFER_01_ASSET_PATH: /samples/transfer-04-open-telemetry/input-file.txt
WEB_HTTP_PROTOCOL_PORT: 8282
WEB_HTTP_PROTOCOL_PATH: /protocol
EDC_DSP_CALLBACK_ADDRESS: http://provider:8282/protocol
EDC_PARTICIPANT_ID: provider
EDC_SAMPLES_TRANSFER_01_ASSET_PATH: /samples/transfer-04-open-telemetry/README.md
volumes:
- ../:/samples
ports:
Expand All @@ -56,7 +60,7 @@ services:

prometheus:
image: prom/prometheus:v2.30.3
container_name: prometheus
# container_name: prometheus # does not work with testcontainers
volumes:
- ./prometheus/:/etc/prometheus/
ports:
Expand Down
23 changes: 12 additions & 11 deletions transfer/transfer-04-open-telemetry/filetransfer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/"
},
"@type": "TransferRequestDto",
"dataDestination": {
"type": "File",
"path": "/samples/requested.test.txt",
"keyName": "keyName"
},
"protocol": "dataspace-protocol-http",
"assetId": "test-document",
"contractId": "{agreement ID}",
"dataDestination": {
"path": "/samples/output-file.txt",
"keyName": "keyName",
"type": "File"
},
"transferType": {
"contentType": "application/octet-stream",
"isFinite": true
},
"managedResources": false,
"connectorId": "provider",
"connectorAddress": "http://provider:8282/protocol",
"connectorId": "consumer"
"privateProperties": {},
"managedResources": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {

dependencies {
implementation(libs.edc.control.plane.core)
implementation(libs.edc.data.plane.selector.core)
implementation(libs.edc.micrometer.core)

implementation(libs.edc.configuration.filesystem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins {

dependencies {
implementation(libs.edc.control.plane.core)
implementation(libs.edc.data.plane.selector.core)

implementation(libs.edc.api.observability)

Expand Down