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

ci(test): avoid use of deprecated class #1629

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

Expand All @@ -52,17 +51,13 @@
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_TYPE;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_ACCOUNT_KEY;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_ACCOUNT_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_CONTAINER_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_KEY_ALIAS;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_PROVIDER_ACCOUNT_KEY;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_PROVIDER_ACCOUNT_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_PROVIDER_CONTAINER_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_PROVIDER_KEY_ALIAS;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZURITE_CONTAINER_PORT;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZURITE_DOCKER_IMAGE;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.CONSUMER_AZURITE_ACCOUNT;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.PREFIX_FOR_MUTIPLE_FILES;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.PROVIDER_AZURITE_ACCOUNT;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.TESTFILE_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.blobDestinationAddress;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.blobSourceAddress;
Expand Down Expand Up @@ -92,22 +87,22 @@ public class AzureToAzureTest {
RuntimeConfig.Azure.blobstoreDataplaneConfig("/control", PROVIDER_CONTROL_PORT, AZURITE_HOST_PORT),
":edc-tests:runtime:dataplane-cloud"
)).registerServiceMock(Monitor.class, spy(new ConsoleMonitor("AzureBlob-Dataplane", ConsoleMonitor.Level.DEBUG, true)));

/**
* Currently we have to use one container to host both consumer and provider accounts, because we cannot handle
* two different endpoint templates for provider and consumer. Endpoint templates are configured globally.
* Also, the host-port must be fixed/deterministic, as the {@code PROVIDER_RUNTIME} needs to know it in advance
*/
@Container
private final FixedHostPortGenericContainer<?> azuriteContainer = new FixedHostPortGenericContainer<>(AZURITE_DOCKER_IMAGE)
.withFixedExposedPort(AZURITE_HOST_PORT, AZURITE_CONTAINER_PORT)
.withEnv("AZURITE_ACCOUNTS", AZBLOB_PROVIDER_ACCOUNT_NAME + ":" + AZBLOB_PROVIDER_ACCOUNT_KEY + ";" + AZBLOB_CONSUMER_ACCOUNT_NAME + ":" + AZBLOB_CONSUMER_ACCOUNT_KEY);
private final AzuriteContainer azuriteContainer = new AzuriteContainer(AZURITE_HOST_PORT, PROVIDER_AZURITE_ACCOUNT, CONSUMER_AZURITE_ACCOUNT);

private AzureBlobHelper providerBlobHelper;
private AzureBlobHelper consumerBlobHelper;

@BeforeEach
void setup() {
providerBlobHelper = new AzureBlobHelper(AZBLOB_PROVIDER_ACCOUNT_NAME, AZBLOB_PROVIDER_ACCOUNT_KEY, azuriteContainer.getHost(), azuriteContainer.getMappedPort(AZURITE_CONTAINER_PORT));
consumerBlobHelper = new AzureBlobHelper(AZBLOB_CONSUMER_ACCOUNT_NAME, AZBLOB_CONSUMER_ACCOUNT_KEY, azuriteContainer.getHost(), azuriteContainer.getMappedPort(AZURITE_CONTAINER_PORT));
providerBlobHelper = azuriteContainer.getHelper(PROVIDER_AZURITE_ACCOUNT);
consumerBlobHelper = azuriteContainer.getHelper(CONSUMER_AZURITE_ACCOUNT);
}

@Test
Expand All @@ -120,7 +115,7 @@ void transferMultipleFile_success(Vault vault) {
fileNames.forEach(filename -> providerBlobHelper.uploadBlob(sourceContainer, fileData, filename));

consumerBlobHelper.createContainer(AZBLOB_CONSUMER_CONTAINER_NAME);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, AZBLOB_PROVIDER_ACCOUNT_KEY);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, PROVIDER_AZURITE_ACCOUNT.key());
vault.storeSecret(AZBLOB_CONSUMER_KEY_ALIAS, """
{"sas": "%s","edctype":"dataspaceconnector:azuretoken"}
""".formatted(consumerBlobHelper.generateAccountSas(AZBLOB_CONSUMER_CONTAINER_NAME)));
Expand Down Expand Up @@ -157,7 +152,7 @@ void transferFile_success(Vault vault) {
// create container in consumer's blob store
consumerBlobHelper.createContainer(AZBLOB_CONSUMER_CONTAINER_NAME);

vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, AZBLOB_PROVIDER_ACCOUNT_KEY);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, PROVIDER_AZURITE_ACCOUNT.key());
vault.storeSecret(AZBLOB_CONSUMER_KEY_ALIAS, """
{"sas": "%s","edctype":"dataspaceconnector:azuretoken"}
""".formatted(consumerBlobHelper.generateAccountSas(AZBLOB_CONSUMER_CONTAINER_NAME)));
Expand Down Expand Up @@ -205,7 +200,7 @@ void transferFile_largeFile(long sizeBytes, Vault vault) throws IOException {
// create container in consumer's blob store
consumerBlobHelper.createContainer(AZBLOB_CONSUMER_CONTAINER_NAME);

vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, AZBLOB_PROVIDER_ACCOUNT_KEY);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, PROVIDER_AZURITE_ACCOUNT.key());
vault.storeSecret(AZBLOB_CONSUMER_KEY_ALIAS, """
{"sas": "%s","edctype":"dataspaceconnector:azuretoken"}
""".formatted(consumerBlobHelper.generateAccountSas(AZBLOB_CONSUMER_CONTAINER_NAME)));
Expand All @@ -231,7 +226,7 @@ void transferFile_largeFile(long sizeBytes, Vault vault) throws IOException {
@Test
void transferFolder_targetFolderNotExists_shouldCreate(Vault vault) {

vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, AZBLOB_PROVIDER_ACCOUNT_KEY);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, PROVIDER_AZURITE_ACCOUNT.key());
var sas = consumerBlobHelper.generateAccountSas(AZBLOB_CONSUMER_CONTAINER_NAME);
vault.storeSecret(AZBLOB_CONSUMER_KEY_ALIAS, """
{"sas": "%s","edctype":"dataspaceconnector:azuretoken"}
Expand Down Expand Up @@ -275,7 +270,7 @@ void transferFile_targetContainerNotExist_shouldFail(Vault vault) {

providerBlobHelper.uploadBlob(sourceContainer, fileData, TESTFILE_NAME);

vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, AZBLOB_PROVIDER_ACCOUNT_KEY);
vault.storeSecret(AZBLOB_PROVIDER_KEY_ALIAS, PROVIDER_AZURITE_ACCOUNT.key());
vault.storeSecret(AZBLOB_CONSUMER_KEY_ALIAS, """
{"sas": "%s","edctype":"dataspaceconnector:azuretoken"}
""".formatted(consumerBlobHelper.generateAccountSas(AZBLOB_CONSUMER_CONTAINER_NAME)));
Expand All @@ -292,7 +287,7 @@ void transferFile_targetContainerNotExist_shouldFail(Vault vault) {
await().pollInterval(Duration.ofSeconds(2))
.atMost(Duration.ofSeconds(10))
.untilAsserted(() -> verify(DATAPLANE_RUNTIME.getService(Monitor.class))
.severe(contains("Error creating blob %s on account %s".formatted(TESTFILE_NAME, AZBLOB_CONSUMER_ACCOUNT_NAME)), isA(IOException.class)));
.severe(contains("Error creating blob %s on account %s".formatted(TESTFILE_NAME, CONSUMER_AZURITE_ACCOUNT.name())), isA(IOException.class)));
}

private JsonObjectBuilder createFlowRequestBuilder(String blobName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 Cofinity-X
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

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

import org.testcontainers.containers.GenericContainer;

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

import static java.util.stream.Collectors.joining;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZURITE_CONTAINER_PORT;

public class AzuriteContainer extends GenericContainer<AzuriteContainer> {

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

public AzureBlobHelper getHelper(Account account) {
return new AzureBlobHelper(account.name(), account.key(), getHost(), getMappedPort(AZURITE_CONTAINER_PORT));
}

public record Account(String name, String key) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import software.amazon.awssdk.regions.Region;
Expand All @@ -55,10 +54,9 @@
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_TYPE;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_ACCOUNT_KEY;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_ACCOUNT_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_CONTAINER_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.AZBLOB_CONSUMER_KEY_ALIAS;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.CONSUMER_AZURITE_ACCOUNT;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.PREFIX_FOR_MUTIPLE_FILES;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.S3_CONSUMER_BUCKET_NAME;
import static org.eclipse.tractusx.edc.dataplane.transfer.test.TestConstants.TESTFILE_NAME;
Expand All @@ -73,9 +71,6 @@ public class MultiCloudTest {
public static final String BUCKET_NAME = S3_CONSUMER_BUCKET_NAME;
public static final String BLOB_KEY_ALIAS = AZBLOB_CONSUMER_KEY_ALIAS;

// Azure Blob test constants
private static final String BLOB_ACCOUNT_NAME = AZBLOB_CONSUMER_ACCOUNT_NAME;
private static final String BLOB_ACCOUNT_KEY = AZBLOB_CONSUMER_ACCOUNT_KEY;
private static final int AZURITE_HOST_PORT = getFreePort();
private static final String BLOB_CONTAINER_NAME = AZBLOB_CONSUMER_CONTAINER_NAME;

Expand All @@ -93,17 +88,15 @@ public class MultiCloudTest {
private final MinioContainer s3Container = new MinioContainer();

@Container
private final FixedHostPortGenericContainer<?> azuriteContainer = new FixedHostPortGenericContainer<>(TestConstants.AZURITE_DOCKER_IMAGE)
.withFixedExposedPort(AZURITE_HOST_PORT, 10000)
.withEnv("AZURITE_ACCOUNTS", BLOB_ACCOUNT_NAME + ":" + BLOB_ACCOUNT_KEY);
private final AzuriteContainer azuriteContainer = new AzuriteContainer(AZURITE_HOST_PORT, CONSUMER_AZURITE_ACCOUNT);

private AzureBlobHelper blobStoreHelper;
private S3Client s3Client;
private String s3EndpointOverride;

@BeforeEach
void setup() {
blobStoreHelper = new AzureBlobHelper(BLOB_ACCOUNT_NAME, BLOB_ACCOUNT_KEY, azuriteContainer.getHost(), azuriteContainer.getMappedPort(10000));
blobStoreHelper = azuriteContainer.getHelper(CONSUMER_AZURITE_ACCOUNT);
s3EndpointOverride = "http://localhost:%s/".formatted(s3Container.getFirstMappedPort());
var providerConfig = AwsClientProviderConfiguration.Builder.newInstance()
.endpointOverride(URI.create(s3EndpointOverride))
Expand All @@ -121,7 +114,7 @@ void transferFile_azureToS3MultipleFiles(Vault vault) {
var fileNames = IntStream.rangeClosed(1, 2).mapToObj(i -> PREFIX_FOR_MUTIPLE_FILES + i + '_' + TESTFILE_NAME).toList();
fileNames.forEach(filename -> blobStoreHelper.uploadBlob(sourceContainer, fileData, filename));

vault.storeSecret(BLOB_KEY_ALIAS, BLOB_ACCOUNT_KEY);
vault.storeSecret(BLOB_KEY_ALIAS, CONSUMER_AZURITE_ACCOUNT.key());

var destinationBucket = s3Client.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build());
assertThat(destinationBucket.sdkHttpResponse().isSuccessful()).isTrue();
Expand All @@ -135,7 +128,7 @@ void transferFile_azureToS3MultipleFiles(Vault vault) {
.add("dspace:endpointType", "AzureStorage")
.add("dspace:endpointProperties", Json.createArrayBuilder()
.add(dspaceProperty(EDC_NAMESPACE + "container", BLOB_CONTAINER_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", BLOB_ACCOUNT_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", CONSUMER_AZURITE_ACCOUNT.name()))
.add(dspaceProperty(EDC_NAMESPACE + "keyName", BLOB_KEY_ALIAS))
.add(dspaceProperty(EDC_NAMESPACE + "blobPrefix", PREFIX_FOR_MUTIPLE_FILES))
)
Expand Down Expand Up @@ -176,7 +169,7 @@ void transferFile_azureToS3(Vault vault) {
var fileData = BinaryData.fromString(TestUtils.getResourceFileContentAsString(TESTFILE_NAME));
var sourceContainer = blobStoreHelper.createContainer(BLOB_CONTAINER_NAME);
blobStoreHelper.uploadBlob(sourceContainer, fileData, TESTFILE_NAME);
vault.storeSecret(BLOB_KEY_ALIAS, BLOB_ACCOUNT_KEY);
vault.storeSecret(BLOB_KEY_ALIAS, CONSUMER_AZURITE_ACCOUNT.key());

var r = s3Client.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build());
assertThat(r.sdkHttpResponse().isSuccessful()).isTrue();
Expand All @@ -190,7 +183,7 @@ void transferFile_azureToS3(Vault vault) {
.add("dspace:endpointType", "AzureStorage")
.add("dspace:endpointProperties", Json.createArrayBuilder()
.add(dspaceProperty(EDC_NAMESPACE + "container", BLOB_CONTAINER_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", BLOB_ACCOUNT_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", CONSUMER_AZURITE_ACCOUNT.name()))
.add(dspaceProperty(EDC_NAMESPACE + "keyName", BLOB_KEY_ALIAS))
.add(dspaceProperty(EDC_NAMESPACE + "blobName", TESTFILE_NAME))
)
Expand Down Expand Up @@ -268,7 +261,7 @@ void transferFile_s3ToAzureMultipleFiles(Vault vault) {
.add("dspace:endpointType", "AzureStorage")
.add("dspace:endpointProperties", Json.createArrayBuilder()
.add(dspaceProperty(EDC_NAMESPACE + "container", AZBLOB_CONSUMER_CONTAINER_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", AZBLOB_CONSUMER_ACCOUNT_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", CONSUMER_AZURITE_ACCOUNT.name()))
.add(dspaceProperty(EDC_NAMESPACE + "keyName", AZBLOB_CONSUMER_KEY_ALIAS))
)
)
Expand Down Expand Up @@ -334,7 +327,7 @@ void transferFile_s3ToAzureMultipleFiles_whenConsumerDefinesBloblName_success(Va
.add("dspace:endpointType", "AzureStorage")
.add("dspace:endpointProperties", Json.createArrayBuilder()
.add(dspaceProperty(EDC_NAMESPACE + "container", AZBLOB_CONSUMER_CONTAINER_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", AZBLOB_CONSUMER_ACCOUNT_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", CONSUMER_AZURITE_ACCOUNT.name()))
.add(dspaceProperty(EDC_NAMESPACE + "keyName", AZBLOB_CONSUMER_KEY_ALIAS))
.add(dspaceProperty(EDC_NAMESPACE + "blobName", "NOME_TEST"))
)
Expand Down Expand Up @@ -391,7 +384,7 @@ void transferFile_s3ToAzure(Vault vault) {
.add("dspace:endpointType", "AzureStorage")
.add("dspace:endpointProperties", Json.createArrayBuilder()
.add(dspaceProperty(EDC_NAMESPACE + "container", AZBLOB_CONSUMER_CONTAINER_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", AZBLOB_CONSUMER_ACCOUNT_NAME))
.add(dspaceProperty(EDC_NAMESPACE + "account", CONSUMER_AZURITE_ACCOUNT.name()))
.add(dspaceProperty(EDC_NAMESPACE + "keyName", AZBLOB_CONSUMER_KEY_ALIAS))
.add(dspaceProperty(EDC_NAMESPACE + "blobName", TESTFILE_NAME))
)
Expand Down
Loading
Loading