You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/04/15 12:56:31 UTC

[camel] 05/07: CAMEL-16506 - Camel-Azure-Storage-queue: Add Azurite IT Tests

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 93478466328cb3c98d748d721d9a29f9e9b64e60
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 15 14:49:49 2021 +0200

    CAMEL-16506 - Camel-Azure-Storage-queue: Add Azurite IT Tests
---
 .../queue/integration/StorageQueueBase.java        |  1 +
 .../queue/integration/StorageQueueConsumerIT.java  | 55 ++------------
 .../queue/integration/StorageQueueProducerIT.java  | 88 +---------------------
 3 files changed, 8 insertions(+), 136 deletions(-)

diff --git a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueBase.java b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueBase.java
index beb643d..4ec3979 100644
--- a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueBase.java
+++ b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueBase.java
@@ -80,6 +80,7 @@ public class StorageQueueBase extends CamelTestSupport {
         configuration.setQueueName(queueName);
 
         serviceClient = AzureStorageClientUtils.getClient();
+        serviceClient.getQueueClient(queueName).create();
     }
 
 }
diff --git a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueConsumerIT.java b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueConsumerIT.java
index 1396af6..9634fe1 100644
--- a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueConsumerIT.java
+++ b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueConsumerIT.java
@@ -17,55 +17,27 @@
 package org.apache.camel.component.azure.storage.queue.integration;
 
 import java.util.List;
-import java.util.Properties;
 
-import com.azure.storage.common.StorageSharedKeyCredential;
-import com.azure.storage.queue.QueueServiceClient;
-import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.azure.storage.queue.QueueConfiguration;
-import org.apache.camel.component.azure.storage.queue.QueueTestUtils;
-import org.apache.camel.component.azure.storage.queue.client.QueueClientFactory;
-import org.apache.camel.component.azure.storage.queue.client.QueueClientWrapper;
-import org.apache.camel.component.azure.storage.queue.client.QueueServiceClientWrapper;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInstance;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-@TestInstance(TestInstance.Lifecycle.PER_CLASS)
 class StorageQueueConsumerIT extends StorageQueueBase {
 
     @EndpointInject("mock:result")
     private MockEndpoint result;
     private String resultName = "mock:result";
 
-    private String queueName;
-    private QueueClientWrapper queueClientWrapper;
-
     @BeforeAll
-    public void prepare() throws Exception {
-        queueName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
-
-        final QueueConfiguration configuration = new QueueConfiguration();
-        configuration.setCredentials(storageSharedKeyCredential());
-        configuration.setQueueName(queueName);
-
-        final QueueServiceClient serviceClient = QueueClientFactory.createQueueServiceClient(configuration);
-        queueClientWrapper = new QueueServiceClientWrapper(serviceClient).getQueueClientWrapper(queueName);
-
-        queueClientWrapper.create(null, null);
-        queueClientWrapper.sendMessage("test-message-1", null, null, null);
-        queueClientWrapper.sendMessage("test-message-2", null, null, null);
-        queueClientWrapper.sendMessage("test-message-3", null, null, null);
+    public void setup() {
+        serviceClient.getQueueClient(queueName).sendMessage("test-message-1");
+        serviceClient.getQueueClient(queueName).sendMessage("test-message-2");
+        serviceClient.getQueueClient(queueName).sendMessage("test-message-3");
     }
 
     @Test
@@ -85,32 +57,15 @@ class StorageQueueConsumerIT extends StorageQueueBase {
         assertEquals("test-message-3", exchanges.get(2).getMessage().getBody());
     }
 
-    @AfterAll
-    public void tearDown() {
-        queueClientWrapper.delete(null);
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("azure-storage-queue://cameldev/" + queueName + "?credentials=#creds&maxMessages=5")
+                from("azure-storage-queue://cameldev/" + queueName + "?maxMessages=5")
                         .to(resultName);
 
             }
         };
     }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        context.getRegistry().bind("creds", storageSharedKeyCredential());
-        return context;
-    }
-
-    private StorageSharedKeyCredential storageSharedKeyCredential() throws Exception {
-        final Properties properties = QueueTestUtils.loadAzureAccessFromJvmEnv();
-        return new StorageSharedKeyCredential(properties.getProperty("account_name"), properties.getProperty("access_key"));
-    }
 }
diff --git a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueProducerIT.java b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueProducerIT.java
index 47025aa..b10f43f 100644
--- a/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueProducerIT.java
+++ b/components/camel-azure/camel-azure-storage-queue/src/test/java/org/apache/camel/component/azure/storage/queue/integration/StorageQueueProducerIT.java
@@ -16,36 +16,20 @@
  */
 package org.apache.camel.component.azure.storage.queue.integration;
 
-import java.util.List;
 import java.util.Map;
-import java.util.Properties;
-import java.util.stream.Collectors;
 
-import com.azure.storage.common.StorageSharedKeyCredential;
-import com.azure.storage.queue.QueueServiceClient;
-import com.azure.storage.queue.models.QueueMessageItem;
-import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.azure.storage.queue.QueueConfiguration;
 import org.apache.camel.component.azure.storage.queue.QueueConstants;
-import org.apache.camel.component.azure.storage.queue.QueueTestUtils;
-import org.apache.camel.component.azure.storage.queue.client.QueueClientFactory;
-import org.apache.camel.component.azure.storage.queue.client.QueueServiceClientWrapper;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit5.CamelTestSupport;
 import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInstance;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-@TestInstance(TestInstance.Lifecycle.PER_CLASS)
 class StorageQueueProducerIT extends StorageQueueBase {
 
     @EndpointInject
@@ -55,21 +39,8 @@ class StorageQueueProducerIT extends StorageQueueBase {
     private MockEndpoint result;
     private String resultName = "mock:result";
 
-    private QueueConfiguration configuration;
-    private QueueServiceClientWrapper serviceClient;
-
-    @BeforeAll
-    public void prepare() throws Exception {
-        configuration = new QueueConfiguration();
-        configuration.setCredentials(storageSharedKeyCredential());
-
-        final QueueServiceClient client = QueueClientFactory.createQueueServiceClient(configuration);
-        serviceClient = new QueueServiceClientWrapper(client);
-    }
-
     @Test
     public void testCreateDeleteQueue() throws InterruptedException {
-        final String queueName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
 
         template.send("direct:createQueue", ExchangePattern.InOnly, exchange -> {
             exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, queueName);
@@ -77,9 +48,6 @@ class StorageQueueProducerIT extends StorageQueueBase {
 
         result.assertIsSatisfied();
 
-        // check name
-        assertEquals(queueName, serviceClient.listQueues(null, null).get(0).getName());
-
         // delete queue
         template.send("direct:deleteQueue", ExchangePattern.InOnly, exchange -> {
             exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, queueName);
@@ -91,9 +59,8 @@ class StorageQueueProducerIT extends StorageQueueBase {
         result.assertIsSatisfied();
 
         // check name
-        assertEquals("testqueue", serviceClient.listQueues(null, null).get(0).getName());
+        assertEquals("testqueue", serviceClient.getQueueClient("testqueue").getQueueName());
 
-        serviceClient.getQueueClientWrapper("testqueue").delete(null);
     }
 
     @Test
@@ -124,10 +91,6 @@ class StorageQueueProducerIT extends StorageQueueBase {
 
         final Map<String, Object> sentMessageHeaders = result.getExchanges().get(0).getMessage().getHeaders();
 
-        // check message
-        assertEquals("test-message-1",
-                serviceClient.getQueueClientWrapper(queueName).peekMessages(1, null).get(0).getMessageText());
-
         result.reset();
 
         template.send("direct:deleteMessage", ExchangePattern.InOnly, exchange -> {
@@ -136,49 +99,7 @@ class StorageQueueProducerIT extends StorageQueueBase {
             exchange.getIn().setHeader(QueueConstants.POP_RECEIPT, sentMessageHeaders.get(QueueConstants.POP_RECEIPT));
         });
 
-        // check
-        assertTrue(serviceClient.getQueueClientWrapper(queueName).peekMessages(1, null).isEmpty());
-
-        result.assertIsSatisfied();
-
-        serviceClient.getQueueClientWrapper(queueName).delete(null);
-    }
-
-    @Test
-    public void testReceiveMessages() throws InterruptedException {
-        final String queueName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
-        serviceClient.getQueueClientWrapper(queueName).create(null, null);
-        serviceClient.getQueueClientWrapper(queueName).sendMessage("test-message-1", null, null, null);
-        serviceClient.getQueueClientWrapper(queueName).sendMessage("test-message-2", null, null, null);
-        serviceClient.getQueueClientWrapper(queueName).sendMessage("test-message-3", null, null, null);
-
-        result.expectedMessageCount(1);
-
-        template.send("direct:receiveMessages", ExchangePattern.InOnly, exchange -> {
-            exchange.getIn().setHeader(QueueConstants.QUEUE_NAME, queueName);
-            exchange.getIn().setHeader(QueueConstants.MAX_MESSAGES, 3);
-        });
-
         result.assertIsSatisfied();
-
-        final List<QueueMessageItem> messages = result.getExchanges().get(0).getMessage().getBody(List.class);
-        final List<String> messagesText = messages
-                .stream()
-                .map(QueueMessageItem::getMessageText)
-                .collect(Collectors.toList());
-
-        assertTrue(messagesText.contains("test-message-1"));
-        assertTrue(messagesText.contains("test-message-2"));
-        assertTrue(messagesText.contains("test-message-3"));
-
-        serviceClient.getQueueClientWrapper(queueName).delete(null);
-    }
-
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        context.getRegistry().bind("creds", storageSharedKeyCredential());
-        return context;
     }
 
     @Override
@@ -209,12 +130,7 @@ class StorageQueueProducerIT extends StorageQueueBase {
         };
     }
 
-    private StorageSharedKeyCredential storageSharedKeyCredential() throws Exception {
-        final Properties properties = QueueTestUtils.loadAzureAccessFromJvmEnv();
-        return new StorageSharedKeyCredential(properties.getProperty("account_name"), properties.getProperty("access_key"));
-    }
-
     private String componentUri(final String operation, final String queueName) {
-        return String.format("azure-storage-queue://cameldev/%s?credentials=#creds&operation=%s", queueName, operation);
+        return String.format("azure-storage-queue://cameldev/%s?operation=%s", queueName, operation);
     }
 }