From 989be551d03a2551ac6d2b97d4ec2da26fbe9040 Mon Sep 17 00:00:00 2001 From: Manfred Riem Date: Fri, 29 Mar 2024 16:24:33 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20#376=20-=20Separate=20Docker=20containe?= =?UTF-8?q?r=20into=20Maven=20profile=20for=20Azure=20S=E2=80=A6=20(#377)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- azure-storage/pom.xml | 153 +++++++++--------- .../main/java/storage/ContainerResource.java | 41 +++++ .../src/test/java/storage/StorageIT.java | 51 ++++++ 3 files changed, 173 insertions(+), 72 deletions(-) create mode 100644 azure-storage/src/main/java/storage/ContainerResource.java create mode 100644 azure-storage/src/test/java/storage/StorageIT.java diff --git a/azure-storage/pom.xml b/azure-storage/pom.xml index c30bc49..d7d94d2 100644 --- a/azure-storage/pom.xml +++ b/azure-storage/pom.xml @@ -40,7 +40,7 @@ com.azure - azure-data-appconfiguration + azure-storage-blob test @@ -100,77 +100,86 @@ false - - io.fabric8 - docker-maven-plugin - ${docker-maven-plugin.version} - - - - ocelot-azure-storage - ghcr.io/manorrock/ocelot-azure-storage:%l - - - - linux/amd64 - linux/arm64 - - - ${basedir} - src/main/docker/Dockerfile - - - - 8103:8103 - 8203:8203 - - - - ${basedir}/src/test/certs:/home/piranha/certs - - - - - http://localhost:8103/ping - - - - - - - - - - build - none - - build - - - - start - pre-integration-test - - build - start - - - - stop - post-integration-test - - stop - - - - push - none - - push - - - - + + + docker + + + + io.fabric8 + docker-maven-plugin + ${docker-maven-plugin.version} + + + + ocelot-azure-storage + ghcr.io/manorrock/ocelot-azure-storage:%l + + + + linux/amd64 + linux/arm64 + + + ${basedir} + src/main/docker/Dockerfile + + + + 8103:8103 + 8203:8203 + + + + ${basedir}/src/test/certs:/home/piranha/certs + + + + + http://localhost:8103/ping + + + + + + + + + + build + none + + build + + + + start + pre-integration-test + + build + start + + + + stop + post-integration-test + + stop + + + + push + none + + push + + + + + + + + diff --git a/azure-storage/src/main/java/storage/ContainerResource.java b/azure-storage/src/main/java/storage/ContainerResource.java new file mode 100644 index 0000000..1ff9410 --- /dev/null +++ b/azure-storage/src/main/java/storage/ContainerResource.java @@ -0,0 +1,41 @@ +package storage; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.core.Response; +import static jakarta.ws.rs.core.Response.Status.CREATED; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Manfred Riem (mriem@manorrock.com) + */ +@Path("") +@Singleton +public class ContainerResource { + + /** + * Stores the secrets. + */ + private final List containerNames = new ArrayList<>(); + + /** + * Create the container. + * + * @param containerName the container name. + * @return the response. + */ + @Path("{containerName}?restype=container") + @PUT + public Response createContainer( + @PathParam("containerName") String containerName) { + + if (!containerNames.contains(containerName)) { + containerNames.add(containerName); + return Response.status(CREATED).header("Connection", "close").build(); + } + return Response.serverError().build(); + } +} diff --git a/azure-storage/src/test/java/storage/StorageIT.java b/azure-storage/src/test/java/storage/StorageIT.java new file mode 100644 index 0000000..abc9631 --- /dev/null +++ b/azure-storage/src/test/java/storage/StorageIT.java @@ -0,0 +1,51 @@ +package storage; + +import com.azure.core.credential.BasicAuthenticationCredential; +import com.azure.core.credential.TokenCredential; +import static com.azure.core.http.policy.HttpLogDetailLevel.BODY_AND_HEADERS; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.storage.blob.BlobContainerClient; +import com.azure.storage.blob.BlobContainerClientBuilder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +/** + * The integration tests to test our simulated Azure Storage. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +public class StorageIT { + + /** + * Stores the credential. + */ + private TokenCredential credential; + + /** + * Setup the credential. + */ + @BeforeEach + public void setUp() { + credential = new BasicAuthenticationCredential("username", "password"); + } + + /** + * Test creating blob container. + */ + @Test + @Disabled + public void testCreateBlobContainer() { + + BlobContainerClient blobContainerClient = new BlobContainerClientBuilder() + .endpoint("https://localhost:8203") + .credential(credential) + .containerName("myBlobContainer") + .httpLogOptions(new HttpLogOptions().setLogLevel(BODY_AND_HEADERS)) + .buildClient(); + + blobContainerClient.create(); + assertEquals("myBlobContainer", blobContainerClient.getBlobContainerName()); + } +}