-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): adds E2E tests to the CI (#294)
* feat(test): add e2e test * checkstyle * run e2e tests on push * enable verbosity
- Loading branch information
1 parent
0c90667
commit 2c7701c
Showing
9 changed files
with
259 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2024 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
testImplementation(libs.edc.junit) | ||
testImplementation(libs.jakarta.json.api) | ||
testImplementation(libs.jackson.datatype.jakarta.jsonp) | ||
testImplementation(libs.parsson) | ||
testImplementation(libs.restAssured) | ||
testImplementation(libs.awaitility) | ||
} |
151 changes: 151 additions & 0 deletions
151
tests/end2end/src/test/java/org/eclipse/edc/demo/tests/transfer/TransferEndToEndTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (c) 2024 Metaform Systems, Inc. | ||
* | ||
* 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: | ||
* Metaform Systems, Inc. - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.demo.tests.transfer; | ||
|
||
import io.restassured.specification.RequestSpecification; | ||
import jakarta.json.Json; | ||
import org.eclipse.edc.junit.annotations.EndToEndTest; | ||
import org.eclipse.edc.junit.testfixtures.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.http.ContentType.JSON; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
/** | ||
* This test is designed to run against an MVD deployed in a Kubernetes cluster, with an active ingress controller. | ||
* The cluster MUST be deployed and seeded according to the README before running this test! | ||
*/ | ||
@EndToEndTest | ||
public class TransferEndToEndTest { | ||
// Management API base URL of the consumer connector, goes through Ingress controller | ||
private static final String CONSUMER_MANAGEMENT_URL = "http://127.0.0.1/consumer/cp"; | ||
// Catalog Query API URL of the consumer connector, goes through ingress controller | ||
private static final String CONSUMER_CATALOG_URL = "http://127.0.0.1/consumer/fc"; | ||
// DSP service URL of the provider, not reachable outside the cluster | ||
private static final String PROVIDER_DSP_URL = "http://provider-qna-controlplane:8082"; | ||
// DID of the provider company | ||
private static final String PROVIDER_ID = "did:web:provider-identityhub%3A7083:provider"; | ||
// public API endpoint of the provider-qna connector, goes through the incress controller | ||
private static final String PROVIDER_PUBLIC_URL = "http://127.0.0.1/provider-qna/public"; | ||
private static final Duration TEST_TIMEOUT_DURATION = Duration.ofSeconds(60); | ||
|
||
private static RequestSpecification baseRequest() { | ||
return given() | ||
.header("X-Api-Key", "password") | ||
.contentType(JSON) | ||
.when(); | ||
} | ||
|
||
@Test | ||
void transferData() { | ||
var emptyQueryBody = Json.createObjectBuilder() | ||
.add("@context", Json.createObjectBuilder().add("edc", "https://w3id.org/edc/v0.0.1/ns/")) | ||
.add("@type", "QuerySpec") | ||
.build(); | ||
var offerId = new AtomicReference<String>(); | ||
// get catalog, extract offer ID | ||
await().atMost(TEST_TIMEOUT_DURATION) | ||
.untilAsserted(() -> { | ||
var oid = baseRequest() | ||
.body(emptyQueryBody) | ||
.post(CONSUMER_CATALOG_URL + "/api/catalog/v1alpha/catalog/query") | ||
.then() | ||
.log().ifError() | ||
.statusCode(200) | ||
// yes, it's a bit brittle with the hardcoded indexes, but it appears to work. | ||
.extract().body().jsonPath().getString("[0]['http://www.w3.org/ns/dcat#dataset'][1]['http://www.w3.org/ns/dcat#dataset'][0]['odrl:hasPolicy']['@id']"); | ||
|
||
assertThat(oid).isNotNull(); | ||
offerId.set(oid); | ||
}); | ||
|
||
// initiate negotiation | ||
var negotiationRequest = TestUtils.getResourceFileContentAsString("negotiation-request.json") | ||
.replace("{{PROVIDER_ID}}", PROVIDER_ID) | ||
.replace("{{PROVIDER_DSP_URL}}", PROVIDER_DSP_URL) | ||
.replace("{{OFFER_ID}}", offerId.get()); | ||
var negotiationId = baseRequest() | ||
.body(negotiationRequest) | ||
.post(CONSUMER_MANAGEMENT_URL + "/api/management/v3/contractnegotiations") | ||
.then() | ||
.log().ifError() | ||
.statusCode(200) | ||
.extract().body().jsonPath().getString("@id"); | ||
assertThat(negotiationId).isNotNull(); | ||
|
||
//wait until negotiation is FINALIZED | ||
var agreementId = new AtomicReference<String>(); | ||
await().atMost(TEST_TIMEOUT_DURATION) | ||
.untilAsserted(() -> { | ||
var jp = baseRequest() | ||
.get(CONSUMER_MANAGEMENT_URL + "/api/management/v3/contractnegotiations/" + negotiationId) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().jsonPath(); | ||
var state = jp.getString("state"); | ||
assertThat(state).isEqualTo("FINALIZED"); | ||
agreementId.set(jp.getString("contractAgreementId")); | ||
|
||
}); | ||
|
||
//start transfer process | ||
var tpRequest = TestUtils.getResourceFileContentAsString("transfer-request.json") | ||
.replace("{{PROVIDER_ID}}", PROVIDER_ID) | ||
.replace("{{PROVIDER_DSP_URL}}", PROVIDER_DSP_URL) | ||
.replace("{{CONTRACT_ID}}", agreementId.get()); | ||
|
||
var transferProcessId = baseRequest() | ||
.body(tpRequest) | ||
.post(CONSUMER_MANAGEMENT_URL + "/api/management/v3/transferprocesses") | ||
.then() | ||
.log().ifError() | ||
.statusCode(200) | ||
.extract().body().jsonPath().getString("@id"); | ||
|
||
// fetch EDR for transfer process | ||
var endpoint = new AtomicReference<String>(); | ||
var token = new AtomicReference<String>(); | ||
await().atMost(TEST_TIMEOUT_DURATION) | ||
.untilAsserted(() -> { | ||
var jp = baseRequest() | ||
.get(CONSUMER_MANAGEMENT_URL + "/api/management/v3/edrs/%s/dataaddress".formatted(transferProcessId)) | ||
.then() | ||
.statusCode(200) | ||
.extract().body().jsonPath(); | ||
|
||
endpoint.set(jp.getString("endpoint")); | ||
token.set(jp.getString("authorization")); | ||
|
||
assertThat(endpoint.get()).isNotNull().endsWith("/api/public"); | ||
assertThat(token.get()).isNotNull(); | ||
}); | ||
|
||
//download exemplary JSON data from public endpoint | ||
var response = given() | ||
.header("Authorization", token.get()) | ||
.get(PROVIDER_PUBLIC_URL + "/api/public") | ||
.then() | ||
.log().ifError() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
|
||
assertThat(response).isNotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"@context": { | ||
"@vocab": "https://w3id.org/edc/v0.0.1/ns/" | ||
}, | ||
"@type": "https://w3id.org/edc/v0.0.1/ns/ContractRequest", | ||
"counterPartyAddress": "{{PROVIDER_DSP_URL}}/api/dsp", | ||
"counterPartyId": "{{PROVIDER_ID}}", | ||
"protocol": "dataspace-protocol-http", | ||
"policy": { | ||
"@context": "http://www.w3.org/ns/odrl.jsonld", | ||
"@type": "http://www.w3.org/ns/odrl/2/Offer", | ||
"@id": "{{OFFER_ID}}", | ||
"assigner": "{{PROVIDER_ID}}", | ||
"permission": [], | ||
"prohibition": [], | ||
"odrl:obligation": { | ||
"odrl:action": { | ||
"@id": "use" | ||
}, | ||
"odrl:constraint": { | ||
"odrl:leftOperand": { | ||
"@id": "FrameworkCredential.pcf" | ||
}, | ||
"odrl:operator": { | ||
"@id": "odrl:eq" | ||
}, | ||
"odrl:rightOperand": "active" | ||
} | ||
}, | ||
"target": "asset-1" | ||
}, | ||
"callbackAddresses": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"@context": { | ||
"odrl": "http://www.w3.org/ns/odrl/2/" | ||
}, | ||
"assetId": "asset-1", | ||
"counterPartyAddress": "{{PROVIDER_DSP_URL}}/api/dsp", | ||
"connectorId": "{{PROVIDER_ID}}", | ||
"contractId": "{{CONTRACT_ID}}", | ||
"dataDestination": { | ||
"type": "HttpProxy" | ||
}, | ||
"protocol": "dataspace-protocol-http", | ||
"transferType": "HttpData-PULL" | ||
} |
This file was deleted.
Oops, something went wrong.