This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new b91b101 Test Azure extension with Azurite
b91b101 is described below
commit b91b101835e7620b3d17468f853bbf988a15cb06
Author: James Netherton <[email protected]>
AuthorDate: Fri May 15 13:55:21 2020 +0100
Test Azure extension with Azurite
Fixes #1072
---
integration-tests/azure/README.adoc | 13 ----
integration-tests/azure/pom.xml | 5 ++
.../component/azure/it/AzureBlobResource.java | 34 ++++++++--
.../component/azure/it/AzureQueueResource.java | 27 ++++++--
.../src/main/resources/application.properties | 25 -------
.../camel/quarkus/component/azure/it/AzureIT.java | 3 -
.../quarkus/component/azure/it/AzureTest.java | 5 +-
.../component/azure/it/AzureTestResource.java | 76 ++++++++++++++++++++++
8 files changed, 136 insertions(+), 52 deletions(-)
diff --git a/integration-tests/azure/README.adoc
b/integration-tests/azure/README.adoc
deleted file mode 100644
index 035501b..0000000
--- a/integration-tests/azure/README.adoc
+++ /dev/null
@@ -1,13 +0,0 @@
-== Camel Quarkus Azure Integration Tests
-
-To run `camel-quarkus-azure` integration tests, you will need a
https://azure.microsoft.com/[Azure] account.
-
-Set up a new storage account via the Azure console. Next create a new Blob
service container named 'camel-test'.
-
-Then set the following environment variables:
-
-[source,shell]
-----
-export AZURE_STORAGE_ACCOUNT=my-storage-account-name
-export AZURE_STORAGE_KEY=my-storage-key
-----
diff --git a/integration-tests/azure/pom.xml b/integration-tests/azure/pom.xml
index 8947c4e..f5fef60 100644
--- a/integration-tests/azure/pom.xml
+++ b/integration-tests/azure/pom.xml
@@ -60,6 +60,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+
<artifactId>camel-quarkus-integration-testcontainers-support</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureBlobResource.java
b/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureBlobResource.java
index 20a9ff9..9ca15a0 100644
---
a/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureBlobResource.java
+++
b/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureBlobResource.java
@@ -20,8 +20,10 @@ import java.io.ByteArrayInputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
+import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -32,6 +34,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import com.microsoft.azure.storage.StorageCredentials;
+import com.microsoft.azure.storage.blob.CloudBlob;
+import com.microsoft.azure.storage.blob.CloudBlobContainer;
+import com.microsoft.azure.storage.blob.CloudBlockBlob;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.azure.blob.BlobBlock;
@@ -43,12 +49,30 @@ public class AzureBlobResource {
@Inject
ProducerTemplate producerTemplate;
+ @PostConstruct
+ public void init() throws Exception {
+ StorageCredentials credentials =
StorageCredentials.tryParseCredentials(System.getProperty("azurite.credentials"));
+ URI uri = new URI(System.getProperty("azurite.blob.service.url") +
"camel-test");
+ CloudBlobContainer container = new CloudBlobContainer(uri,
credentials);
+ container.create();
+ }
+
+ @javax.enterprise.inject.Produces
+ @Named("azureBlobClient")
+ public CloudBlob createBlobClient() throws Exception {
+ StorageCredentials credentials =
StorageCredentials.tryParseCredentials(System.getProperty("azurite.credentials"));
+ URI uri = new URI(System.getProperty("azurite.blob.service.url") +
"camel-test/test");
+ CloudBlockBlob cloudBlockBlob = new CloudBlockBlob(uri, credentials);
+ return cloudBlockBlob;
+ }
+
@Path("/blob/create")
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response createBlob(String message) throws Exception {
BlobBlock blob = new BlobBlock(new
ByteArrayInputStream(message.getBytes(StandardCharsets.UTF_8)));
-
producerTemplate.sendBody("azure-blob://{{env:AZURE_STORAGE_ACCOUNT}}/camel-test/test?operation=uploadBlobBlocks",
+ producerTemplate.sendBody(
+
"azure-blob://devstoreaccount1/camel-test/test?operation=uploadBlobBlocks&azureBlobClient=#azureBlobClient&validateClientURI=false",
blob);
return Response.created(new URI("https://camel.apache.org/")).build();
}
@@ -58,7 +82,7 @@ public class AzureBlobResource {
@Produces(MediaType.TEXT_PLAIN)
public String readBlob() throws Exception {
return producerTemplate.requestBodyAndHeader(
-
"azure-blob://{{env:AZURE_STORAGE_ACCOUNT}}/camel-test/test?operation=getBlob",
+
"azure-blob://devstoreaccount1/camel-test/test?operation=getBlob&azureBlobClient=#azureBlobClient&validateClientURI=false",
null, Exchange.CHARSET_NAME, StandardCharsets.UTF_8.name(),
String.class);
}
@@ -66,7 +90,8 @@ public class AzureBlobResource {
@PATCH
@Consumes(MediaType.TEXT_PLAIN)
public Response updateBlob(String message) throws Exception {
-
producerTemplate.sendBody("azure-blob://{{env:AZURE_STORAGE_ACCOUNT}}/camel-test/test?operation=updateBlockBlob",
+ producerTemplate.sendBody(
+
"azure-blob://devstoreaccount1/camel-test/test?operation=updateBlockBlob&azureBlobClient=#azureBlobClient&validateClientURI=false",
message);
return Response.ok().build();
}
@@ -74,7 +99,8 @@ public class AzureBlobResource {
@Path("/blob/delete")
@DELETE
public Response deleteBlob() throws Exception {
-
producerTemplate.sendBody("azure-blob://{{env:AZURE_STORAGE_ACCOUNT}}/camel-test/test?operation=deleteBlob",
+ producerTemplate.sendBody(
+
"azure-blob://devstoreaccount1/camel-test/test?operation=deleteBlob&azureBlobClient=#azureBlobClient&validateClientURI=false",
null);
return Response.noContent().build();
}
diff --git
a/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureQueueResource.java
b/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureQueueResource.java
index 6db682b..70e5379 100644
---
a/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureQueueResource.java
+++
b/integration-tests/azure/src/main/java/org/apache/camel/quarkus/component/azure/it/AzureQueueResource.java
@@ -21,6 +21,7 @@ import java.util.UUID;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -30,6 +31,8 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import com.microsoft.azure.storage.StorageCredentials;
+import com.microsoft.azure.storage.queue.CloudQueue;
import com.microsoft.azure.storage.queue.CloudQueueMessage;
import org.apache.camel.ProducerTemplate;
@@ -42,10 +45,21 @@ public class AzureQueueResource {
@Inject
ProducerTemplate producerTemplate;
+ @javax.enterprise.inject.Produces
+ @Named("azureQueueClient")
+ public CloudQueue createQueueClient() throws Exception {
+ StorageCredentials credentials =
StorageCredentials.tryParseCredentials(System.getProperty("azurite.credentials"));
+ URI uri = new URI(System.getProperty("azurite.queue.service.url") +
QUEUE_NAME);
+ return new CloudQueue(uri, credentials);
+ }
+
@Path("/queue/create")
@POST
public Response createQueue() throws Exception {
-
producerTemplate.sendBody("azure-queue://{{env:AZURE_STORAGE_ACCOUNT}}/" +
QUEUE_NAME + "?operation=createQueue", null);
+ producerTemplate.sendBody(
+ "azure-queue://devstoreaccount1/" + QUEUE_NAME
+ +
"?operation=createQueue&azureQueueClient=#azureQueueClient&validateClientURI=false",
+ null);
return Response.created(new URI("https://camel.apache.org/")).build();
}
@@ -54,7 +68,8 @@ public class AzureQueueResource {
@Produces(MediaType.TEXT_PLAIN)
public String retrieveMessage() throws Exception {
CloudQueueMessage message = producerTemplate.requestBody(
- "azure-queue://{{env:AZURE_STORAGE_ACCOUNT}}/" + QUEUE_NAME +
"?operation=retrieveMessage",
+ "azure-queue://devstoreaccount1/" + QUEUE_NAME
+ +
"?operation=retrieveMessage&azureQueueClient=#azureQueueClient&validateClientURI=false",
null, CloudQueueMessage.class);
return message.getMessageContentAsString();
}
@@ -63,7 +78,9 @@ public class AzureQueueResource {
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response addMessage(String message) throws Exception {
-
producerTemplate.sendBody("azure-queue://{{env:AZURE_STORAGE_ACCOUNT}}/" +
QUEUE_NAME + "?operation=addMessage",
+ producerTemplate.sendBody(
+ "azure-queue://devstoreaccount1/" + QUEUE_NAME
+ +
"?operation=addMessage&azureQueueClient=#azureQueueClient&validateClientURI=false",
message);
return Response.created(new URI("https://camel.apache.org/")).build();
}
@@ -71,7 +88,9 @@ public class AzureQueueResource {
@Path("/queue/delete")
@DELETE
public Response deleteQueue() throws Exception {
-
producerTemplate.sendBody("azure-queue://{{env:AZURE_STORAGE_ACCOUNT}}/" +
QUEUE_NAME + "?operation=deleteQueue",
+ producerTemplate.sendBody(
+ "azure-queue://devstoreaccount1/" + QUEUE_NAME
+ +
"?operation=deleteQueue&azureQueueClient=#azureQueueClient&validateClientURI=false",
null);
return Response.noContent().build();
}
diff --git a/integration-tests/azure/src/main/resources/application.properties
b/integration-tests/azure/src/main/resources/application.properties
deleted file mode 100644
index fa2d35c..0000000
--- a/integration-tests/azure/src/main/resources/application.properties
+++ /dev/null
@@ -1,25 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://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.
-## ---------------------------------------------------------------------------
-
-
-#
-# Camel :: Azure
-#
-camel.component.azure-blob.credentialsAccountName =
{{env:AZURE_STORAGE_ACCOUNT}}
-camel.component.azure-blob.credentialsAccountKey = {{env:AZURE_STORAGE_KEY}}
-camel.component.azure-queue.credentialsAccountName =
{{env:AZURE_STORAGE_ACCOUNT}}
-camel.component.azure-queue.credentialsAccountKey = {{env:AZURE_STORAGE_KEY}}
diff --git
a/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureIT.java
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureIT.java
index c670aac..5c0d3e1 100644
---
a/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureIT.java
+++
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureIT.java
@@ -17,11 +17,8 @@
package org.apache.camel.quarkus.component.azure.it;
import io.quarkus.test.junit.NativeImageTest;
-import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
@NativeImageTest
-@EnabledIfEnvironmentVariable(named = "AZURE_STORAGE_ACCOUNT", matches = ".+")
-@EnabledIfEnvironmentVariable(named = "AZURE_STORAGE_KEY", matches = ".+")
class AzureIT extends AzureTest {
}
diff --git
a/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTest.java
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTest.java
index 67d37db..d27ffab 100644
---
a/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTest.java
+++
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTest.java
@@ -16,17 +16,16 @@
*/
package org.apache.camel.quarkus.component.azure.it;
+import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import static org.hamcrest.core.Is.is;
@QuarkusTest
-@EnabledIfEnvironmentVariable(named = "AZURE_STORAGE_ACCOUNT", matches = ".*")
-@EnabledIfEnvironmentVariable(named = "AZURE_STORAGE_KEY", matches = ".*")
+@QuarkusTestResource(AzureTestResource.class)
class AzureTest {
@Test
diff --git
a/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTestResource.java
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTestResource.java
new file mode 100644
index 0000000..7bd102c
--- /dev/null
+++
b/integration-tests/azure/src/test/java/org/apache/camel/quarkus/component/azure/it/AzureTestResource.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://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.
+ */
+
+package org.apache.camel.quarkus.component.azure.it;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+public class AzureTestResource implements QuarkusTestResourceLifecycleManager {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(AzureTestResource.class);
+ private static final String AZURITE_IMAGE =
"mcr.microsoft.com/azure-storage/azurite:3.6.0";
+ private static final String AZURITE_CREDENTIALS =
"DefaultEndpointsProtocol=http;AccountName="
+ +
"devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;"
+ + "BlobEndpoint=%s;QueueEndpoint=%s;";
+ private static final int BLOB_SERVICE_PORT = 10000;
+ private static final int QUEUE_SERVICE_PORT = 10001;
+
+ private GenericContainer<?> container;
+
+ @Override
+ public Map<String, String> start() {
+ try {
+ container = new GenericContainer<>(AZURITE_IMAGE)
+ .withExposedPorts(BLOB_SERVICE_PORT, QUEUE_SERVICE_PORT)
+ .withLogConsumer(new Slf4jLogConsumer(LOGGER))
+ .waitingFor(Wait.forListeningPort());
+ container.start();
+
+ String baseServiceUrl = "http://%s:%d/devstoreaccount1/";
+ String blobServiceUrl = String.format(baseServiceUrl,
container.getContainerIpAddress(),
+ container.getMappedPort(BLOB_SERVICE_PORT));
+ String queueServiceUrl = String.format(baseServiceUrl,
container.getContainerIpAddress(),
+ container.getMappedPort(QUEUE_SERVICE_PORT));
+
+ Map<String, String> configuration = new HashMap<>();
+ configuration.put("azurite.blob.service.url", blobServiceUrl);
+ configuration.put("azurite.queue.service.url", queueServiceUrl);
+ configuration.put("azurite.credentials",
String.format(AZURITE_CREDENTIALS, blobServiceUrl, queueServiceUrl));
+ return configuration;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void stop() {
+ try {
+ if (container != null) {
+ container.stop();
+ }
+ } catch (Exception e) {
+ // ignored
+ }
+ }
+}