Skip to content

Commit

Permalink
refactor: extract e2e-fixtures module
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Oct 18, 2024
1 parent 27e6b15 commit 3fe0075
Show file tree
Hide file tree
Showing 49 changed files with 80 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -23,42 +23,40 @@ plugins {
}

dependencies {
// api modules that the test classes may need
testFixturesApi(project(":spi:edr-spi"))
testFixturesApi(project(":edc-extensions:edr:edr-api-v2"))
testFixturesApi(project(":spi:core-spi"))
testFixturesApi(project(":spi:tokenrefresh-spi"))
testFixturesApi(project(":spi:bdrs-client-spi"))
testFixturesApi(project(":spi:core-spi"))
testFixturesApi(project(":spi:edr-spi"))
testFixturesApi(project(":edc-extensions:agreements:retirement-evaluation-spi"))
testFixturesApi(project(":edc-extensions:bpn-validation:bpn-validation-spi"))

testFixturesApi(libs.edc.spi.core)

testFixturesApi(libs.edc.core.token)
testFixturesApi(libs.edc.identity.trust.sts.embedded)
testFixturesApi(libs.edc.junit)
testFixturesApi(libs.edc.lib.cryptocommon)
testFixturesApi(libs.edc.lib.jws2020)
testFixturesApi(libs.edc.lib.util)
testFixturesApi(libs.edc.aws.s3.core)
testFixturesApi(libs.edc.spi.edrstore)
testFixturesApi(libs.edc.spi.jsonld)
testFixturesApi(libs.edc.spi.policy)
testFixturesApi(libs.edc.spi.contract)
testFixturesApi(libs.edc.spi.transfer)
testFixturesApi(testFixtures(libs.edc.api.management.test.fixtures))
testFixturesApi(libs.edc.spi.edrstore)
testFixturesApi(libs.edc.lib.cryptocommon)
testFixturesApi(libs.edc.lib.boot)

// api modules for some test utils
testFixturesApi(libs.assertj)
testFixturesApi(libs.awaitility)
testFixturesApi(libs.aws.s3)
testFixturesApi(libs.azure.storage.blob)
testFixturesApi(libs.jakartaJson)
testFixturesApi(libs.junit.jupiter.api)
testFixturesApi(libs.junit.jupiter.params)
testFixturesApi(libs.netty.mockserver)
testFixturesApi(libs.edc.junit)
testFixturesApi(libs.postgres)
testFixturesApi(libs.restAssured)
testFixturesApi(libs.awaitility)

testFixturesImplementation(libs.edc.identity.trust.sts.embedded)
testFixturesImplementation(libs.edc.core.token)
testFixturesImplementation(libs.edc.spi.identity.did)
testFixturesImplementation(libs.postgres)
testFixturesImplementation(libs.testcontainers.postgres)
testFixturesImplementation(libs.assertj)
testFixturesImplementation(libs.junit.jupiter.api)
testFixturesImplementation(project(":edc-extensions:bpn-validation:bpn-validation-spi"))
testFixturesImplementation(project(":edc-extensions:agreements:retirement-evaluation-spi"))

testCompileOnly(project(":edc-tests:runtime:runtime-memory"))
testCompileOnly(project(":edc-tests:runtime:runtime-postgresql"))
testFixturesApi(libs.testcontainers.junit)
testFixturesApi(libs.testcontainers.postgres)
}

// do not publish
edcBuild {
publish.set(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.tests.transfer;
package org.eclipse.tractusx.edc.tests.aws;

import org.testcontainers.containers.GenericContainer;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -17,7 +17,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

package org.eclipse.tractusx.edc.dataplane.transfer.test;
package org.eclipse.tractusx.edc.tests.azure;

import com.azure.core.util.BinaryData;
import com.azure.storage.blob.BlobContainerClient;
Expand All @@ -43,7 +43,7 @@ public class AzureBlobHelper {
private final int port;
private BlobServiceClient blobServiceClient;

public AzureBlobHelper(String accountName, String key, String host, int port) {
AzureBlobHelper(String accountName, String key, String host, int port) {
this.accountName = accountName;
this.key = key;
this.host = host;
Expand All @@ -54,25 +54,14 @@ public BlobContainerClient createContainer(String containerName) {
return blobClient().createBlobContainer(containerName);
}

private BlobServiceClient blobClient() {
if (blobServiceClient == null) {
var endpoint = "http://%s:%s/%s".formatted(host, port, accountName);
blobServiceClient = new BlobServiceClientBuilder()
.credential(new StorageSharedKeyCredential(accountName, key))
.endpoint(endpoint)
.buildClient();
}
return blobServiceClient;
public void uploadBlob(BlobContainerClient client, BinaryData data, String targetBlobName) {
client.getBlobClient(targetBlobName).upload(data, true);
}

public void uploadBlob(BlobContainerClient client, InputStream inputStream, String targetBlobName) {
client.getBlobClient(targetBlobName).upload(inputStream, true);
}

public void uploadBlob(BlobContainerClient client, BinaryData data, String targetBlobName) {
client.getBlobClient(targetBlobName).upload(data, true);
}

public List<String> listBlobs(String container) {
if (blobClient().listBlobContainers().stream().noneMatch(bci -> bci.getName().equalsIgnoreCase(container))) {
return List.of();
Expand All @@ -84,11 +73,22 @@ public List<String> listBlobs(String container) {
.toList();
}

private BlobServiceClient blobClient() {
if (blobServiceClient == null) {
var endpoint = "http://%s:%s/%s".formatted(host, port, accountName);
blobServiceClient = new BlobServiceClientBuilder()
.credential(new StorageSharedKeyCredential(accountName, key))
.endpoint(endpoint)
.buildClient();
}
return blobServiceClient;
}

public String generateAccountSas(String containerName) {
var expiry = OffsetDateTime.MAX.minusDays(1);
var permissions = BlobContainerSasPermission.parse("w");
var vals = new BlobServiceSasSignatureValues(expiry, permissions);
return blobClient().getBlobContainerClient(containerName).generateSas(vals);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.eclipse.tractusx.edc.tests.transfer;
package org.eclipse.tractusx.edc.tests.azure;

import org.testcontainers.containers.GenericContainer;

import java.util.Arrays;
import java.util.List;

import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
import static org.eclipse.tractusx.edc.tests.transfer.AzureToAzureEndToEndTest.AZURITE_DOCKER_IMAGE;

public class AzuriteContainer extends GenericContainer<AzuriteContainer> {

private static final String IMAGE_NAME = "mcr.microsoft.com/azure-storage/azurite";
private final int containerPort = 10_000;

public AzuriteContainer(int azuriteHostPort, Account... accounts) {
super(AZURITE_DOCKER_IMAGE);
var azuriteAccounts = Arrays.stream(accounts).map(it -> "%s:%s".formatted(it.name, it.key)).collect(joining(";"));
addEnv("AZURITE_ACCOUNTS", azuriteAccounts);
super(IMAGE_NAME);
addEnv("AZURITE_ACCOUNTS", stream(accounts).map(it -> "%s:%s".formatted(it.name, it.key)).collect(joining(";")));
setPortBindings(List.of("%d:%d".formatted(azuriteHostPort, containerPort)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ void httpPushDataTransfer() {

var destination = httpDataAddress(consumerUrl);

var transferProcessId = consumer().requestAsset(provider(), assetId, createObjectBuilder().build(), destination, "HttpData-PUSH");
var transferProcessId = consumer()
.requestAssetFrom(assetId, provider())
.withDestination(destination)
.withTransferType("HttpData-PUSH")
.execute();
await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> {
var state = consumer().getTransferProcessState(transferProcessId);
assertThat(state).isEqualTo(COMPLETED.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))

testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.junit)
Expand Down
2 changes: 1 addition & 1 deletion edc-tests/edc-controlplane/catalog-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))

testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.junit)
Expand Down
5 changes: 4 additions & 1 deletion edc-tests/edc-controlplane/edr-api-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(project(":spi:tokenrefresh-spi"))

testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))
testImplementation(libs.edc.spi.edrstore)

testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.junit)
Expand Down
2 changes: 1 addition & 1 deletion edc-tests/edc-controlplane/iatp-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))
testImplementation(libs.edc.identity.trust.sts.embedded)
testImplementation(libs.edc.ih.did)
testImplementation(libs.edc.ih.spi)
Expand Down
2 changes: 1 addition & 1 deletion edc-tests/edc-controlplane/policy-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))

testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.junit)
Expand Down
2 changes: 1 addition & 1 deletion edc-tests/edc-controlplane/transfer-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {

dependencies {
testImplementation(project(":spi:bdrs-client-spi"))
testImplementation(testFixtures(project(":edc-tests:edc-controlplane:fixtures")))
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))

testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {
}

dependencies {
testImplementation(testFixtures(project(":edc-tests:e2e-fixtures")))

testImplementation(libs.edc.junit)
testImplementation(libs.restAssured)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.tractusx.edc.tests.azure.AzureBlobHelper;
import org.eclipse.tractusx.edc.tests.azure.AzuriteContainer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.tractusx.edc.tests.aws.MinioContainer;
import org.eclipse.tractusx.edc.tests.azure.AzureBlobHelper;
import org.eclipse.tractusx.edc.tests.azure.AzuriteContainer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.tractusx.edc.tests.aws.MinioContainer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down
Loading

0 comments on commit 3fe0075

Please sign in to comment.