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

refactor(test): introduce Azurite and Minio extensions #1643

Merged
Merged
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
4 changes: 2 additions & 2 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ maven/mavencentral/com.azure/azure-json/1.3.0, MIT, approved, clearlydefined
maven/mavencentral/com.azure/azure-security-keyvault-secrets/4.8.7, MIT, approved, #13690
maven/mavencentral/com.azure/azure-storage-blob/12.28.0, MIT, approved, clearlydefined
maven/mavencentral/com.azure/azure-storage-blob/12.28.1, MIT, approved, clearlydefined
maven/mavencentral/com.azure/azure-storage-common/12.27.0, MIT, approved, clearlydefined
maven/mavencentral/com.azure/azure-storage-common/12.27.1, , restricted, clearlydefined
maven/mavencentral/com.azure/azure-storage-common/12.27.0, MIT, approved, #16851
maven/mavencentral/com.azure/azure-storage-common/12.27.1, MIT, approved, #16851
maven/mavencentral/com.azure/azure-storage-internal-avro/12.13.0, MIT, approved, clearlydefined
maven/mavencentral/com.azure/azure-xml/1.1.0, MIT, approved, clearlydefined
maven/mavencentral/com.ethlo.time/itu/1.7.0, Apache-2.0, approved, clearlydefined
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.tests.aws;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.GenericContainer;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;

import java.util.UUID;

public class MinioExtension implements BeforeAllCallback, AfterAllCallback {

private final MinioContainer minioContainer = new MinioContainer();

@Override
public void beforeAll(ExtensionContext context) {
minioContainer.start();
}

@Override
public void afterAll(ExtensionContext context) {
minioContainer.stop();
}

public int getPort() {
return minioContainer.getFirstMappedPort();
}

public AwsCredentials getCredentials() {
return minioContainer.getCredentials();
}

private static class MinioContainer extends GenericContainer<MinioContainer> {

private final String accessKeyId = "test-access-key";
private final String secretAccessKey = UUID.randomUUID().toString();

public MinioContainer() {
super("bitnami/minio");
addEnv("MINIO_ROOT_USER", accessKeyId);
addEnv("MINIO_ROOT_PASSWORD", secretAccessKey);
addExposedPort(9000);
}

public AwsBasicCredentials getCredentials() {
return AwsBasicCredentials.create(accessKeyId, secretAccessKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
/**
* Helper class that internally uses Azure SDK classes to create containers, upload blobs, generate SAS tokens, etc.
*/
public class AzureBlobHelper {
public class AzureBlobClient {
private final String accountName;
private final String key;
private final String host;
private final int port;
private BlobServiceClient blobServiceClient;

AzureBlobHelper(String accountName, String key, String host, int port) {
AzureBlobClient(String accountName, String key, String host, int port) {
this.accountName = accountName;
this.key = key;
this.host = host;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.tests.azure;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.GenericContainer;

import java.util.List;

import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;

public class AzuriteExtension implements BeforeAllCallback, AfterAllCallback {

private final AzuriteContainer azuriteContainer;

public AzuriteExtension(int azuriteHostPort, Account... accounts) {
azuriteContainer = new AzuriteContainer(azuriteHostPort, accounts);
}

@Override
public void beforeAll(ExtensionContext context) {
azuriteContainer.start();
}

@Override
public void afterAll(ExtensionContext context) {
azuriteContainer.stop();
}

public AzureBlobClient getClientFor(Account account) {
return azuriteContainer.getHelper(account);
}

public record Account(String name, String key) { }

private static 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(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)));
}

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

}
}
Loading
Loading