You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/04/05 20:15:05 UTC

[camel-quarkus] 02/02: Test Azure Blob with autowiredEnabled=false

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

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit c67b3165b440ecf1d964061f0d45a4b7281f0e6e
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Apr 5 15:11:56 2022 +0100

    Test Azure Blob with autowiredEnabled=false
    
    Fixes #3694
---
 .../storage/blob/it/AzureStorageBlobProducers.java |  8 +++++++
 .../storage/blob/it/AzureStorageBlobResource.java  | 10 ++++++--
 .../storage/blob/it/AzureStorageBlobRoutes.java    | 11 ++++++++-
 .../storage/blob/it/AzureStorageBlobTest.java      | 28 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobProducers.java b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobProducers.java
index dfd65bea34..f15cabf492 100644
--- a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobProducers.java
+++ b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobProducers.java
@@ -23,6 +23,7 @@ import com.azure.core.http.policy.HttpLogOptions;
 import com.azure.storage.blob.BlobServiceClient;
 import com.azure.storage.blob.BlobServiceClientBuilder;
 import com.azure.storage.common.StorageSharedKeyCredential;
+import org.apache.camel.component.azure.storage.blob.BlobComponent;
 import org.eclipse.microprofile.config.inject.ConfigProperty;
 
 public class AzureStorageBlobProducers {
@@ -46,4 +47,11 @@ public class AzureStorageBlobProducers {
                 .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).setPrettyPrintBody(true))
                 .buildClient();
     }
+
+    @Named("azure-storage-blob-managed-client")
+    public BlobComponent azureBlobComponentWithManagedClient() {
+        BlobComponent component = new BlobComponent();
+        component.setAutowiredEnabled(false);
+        return component;
+    }
 }
diff --git a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobResource.java b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobResource.java
index 5bd0f54f2b..bea14e5c8b 100644
--- a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobResource.java
+++ b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobResource.java
@@ -113,15 +113,21 @@ public class AzureStorageBlobResource {
     @Path("/blob/read")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
-    public String readBlob(@QueryParam("containerName") String containerName) {
+    public String readBlob(
+            @QueryParam("containerName") String containerName,
+            @QueryParam("uri") String uri) {
         if (containerName == null) {
             containerName = azureBlobContainerName;
         }
 
+        if (uri == null) {
+            uri = "direct:read";
+        }
+
         Map<String, Object> headers = new HashMap<>();
         headers.put(Exchange.CHARSET_NAME, StandardCharsets.UTF_8.name());
         headers.put(BlobConstants.BLOB_CONTAINER_NAME, containerName);
-        return producerTemplate.requestBodyAndHeaders("direct:read", null, headers, String.class);
+        return producerTemplate.requestBodyAndHeaders(uri, null, headers, String.class);
     }
 
     @Path("/blob/read/bytes")
diff --git a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobRoutes.java b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobRoutes.java
index a1de8d5903..954f55d980 100644
--- a/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobRoutes.java
+++ b/integration-test-groups/azure/azure-storage-blob/src/main/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobRoutes.java
@@ -50,6 +50,10 @@ public class AzureStorageBlobRoutes extends RouteBuilder {
         from("direct:read")
                 .to(componentUri(BlobOperationsDefinition.getBlob));
 
+        from("direct:readWithManagedClient")
+                .to(componentUri("azure-storage-blob-managed-client", BlobOperationsDefinition.getBlob)
+                        + "&autowiredEnabled=false&accessKey=RAW(" + azureStorageAccountKey + ")");
+
         from("direct:update")
                 .to(componentUri(BlobOperationsDefinition.uploadBlockBlob));
 
@@ -117,7 +121,12 @@ public class AzureStorageBlobRoutes extends RouteBuilder {
     }
 
     private String componentUri(final BlobOperationsDefinition operation) {
-        return String.format("azure-storage-blob://%s/%s?operation=%s&blobName=%s",
+        return componentUri("azure-storage-blob", operation);
+    }
+
+    private String componentUri(final String componentName, final BlobOperationsDefinition operation) {
+        return String.format("%s://%s/%s?operation=%s&blobName=%s",
+                componentName,
                 azureStorageAccountName,
                 azureBlobContainerName,
                 operation.name(), BLOB_NAME);
diff --git a/integration-test-groups/azure/azure-storage-blob/src/test/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobTest.java b/integration-test-groups/azure/azure-storage-blob/src/test/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobTest.java
index d7a5cd1192..de772d5902 100644
--- a/integration-test-groups/azure/azure-storage-blob/src/test/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobTest.java
+++ b/integration-test-groups/azure/azure-storage-blob/src/test/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobTest.java
@@ -516,4 +516,32 @@ class AzureStorageBlobTest {
                     .statusCode(anyOf(is(204), is(404)));
         }
     }
+
+    // Can only use the Camel component managed blob client with the real Azure service
+    @EnabledIf({ MockBackendDisabled.class })
+    @Test
+    public void readWithManagedClient() {
+        try {
+            // Create
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Read
+            RestAssured.given()
+                    .queryParam("uri", "direct:readWithManagedClient")
+                    .get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(BLOB_CONTENT));
+        } finally {
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(anyOf(is(204), is(404)));
+        }
+    }
 }