ppalaga commented on a change in pull request #2694:
URL: https://github.com/apache/camel-quarkus/pull/2694#discussion_r642458144



##########
File path: 
integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
##########
@@ -66,4 +78,169 @@ public void testSqlStoredComponent() {
                 .statusCode(200)
                 .body(is("15"));
     }
+
+    @Test
+    public void testConsumer() throws InterruptedException {
+        testConsumer(1, "consumerRoute");
+    }
+
+    @Test
+    public void testClasspathConsumer() throws InterruptedException {
+        testConsumer(2, "consumerClasspathRoute");
+    }
+
+    @Test
+    public void testFileConsumer() throws InterruptedException {
+        testConsumer(3, "consumerFileRoute");
+    }
+
+    private void testConsumer(int id, String routeId) throws 
InterruptedException {
+        route(routeId, "start", "Started");
+
+        Map project = CollectionHelper.mapOf("ID", id, "PROJECT", routeId, 
"LICENSE", "222", "PROCESSED", false);
+        Map updatedProject = CollectionHelper.mapOf("ID", id, "PROJECT", 
routeId, "LICENSE", "XXX", "PROCESSED", false);
+
+        postMapWithParam("/sql/insert",
+                "table", "projects",
+                project)
+                        .statusCode(201);
+
+        //wait for the record to be caught
+        Thread.sleep(500);
+
+        RestAssured.get("/sql/get/results/" + routeId)
+                .then()
+                .statusCode(200)
+                .body("size()", is(1), "$", hasItem(project));
+
+        //update
+        postMapWithParam("/sql/update",
+                "table", "projects",
+                updatedProject)
+                        .statusCode(201);
+
+        Thread.sleep(500);
+
+        RestAssured.get("/sql/get/results/" + routeId)
+                .then()
+                .statusCode(200)
+                .body("size()", is(1), "$", hasItem(updatedProject));
+
+        route(routeId, "stop", "Stopped");
+    }
+
+    @Test
+    public void testTransacted() throws InterruptedException {
+
+        postMap("/sql/toDirect/transacted", 
CollectionHelper.mapOf(SqlConstants.SQL_QUERY,
+                "insert into projects values (5, 'Transacted', 'ASF', false)",
+                "rollback", false))
+                        .statusCode(204);
+
+        postMap("/sql/toDirect/transacted", 
CollectionHelper.mapOf(SqlConstants.SQL_QUERY,
+                "select * from projects where project = 'Transacted'"))
+                        .statusCode(200)
+                        .body("size()", is(1));
+
+        postMap("/sql/toDirect/transacted", 
CollectionHelper.mapOf(SqlConstants.SQL_QUERY,
+                "insert into projects values (6, 'Transacted', 'ASF', false)",
+                "rollback", true))
+                        .statusCode(200)
+                        .body(is("java.lang.Exception:forced Exception"));
+
+        postMap("/sql/toDirect/transacted",
+                CollectionHelper.mapOf(SqlConstants.SQL_QUERY, "select * from 
projects where project = 'Transacted'"))
+                        .statusCode(200)
+                        .body("size()", is(1));
+    }
+
+    @Test
+    public void testDefaultErrorCode() throws InterruptedException {
+        postMap("/sql/toDirect/transacted", 
CollectionHelper.mapOf(SqlConstants.SQL_QUERY, "select * from NOT_EXIST order 
id"))
+                .statusCode(200)
+                
.body(startsWith("org.springframework.jdbc.BadSqlGrammarException"));
+    }
+
+    @Test
+    public void testIdempotentRepository() {
+        // add value with key 1
+        postMapWithParam("/sql/toDirect/idempotent",
+                "body", "one",
+                CollectionHelper.mapOf("messageId", "1"))
+                        .statusCode(200);
+
+        // add value with key 2
+        postMapWithParam("/sql/toDirect/idempotent",
+                "body", "two",
+                CollectionHelper.mapOf("messageId", "2"))
+                        .statusCode(200);
+
+        // add same value with key 3
+        postMapWithParam("/sql/toDirect/idempotent",
+                "body", "three",
+                CollectionHelper.mapOf("messageId", "3"))
+                        .statusCode(200);
+
+        // add another value with key 1 -- this one is supposed to be skipped
+        postMapWithParam("/sql/toDirect/idempotent",
+                "body", "four",
+                CollectionHelper.mapOf("messageId", "1"))
+                        .statusCode(200);
+
+        // get all values from the result map
+        await().atMost(5, TimeUnit.SECONDS).until(() -> (Iterable<? extends 
String>) RestAssured
+                
.get("/sql/get/results/idempotentRoute").then().extract().as(List.class),
+                containsInAnyOrder("one", "two", "three"));
+    }
+
+    @Test
+    @Disabled //see https://github.com/apache/camel-quarkus/issues/2693
+    public void testAggregationRepository() {
+        postMapWithParam("/sql/toDirect/aggregation", "body", "A", 
CollectionHelper.mapOf("messageId", "123"))
+                .statusCode(200);
+
+        postMapWithParam("/sql/toDirect/aggregation", "body", "B", 
CollectionHelper.mapOf("messageId", "123"))
+                .statusCode(200);
+
+        postMapWithParam("/sql/toDirect/aggregation", "body", "C", 
CollectionHelper.mapOf("messageId", "123"))
+                .statusCode(200);
+
+        postMapWithParam("/sql/toDirect/aggregation", "body", "D", 
CollectionHelper.mapOf("messageId", "123"))
+                .statusCode(200);

Review comment:
       Plz. do not change anything, maybe it is just me :)




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to