JinyuChen97 commented on code in PR #8500:
URL: https://github.com/apache/camel-quarkus/pull/8500#discussion_r3028057255
##########
integration-tests/ibm-cos/src/test/java/org/apache/camel/quarkus/component/ibm/cos/it/IBMCloudObjectStorageTest.java:
##########
@@ -31,54 +44,438 @@
@EnabledIfSystemProperty(named = "camel.ibm.cos.serviceInstanceId", matches =
".*", disabledReason = "IBM COS Service Instance ID not provided")
@EnabledIfSystemProperty(named = "camel.ibm.cos.endpointUrl", matches = ".*",
disabledReason = "IBM COS Endpoint URL not provided")
@QuarkusTest
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class IBMCloudObjectStorageTest {
@Test
+ @Order(0)
+ void setup() {
+ // Cleanup any existing bucket with same name first
+ cleanupBucket();
+
+ // Create Bucket (shared by all tests)
+ given()
+ .post("/ibm-cos/bucket/create")
+ .then()
+ .statusCode(201);
+ }
+
+ @Test
+ @Order(1)
void basicOperations() {
- try {
- // Create Bucket
+ // Bucket already exists from setup test
+
+ String contentInitial = "Hello Camel Quarkus IBM Cloud Object Storage";
+
+ // Create Object
+ given()
+ .contentType(ContentType.TEXT)
+ .body(contentInitial)
+ .post("/ibm-cos/object/put")
+ .then()
+ .statusCode(201);
+
+ // Read Object
+ given()
+ .get("/ibm-cos/object/read")
+ .then()
+ .statusCode(200)
+ .body(is(contentInitial));
+
+ // List Objects in bucket
+ given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .body("objects[0].key",
is(IBMCloudObjectStorageRoutes.KEY_OF_OBJECT_CREATED));
+
+ // Delete Object
+ given()
+ .body(contentInitial)
+ .post("/ibm-cos/object/delete")
+ .then()
+ .statusCode(201);
+
+ // Don't delete bucket - shared with other tests
+ }
+
+ @Test
+ @Order(2)
+ void consumerBasic() {
+ final String content = "Hello Consumer";
+
+ // Bucket already exists from basicOperations test
+
+ // Reset mock endpoint before test
+ resetMockEndpoint();
+
+ // Upload object
+ given()
+ .contentType(ContentType.TEXT)
+ .body(content)
+ .post("/ibm-cos/object/put")
+ .then()
+ .statusCode(201);
+
+ // Start consumer
+ given()
+ .post("/ibm-cos/consumer/start")
+ .then()
+ .statusCode(204);
+
+ // Wait for consumer to receive the message
+ await().atMost(10, TimeUnit.SECONDS)
+ .pollDelay(500, TimeUnit.MILLISECONDS)
+ .pollInterval(500, TimeUnit.MILLISECONDS)
+ .until(() -> {
+ String countStr = given().get("/ibm-cos/consumer/count")
+ .then().statusCode(200).extract().asString();
+ int count = Integer.parseInt(countStr);
+ return count >= 1;
+ });
+
+ // Stop consumer
+ given()
+ .post("/ibm-cos/consumer/stop")
+ .then()
+ .statusCode(204);
+
+ // Get consumed messages
+ String consumedMessages = given()
+ .get("/ibm-cos/consumer")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ // Verify message consumed
+ Assertions.assertEquals(content, consumedMessages);
+
+ // Verify object deleted (deleteAfterRead)
+ int objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
+
+ Assertions.assertEquals(0, objectCount);
+
+ // Don't delete bucket - shared with other tests
+ }
+
+ @Test
+ @Order(3)
+ void consumerMultipleObjects() {
+ final Map<String, String> objectsToUpload = new HashMap<>();
+ objectsToUpload.put("obj-1", "Content 1");
+ objectsToUpload.put("obj-2", "Content 2");
+ objectsToUpload.put("obj-3", "Content 3");
+ objectsToUpload.put("obj-4", "Content 4");
+ objectsToUpload.put("obj-5", "Content 5");
+
+ // Bucket already exists from basicOperations test
+
+ // Reset mock endpoint before test
+ resetMockEndpoint();
+
+ // Upload 5 objects with different keys
+ for (Map.Entry<String, String> entry : objectsToUpload.entrySet()) {
given()
- .post("/ibm-cos/bucket/create")
+ .contentType(ContentType.TEXT)
+ .body(entry.getValue())
+ .post("/ibm-cos/object/put/" + entry.getKey())
.then()
.statusCode(201);
+ }
+
+ // Start consumer
+ given()
+ .post("/ibm-cos/consumer/start")
+ .then()
+ .statusCode(204);
+
+ // Wait for consumer to receive all 5 messages
+ await().atMost(20, TimeUnit.SECONDS)
+ .pollDelay(500, TimeUnit.MILLISECONDS)
+ .pollInterval(500, TimeUnit.MILLISECONDS)
+ .until(() -> {
+ String countStr = given().get("/ibm-cos/consumer/count")
+ .then().statusCode(200).extract().asString();
+ int count = Integer.parseInt(countStr);
+ return count >= 5;
+ });
+
+ // Stop consumer
+ given()
+ .post("/ibm-cos/consumer/stop")
+ .then()
+ .statusCode(204);
+
+ // Get consumed messages
+ String consumedMessages = given()
+ .get("/ibm-cos/consumer")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ // Verify all messages consumed (split by newline)
+ String[] messages = consumedMessages.split("\n");
+ Assertions.assertEquals(5, messages.length);
- String contentInitial = "Hello Camel Quarkus IBM Cloud Object
Storage";
+ // Verify all contents present
+ Set<String> expectedContents = new HashSet<>(objectsToUpload.values());
+ Set<String> actualContents = new HashSet<>(Arrays.asList(messages));
+ Assertions.assertEquals(expectedContents, actualContents);
- // Create Object
+ // Verify bucket empty (all objects deleted)
+ int objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
+
+ Assertions.assertEquals(0, objectCount);
+
+ // Don't delete bucket - shared with other tests
+ }
+
+ @Test
+ @Order(4)
+ void multipleObjectsOperations() {
+ final Map<String, String> objectsToUpload = new HashMap<>();
+ objectsToUpload.put("obj-1", "Content for obj-1");
+ objectsToUpload.put("obj-2", "Content for obj-2");
+ objectsToUpload.put("obj-3", "Content for obj-3");
+ objectsToUpload.put("obj-4", "Content for obj-4");
+ objectsToUpload.put("obj-5", "Content for obj-5");
+
+ // Bucket already exists from basicOperations test
+
+ // Upload 5 objects with different keys
+ for (Map.Entry<String, String> entry : objectsToUpload.entrySet()) {
given()
.contentType(ContentType.TEXT)
- .body(contentInitial)
- .post("/ibm-cos/object/put")
+ .body(entry.getValue())
+ .post("/ibm-cos/object/put/" + entry.getKey())
.then()
.statusCode(201);
+ }
- // Read Object
- given()
- .get("/ibm-cos/object/read")
- .then()
- .statusCode(200)
- .body(is(contentInitial));
+ // List objects - verify 5 objects
+ int objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
- // List Objects in bucket
- given()
- .get("/ibm-cos/list")
+ Assertions.assertEquals(5, objectCount);
+
+ // Get each object - verify content
+ for (Map.Entry<String, String> entry : objectsToUpload.entrySet()) {
+ String content = given()
+ .get("/ibm-cos/object/read/" + entry.getKey())
.then()
.statusCode(200)
- .body("objects[0].key",
is(IBMCloudObjectStorageRoutes.KEY_OF_OBJECT_CREATED));
+ .extract()
+ .body().asString();
- // Delete Object
- given()
- .body(contentInitial)
- .post("/ibm-cos/object/delete")
- .then()
- .statusCode(201);
+ Assertions.assertEquals(entry.getValue(), content);
+ }
- } finally {
- // Delete Bucket
- given()
- .post("/ibm-cos/bucket/delete")
- .then()
- .statusCode(201);
+ // Copy object obj-1 to obj-1-copy
+ given()
+ .post("/ibm-cos/object/copy/obj-1/obj-1-copy")
+ .then()
+ .statusCode(201);
+
+ // Verify copy exists and content matches
+ String copiedContent = given()
+ .get("/ibm-cos/object/read/obj-1-copy")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ Assertions.assertEquals("Content for obj-1", copiedContent);
+
+ // List objects - verify 6 objects now
+ objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
+
+ Assertions.assertEquals(6, objectCount);
+
+ // Delete objects batch: obj-2, obj-3, obj-4
+ given()
+ .contentType(ContentType.JSON)
+ .body("[\"obj-2\", \"obj-3\", \"obj-4\"]")
+ .post("/ibm-cos/objects/delete")
+ .then()
+ .statusCode(201);
+
+ // List objects - verify 3 objects remain
+ objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
+
+ Assertions.assertEquals(3, objectCount);
+
+ // Verify correct objects remain (obj-1, obj-5, obj-1-copy)
+ List<String> remainingKeys = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects.key", String.class);
+
+ Assertions.assertTrue(remainingKeys.contains("obj-1"));
+ Assertions.assertTrue(remainingKeys.contains("obj-5"));
+ Assertions.assertTrue(remainingKeys.contains("obj-1-copy"));
+
+ // Delete remaining objects using deleteObjects (batch)
+ given()
+ .contentType(ContentType.JSON)
+ .body("[\"obj-1\", \"obj-5\", \"obj-1-copy\"]")
+ .post("/ibm-cos/objects/delete")
+ .then()
+ .statusCode(201);
+
+ // List objects - verify bucket empty
+ objectCount = given()
+ .get("/ibm-cos/list")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath().getList("objects").size();
+
+ Assertions.assertEquals(0, objectCount);
+
+ // Don't delete bucket - shared with other tests
+ }
+
+ @Test
+ @Order(5)
+ void getObjectRangeOperation() {
+ final String testContent = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ // Bucket already exists from basicOperations test
+
+ // Upload object
+ given()
+ .contentType(ContentType.TEXT)
+ .body(testContent)
+ .post("/ibm-cos/object/put")
+ .then()
+ .statusCode(201);
+
+ // Get range 0-9
+ String range1 = given()
+ .queryParam("start", 0)
+ .queryParam("end", 9)
+ .get("/ibm-cos/object/range/" +
IBMCloudObjectStorageRoutes.KEY_OF_OBJECT_CREATED)
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ Assertions.assertEquals("0123456789", range1);
+
+ // Get range 10-35
+ String range2 = given()
+ .queryParam("start", 10)
+ .queryParam("end", 35)
+ .get("/ibm-cos/object/range/" +
IBMCloudObjectStorageRoutes.KEY_OF_OBJECT_CREATED)
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ Assertions.assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", range2);
+
+ // Delete object
+ given()
+ .post("/ibm-cos/object/delete")
+ .then()
+ .statusCode(201);
+
+ // Don't delete bucket - shared with other tests
+ }
+
+ @Test
+ @Order(6)
+ void autoCreateBucket() {
+ final String content = "Test autoCreateBucket content";
+
+ // Put object with autoCreateBucket=true
+ given()
+ .contentType(ContentType.TEXT)
+ .body(content)
+ .post("/ibm-cos/object/put-autocreate")
+ .then()
+ .statusCode(201);
+
+ // Read object from auto-created bucket
+ String readContent = given()
+ .get("/ibm-cos/object/read-autocreate")
+ .then()
+ .statusCode(200)
+ .extract()
+ .body().asString();
+
+ Assertions.assertEquals(content, readContent);
+ }
+
+ @Test
+ @Order(7)
+ void finalCleanup() {
+ // Cleanup all buckets
+ cleanupBucket();
+ cleanupAutoCreateBucket();
+ }
+
+ private void cleanupBucket() {
+ try {
+ given().post("/ibm-cos/bucket/delete");
+ Thread.sleep(5000);
Review Comment:
or I think I can remove this part as the clean up bucket was designed for
each test finish, but now I use one bucket for all test, so I don't need to
wait the bucket is cleaned or not.
--
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]