-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(test): introduce Azurite and Minio extensions
- Loading branch information
Showing
11 changed files
with
395 additions
and
344 deletions.
There are no files selected for viewing
42 changes: 0 additions & 42 deletions
42
...e2e-fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/aws/MinioContainer.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...e2e-fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/aws/MinioExtension.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,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); | ||
} | ||
} | ||
} |
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
45 changes: 0 additions & 45 deletions
45
...fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/azure/AzuriteContainer.java
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/azure/AzuriteExtension.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,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)); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.