zbendhiba commented on a change in pull request #3568:
URL: https://github.com/apache/camel-quarkus/pull/3568#discussion_r812717528



##########
File path: 
integration-test-groups/azure/azure-storage-blob/src/test/java/org/apache/camel/quarkus/component/azure/storage/blob/it/AzureStorageBlobTest.java
##########
@@ -63,47 +87,443 @@ private static BlobContainerClient blobContainer() {
                 .credential(credentials)
                 .httpLogOptions(new 
HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS).setPrettyPrintBody(true))
                 .buildClient();
-        BlobContainerClient blobContainer = client
-                
.getBlobContainerClient(config.getValue("azure.blob.container.name", 
String.class));
-        return blobContainer;
+
+        String containerName = config.getValue("azure.blob.container.name", 
String.class);
+        return client.getBlobContainerClient(containerName);
     }
 
     @Test
     public void crud() {
-        String blobContent = "Hello Camel Quarkus Azure Blob";
-
-        // Create
-        RestAssured.given()
-                .contentType(ContentType.TEXT)
-                .body(blobContent)
-                .post("/azure-storage-blob/blob/create")
-                .then()
-                .statusCode(201);
-
-        // Read
-        RestAssured.get("/azure-storage-blob/blob/read")
-                .then()
-                .statusCode(200)
-                .body(is(blobContent));
-
-        // Update
-        String updatedContent = blobContent + " updated";
-        RestAssured.given()
-                .contentType(ContentType.TEXT)
-                .body(updatedContent)
-                .patch("/azure-storage-blob/blob/update")
-                .then()
-                .statusCode(200);
-
-        RestAssured.get("/azure-storage-blob/blob/read")
-                .then()
-                .statusCode(200)
-                .body(is(updatedContent));
-
-        // Delete
-        RestAssured.delete("/azure-storage-blob/blob/delete")
-                .then()
-                .statusCode(204);
+        try {
+            // Create
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Read
+            RestAssured.get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(BLOB_CONTENT));
+
+            // List
+            RestAssured.get("/azure-storage-blob/blob/list")
+                    .then()
+                    .statusCode(200)
+                    .body("blobs[0].name", 
is(AzureStorageBlobRoutes.BLOB_NAME));
+
+            // Update
+            String updatedContent = BLOB_CONTENT + " updated";
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(updatedContent)
+                    .patch("/azure-storage-blob/blob/update")
+                    .then()
+                    .statusCode(200);
+
+            RestAssured.get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(updatedContent));
+        } finally {
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void download() throws IOException {
+        Path path = null;
+        try {
+            // Create
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Download file
+            String downloadPath = 
RestAssured.get("/azure-storage-blob/blob/download")
+                    .then()
+                    .statusCode(200)
+                    .body(endsWith("target/test"))
+                    .extract()
+                    .body()
+                    .asString();
+
+            path = Paths.get(downloadPath);
+            assertEquals(BLOB_CONTENT, Files.readString(path));
+
+            // Download link
+            RestAssured.get("/azure-storage-blob/blob/download/link")
+                    .then()
+                    .statusCode(200)
+                    .body(matchesPattern("^(https?)://.*/test.*"));
+        } finally {
+            if (path != null) {
+                try {
+                    Files.deleteIfExists(path);
+                } catch (IOException e) {
+                    // Ignore
+                }
+            }
+
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void blockBlobStageCommit() {
+        try {
+            List<String> blockContent = Arrays.asList(BLOB_CONTENT.split(" "));
+
+            // Stage blocks
+            RestAssured.given()
+                    .contentType(ContentType.JSON)
+                    .body(blockContent)
+                    .post("/azure-storage-blob/block/blob/stage")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            // Verify blocks uncommitted
+            JsonPath json = RestAssured.given()
+                    .queryParam("blockListType", BlockListType.UNCOMMITTED)
+                    .get("/azure-storage-blob/blob/block/list")
+                    .then()
+                    .statusCode(200)
+                    .extract()
+                    .body()
+                    .jsonPath();
+
+            List<String> uncommittedBlocks = 
json.getList(BlockListType.UNCOMMITTED.toString());
+            assertNotNull(uncommittedBlocks);
+            assertEquals(blockContent.size(), uncommittedBlocks.size());
+
+            // Commit blocks
+            RestAssured.given()
+                    .contentType(ContentType.JSON)
+                    .body(uncommittedBlocks)
+                    .post("/azure-storage-blob/block/blob/commit")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            // Verify blocks committed
+            json = RestAssured.given()
+                    .queryParam("blockListType", BlockListType.COMMITTED)
+                    .get("/azure-storage-blob/blob/block/list")
+                    .then()
+                    .statusCode(200)
+                    .extract()
+                    .body()
+                    .jsonPath();
+
+            List<String> committedBlocks = 
json.getList(BlockListType.COMMITTED.toString());
+            assertNotNull(committedBlocks);
+            assertEquals(blockContent.size(), committedBlocks.size());
+        } finally {
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void appendBlob() {
+        try {
+            // Create
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/append/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Commit
+            String appendedContent = BLOB_CONTENT + " Appended";
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(appendedContent)
+                    .post("/azure-storage-blob/append/blob/commit")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            // Read
+            RestAssured.get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(appendedContent));
+        } finally {
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void pageBlob() {
+        try {
+            // Create
+            RestAssured.given()
+                    .post("/azure-storage-blob/page/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Upload
+            RestAssured.given()
+                    .queryParam("pageStart", 0)
+                    .queryParam("pageEnd", 511)
+                    .post("/azure-storage-blob/page/blob/upload")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            byte[] pageData = 
RestAssured.get("/azure-storage-blob/blob/read/bytes")
+                    .then()
+                    .statusCode(200)
+                    .extract()
+                    .body()
+                    .asByteArray();
+
+            assertEquals(512, pageData.length);
+
+            // Get ranges
+            RestAssured.given()
+                    .queryParam("pageStart", 0)
+                    .queryParam("pageEnd", 511)
+                    .get("/azure-storage-blob/page/blob")
+                    .then()
+                    .statusCode(200)
+                    .body("ranges[0].start", is(0),
+                            "ranges[0].end", is(511));
+
+            // Resize
+            RestAssured.given()
+                    .queryParam("pageStart", 0)
+                    .queryParam("pageEnd", 1023)
+                    .post("/azure-storage-blob/page/blob/resize")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            // Read after resize
+            pageData = RestAssured.get("/azure-storage-blob/blob/read/bytes")
+                    .then()
+                    .statusCode(200)
+                    .extract()
+                    .body()
+                    .asByteArray();
+
+            assertEquals(1024, pageData.length);
+
+            // Verify page data beyond the resized point is empty
+            for (int i = 512; i < pageData.length; i++) {
+                if (pageData[i] != 0) {
+                    fail("Expected byte element at position " + i + " to be 
zero value");
+                }
+            }
+
+            // Clear
+            RestAssured.given()
+                    .queryParam("pageStart", 0)
+                    .queryParam("pageEnd", 1023)
+                    .post("/azure-storage-blob/page/blob/clear")
+                    .then()
+                    .statusCode(200)
+                    .body(is("true"));
+
+            // Read after clear
+            pageData = RestAssured.get("/azure-storage-blob/blob/read/bytes")
+                    .then()
+                    .statusCode(200)
+                    .extract()
+                    .body()
+                    .asByteArray();
+
+            // Verify all page data is empty
+            for (int i = 0; i < pageData.length; i++) {
+                if (pageData[i] != 0) {
+                    fail("Expected byte element at position " + i + " to be 
zero value");
+                }
+            }
+        } finally {
+            // Delete
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
     }
 
+    @Test
+    public void blobContainer() {
+        String alternativeContainerName = "cq-test-" + UUID.randomUUID();
+
+        try {
+            // Create
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .post("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(201);
+
+            // List
+            String containerName = 
ConfigProvider.getConfig().getValue("azure.blob.container.name", String.class);
+            RestAssured.get("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(200)
+                    .body("containers.name",
+                            containsInAnyOrder(containerName, 
alternativeContainerName));
+        } finally {
+            // Delete
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .delete("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void copyBlob() {
+        String alternativeContainerName = "cq-test-" + UUID.randomUUID();
+
+        try {
+            // Create container to copy to
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .post("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(201);
+
+            // List
+            String containerName = 
ConfigProvider.getConfig().getValue("azure.blob.container.name", String.class);
+            RestAssured.get("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(200)
+                    .body("containers.name",
+                            containsInAnyOrder(containerName, 
alternativeContainerName));
+
+            // Create blob in first container
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Read
+            RestAssured.get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(BLOB_CONTENT));
+
+            // Copy blob to alternate storage container
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .post("/azure-storage-blob/blob/copy")
+                    .then()
+                    .statusCode(200);
+
+            // Read blob from alternate storage container
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .get("/azure-storage-blob/blob/read")
+                    .then()
+                    .statusCode(200)
+                    .body(is(BLOB_CONTENT));
+        } finally {
+            // Delete
+            RestAssured.given()
+                    .queryParam("containerName", alternativeContainerName)
+                    .delete("/azure-storage-blob/blob/container")
+                    .then()
+                    .statusCode(204);
+
+            RestAssured.delete("/azure-storage-blob/blob/delete")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    @Test
+    public void blobConsumer() {
+        try {
+            // Start blob consumer
+            RestAssured.given()
+                    .post("/azure-storage-blob/consumer/true")
+                    .then()
+                    .statusCode(204);
+
+            // Create blob
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .body(BLOB_CONTENT)
+                    .post("/azure-storage-blob/blob/create")
+                    .then()
+                    .statusCode(201);
+
+            // Fetch results
+            RestAssured.get("/azure-storage-blob/consumed/blobs")
+                    .then()
+                    .statusCode(200)
+                    .body(is(BLOB_CONTENT));
+        } finally {
+            // Stop blob consumer
+            RestAssured.given()
+                    .post("/azure-storage-blob/consumer/false")
+                    .then()
+                    .statusCode(204);
+        }
+    }
+
+    // Change feed is not available in Azurite
+    @EnabledIf({ MockBackendDisabled.class })

Review comment:
       Nice !




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to