You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2023/04/14 05:32:00 UTC

[camel-quarkus] branch 2.13.x updated (ac03cf63df -> bd98715259)

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

zhfeng pushed a change to branch 2.13.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


    from ac03cf63df Cxf fixes (#4771)
     new 8c368fa7d6 Fix #4717 to expand camel-quarkus-mybatis test coverage
     new bd98715259 Fix #4781 Intermittent failure of MyBatisConsumerTest

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 integration-tests/mybatis/pom.xml                  |   8 +-
 .../quarkus/component/mybatis/it/MyBatisRoute.java |  36 +++++-
 .../component/mybatis/it/MybatisResource.java      |  76 +++++++++++
 .../src/main/resources/application.properties      |   2 +
 .../mybatis/src/main/resources/insert.sql          |   7 +-
 .../component/mybatis/it/MyBatisConsumerTest.java} |  36 +++---
 .../quarkus/component/mybatis/it/MyBatisTest.java  | 141 ++++++++++++++++++++-
 7 files changed, 275 insertions(+), 31 deletions(-)
 copy integration-tests/{pgevent/src/test/java/org/apache/camel/quarkus/component/pgevent/it/PgeventTest.java => mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisConsumerTest.java} (56%)


[camel-quarkus] 01/02: Fix #4717 to expand camel-quarkus-mybatis test coverage

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8c368fa7d6d7fabef7841b1c2c31be2b811b7515
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Wed Apr 12 22:26:46 2023 +0800

    Fix #4717 to expand camel-quarkus-mybatis test coverage
---
 integration-tests/mybatis/pom.xml                  |   4 +-
 .../quarkus/component/mybatis/it/MyBatisRoute.java |  36 +++++-
 .../component/mybatis/it/MybatisResource.java      |  67 ++++++++++
 .../src/main/resources/application.properties      |   2 +
 .../mybatis/src/main/resources/insert.sql          |   7 +-
 .../component/mybatis/it/MyBatisConsumerTest.java  |  47 +++++++
 .../quarkus/component/mybatis/it/MyBatisTest.java  | 141 ++++++++++++++++++++-
 7 files changed, 292 insertions(+), 12 deletions(-)

diff --git a/integration-tests/mybatis/pom.xml b/integration-tests/mybatis/pom.xml
index e45bc4f85e..9243f2d594 100644
--- a/integration-tests/mybatis/pom.xml
+++ b/integration-tests/mybatis/pom.xml
@@ -37,11 +37,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-mock</artifactId>
+            <artifactId>camel-quarkus-jta</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-jta</artifactId>
+            <artifactId>camel-quarkus-mock</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
diff --git a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisRoute.java b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisRoute.java
index 6747a88939..1c2833b246 100644
--- a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisRoute.java
+++ b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisRoute.java
@@ -20,23 +20,49 @@ package org.apache.camel.quarkus.component.mybatis.it;
 import javax.enterprise.context.ApplicationScoped;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.quarkus.component.mybatis.it.entity.Account;
 
 @ApplicationScoped
 public class MyBatisRoute extends RouteBuilder {
     @Override
     public void configure() throws Exception {
         from("direct:selectOne")
-                .to("mybatis:selectAccountById?statementType=SelectOne")
-                .to("mock:result");
+                .to("mybatis:selectAccountById?statementType=SelectOne");
+
+        from("direct:selectList")
+                .to("mybatis:selectAllAccounts?statementType=SelectList");
 
         from("direct:insertOne")
                 .transacted()
                 .to("mybatis:insertAccount?statementType=Insert")
-                .to("mock:result");
+                .process(exchange -> {
+                    Account account = exchange.getIn().getBody(Account.class);
+                    if (account.getFirstName().equals("Rollback")) {
+                        throw new RuntimeException("Rollback");
+                    }
+                });
+
+        from("direct:insertList")
+                .transacted()
+                .to("mybatis:batchInsertAccount?statementType=InsertList");
 
         from("direct:deleteOne")
                 .transacted()
-                .to("mybatis:deleteAccountById?statementType=Delete")
-                .to("mock:result");
+                .to("mybatis:deleteAccountById?statementType=Delete");
+
+        from("direct:deleteList")
+                .transacted()
+                .to("mybatis:batchDeleteAccountById?statementType=DeleteList");
+
+        from("direct:updateOne")
+                .transacted()
+                .to("mybatis:updateAccount?statementType=Update");
+
+        from("direct:updateList")
+                .transacted()
+                .to("mybatis:batchUpdateAccount?statementType=UpdateList");
+
+        from("mybatis:selectUnprocessedAccounts?onConsume=consumeAccount").routeId("mybatis-consumer").autoStartup(false)
+                .to("mock:results");
     }
 }
diff --git a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
index 27924c7f08..550b982144 100644
--- a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
+++ b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.quarkus.component.mybatis.it;
 
+import java.util.List;
+import java.util.Map;
+
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.transaction.Transactional;
@@ -23,18 +26,23 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.NotFoundException;
+import javax.ws.rs.PATCH;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.quarkus.component.mybatis.it.entity.Account;
 
 @Path("/mybatis")
 @ApplicationScoped
 public class MybatisResource {
+    @Inject
+    CamelContext context;
 
     @Inject
     ProducerTemplate template;
@@ -50,6 +58,13 @@ public class MybatisResource {
         return account;
     }
 
+    @Path("/selectList")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public List selectList() {
+        return template.requestBody("direct:selectList", null, List.class);
+    }
+
     @Path("/insertOne")
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
@@ -60,6 +75,16 @@ public class MybatisResource {
         return getCounts();
     }
 
+    @Path("/insertList")
+    @POST
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    @Transactional
+    public Integer insertList(List<Account> accounts) {
+        template.sendBody("direct:insertList", accounts);
+        return getCounts();
+    }
+
     @Path("/deleteOne")
     @DELETE
     @Produces(MediaType.TEXT_PLAIN)
@@ -69,7 +94,49 @@ public class MybatisResource {
         return getCounts();
     }
 
+    @Path("/deleteList")
+    @DELETE
+    @Produces(MediaType.TEXT_PLAIN)
+    @Transactional
+    public Integer deleteList(List<Integer> ids) {
+        template.sendBody("direct:deleteList", ids);
+        return getCounts();
+    }
+
+    @Path("/updateOne")
+    @PATCH
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    @Transactional
+    public Integer updateOne(Account account) {
+        template.sendBody("direct:updateOne", account);
+        return getCounts();
+    }
+
+    @Path("/updateList")
+    @PATCH
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.TEXT_PLAIN)
+    @Transactional
+    public Integer updateList(Map<String, Object> params) {
+        template.sendBody("direct:updateList", params);
+        return getCounts();
+    }
+
     private Integer getCounts() {
         return template.requestBody("mybatis:count?statementType=SelectOne", null, Integer.class);
     }
+
+    @Path("/consumer")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public List consumer() throws Exception {
+        MockEndpoint results = context.getEndpoint("mock:results", MockEndpoint.class);
+        results.expectedMessageCount(2);
+
+        context.getRouteController().startRoute("mybatis-consumer");
+        MockEndpoint.assertIsSatisfied(context);
+
+        return template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class);
+    }
 }
diff --git a/integration-tests/mybatis/src/main/resources/application.properties b/integration-tests/mybatis/src/main/resources/application.properties
index 6f32aa9595..a513710e03 100644
--- a/integration-tests/mybatis/src/main/resources/application.properties
+++ b/integration-tests/mybatis/src/main/resources/application.properties
@@ -20,6 +20,8 @@ quarkus.datasource.username=username-default
 quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:default
 quarkus.datasource.jdbc.transactions=xa
 
+quarkus.transaction-manager.enable-recovery=true
+
 quarkus.mybatis.environment=development
 quarkus.mybatis.xmlconfig.enable=true
 quarkus.mybatis.xmlconfig.path=SqlMapConfig.xml
diff --git a/integration-tests/mybatis/src/main/resources/insert.sql b/integration-tests/mybatis/src/main/resources/insert.sql
index c0a668569f..6c4759bd36 100644
--- a/integration-tests/mybatis/src/main/resources/insert.sql
+++ b/integration-tests/mybatis/src/main/resources/insert.sql
@@ -21,9 +21,10 @@ CREATE TABLE ACCOUNT (
     ACC_ID INTEGER,
     ACC_FIRST_NAME VARCHAR(255),
     ACC_LAST_NAME VARCHAR(255),
-    ACC_EMAIL VARCHAR(255)
+    ACC_EMAIL VARCHAR(255),
+    PROCESSED BOOLEAN DEFAULT false
 );
 
-INSERT INTO ACCOUNT VALUES (123, 'James', 'Strachan', 'TryGuessing@gmail.com');
-INSERT INTO ACCOUNT VALUES (456, 'Claus', 'Ibsen', 'Noname@gmail.com');
+INSERT INTO ACCOUNT VALUES (123, 'James', 'Strachan', 'TryGuessing@gmail.com', false);
+INSERT INTO ACCOUNT VALUES (456, 'Claus', 'Ibsen', 'Noname@gmail.com', false);
 
diff --git a/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisConsumerTest.java b/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisConsumerTest.java
new file mode 100644
index 0000000000..fd138b29f0
--- /dev/null
+++ b/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisConsumerTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.quarkus.component.mybatis.it;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.h2.H2DatabaseTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.equalTo;
+
+@QuarkusTest
+@QuarkusTestResource(H2DatabaseTestResource.class)
+public class MyBatisConsumerTest {
+
+    @Test
+    public void testSelectList() {
+        RestAssured.get("/mybatis/consumer")
+                .then()
+                .statusCode(200)
+                .body("size()", equalTo(2))
+                .body("[0].id", equalTo(123))
+                .body("[0].firstName", equalTo("James"))
+                .body("[0].lastName", equalTo("Strachan"))
+                .body("[0].emailAddress", equalTo("TryGuessing@gmail.com"))
+                .body("[1].id", equalTo(456))
+                .body("[1].firstName", equalTo("Claus"))
+                .body("[1].lastName", equalTo("Ibsen"))
+                .body("[1].emailAddress", equalTo("Noname@gmail.com"));
+    }
+}
diff --git a/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java b/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java
index 0d72ad6d9b..e9f9bcc457 100644
--- a/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java
+++ b/integration-tests/mybatis/src/test/java/org/apache/camel/quarkus/component/mybatis/it/MyBatisTest.java
@@ -16,6 +16,12 @@
  */
 package org.apache.camel.quarkus.component.mybatis.it;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.h2.H2DatabaseTestResource;
 import io.quarkus.test.junit.QuarkusTest;
@@ -33,9 +39,16 @@ public class MyBatisTest {
     public void tests() {
         testSelectOne();
         testSelectOneNotFound();
+        testSelectList();
+        testUpdateOne();
+        testUpdateList();
         testInsert();
+        testInsertList();
+        testInsertRollback();
+        testSelectOneNotFound();
         testDelete();
         testDeleteNotFound();
+        testDeleteList();
     }
 
     public void testSelectOne() {
@@ -54,6 +67,21 @@ public class MyBatisTest {
                 .statusCode(404);
     }
 
+    public void testSelectList() {
+        RestAssured.get("/mybatis/selectList")
+                .then()
+                .statusCode(200)
+                .body("size()", equalTo(2))
+                .body("[0].id", equalTo(123))
+                .body("[0].firstName", equalTo("James"))
+                .body("[0].lastName", equalTo("Strachan"))
+                .body("[0].emailAddress", equalTo("TryGuessing@gmail.com"))
+                .body("[1].id", equalTo(456))
+                .body("[1].firstName", equalTo("Claus"))
+                .body("[1].lastName", equalTo("Ibsen"))
+                .body("[1].emailAddress", equalTo("Noname@gmail.com"));
+    }
+
     public void testInsert() {
         Account account = new Account();
         account.setId(444);
@@ -70,17 +98,126 @@ public class MyBatisTest {
                 .body(equalTo("3"));
     }
 
+    public void testInsertRollback() {
+        Account account = new Account();
+        account.setId(999);
+        account.setFirstName("Rollback");
+        account.setLastName("Rollback");
+        account.setEmailAddress("Rollback@gmail.com");
+
+        RestAssured.given()
+                .contentType(ContentType.JSON)
+                .body(account)
+                .post("/mybatis/insertOne")
+                .then()
+                .statusCode(500);
+    }
+
+    public void testInsertList() {
+        Account account1 = new Account();
+        account1.setId(555);
+        account1.setFirstName("Aaron");
+        account1.setLastName("Daubman");
+        account1.setEmailAddress("ReadTheDevList@gmail.com");
+
+        Account account2 = new Account();
+        account2.setId(666);
+        account2.setFirstName("Amos");
+        account2.setLastName("Feng");
+        account2.setEmailAddress("ZHENG@gmail.com");
+
+        List<Account> accountList = new ArrayList<>(2);
+
+        accountList.add(account1);
+        accountList.add(account2);
+
+        RestAssured.given()
+                .contentType(ContentType.JSON)
+                .body(accountList)
+                .post("/mybatis/insertList")
+                .then()
+                .statusCode(200)
+                .body(equalTo("5"));
+    }
+
+    public void testUpdateOne() {
+        Account account = new Account();
+        account.setId(456);
+        account.setFirstName("Claus");
+        account.setLastName("Ibsen");
+        account.setEmailAddress("Other@gmail.com");
+
+        RestAssured.given()
+                .contentType(ContentType.JSON)
+                .body(account)
+                .patch("/mybatis/updateOne")
+                .then()
+                .statusCode(200)
+                .body(equalTo("2"));
+
+        RestAssured.get("/mybatis/selectOne?id=456")
+                .then()
+                .statusCode(200)
+                .body("id", equalTo(456))
+                .body("firstName", equalTo("Claus"))
+                .body("lastName", equalTo("Ibsen"))
+                .body("emailAddress", equalTo("Other@gmail.com"));
+    }
+
+    public void testUpdateList() {
+        Account account1 = new Account();
+        account1.setId(123);
+
+        Account account2 = new Account();
+        account2.setId(456);
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("list", Arrays.asList(account1, account2));
+        params.put("emailAddress", "Update@gmail.com");
+
+        RestAssured.given()
+                .contentType(ContentType.JSON)
+                .body(params)
+                .patch("/mybatis/updateList")
+                .then()
+                .statusCode(200)
+                .body(equalTo("2"));
+
+        RestAssured.get("/mybatis/selectList")
+                .then()
+                .statusCode(200)
+                .body("size()", equalTo(2))
+                .body("[0].id", equalTo(123))
+                .body("[0].firstName", equalTo("James"))
+                .body("[0].lastName", equalTo("Strachan"))
+                .body("[0].emailAddress", equalTo("Update@gmail.com"))
+                .body("[1].id", equalTo(456))
+                .body("[1].firstName", equalTo("Claus"))
+                .body("[1].lastName", equalTo("Ibsen"))
+                .body("[1].emailAddress", equalTo("Update@gmail.com"));
+    }
+
     public void testDelete() {
         RestAssured.delete("/mybatis/deleteOne?id=456")
                 .then()
                 .statusCode(200)
-                .body(equalTo("2"));
+                .body(equalTo("4"));
     }
 
     public void testDeleteNotFound() {
         RestAssured.delete("/mybatis/deleteOne?id=999")
                 .then()
                 .statusCode(200)
-                .body(equalTo("2"));
+                .body(equalTo("4"));
+    }
+
+    public void testDeleteList() {
+        RestAssured.given()
+                .contentType(ContentType.JSON)
+                .body(Arrays.asList(444, 555, 666))
+                .delete("/mybatis/deleteList")
+                .then()
+                .statusCode(200)
+                .body(equalTo("1"));
     }
 }


[camel-quarkus] 02/02: Fix #4781 Intermittent failure of MyBatisConsumerTest

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bd987152594191c52e2f2e6300e8f3d70ea5c767
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Fri Apr 14 10:45:06 2023 +0800

    Fix #4781 Intermittent failure of MyBatisConsumerTest
---
 integration-tests/mybatis/pom.xml                             |  4 ++++
 .../camel/quarkus/component/mybatis/it/MybatisResource.java   | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/integration-tests/mybatis/pom.xml b/integration-tests/mybatis/pom.xml
index 9243f2d594..3be4067f9e 100644
--- a/integration-tests/mybatis/pom.xml
+++ b/integration-tests/mybatis/pom.xml
@@ -59,6 +59,10 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-jdbc-h2</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+        </dependency>
 
         <!-- test dependencies -->
         <dependency>
diff --git a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
index 550b982144..b5e45e2ba8 100644
--- a/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
+++ b/integration-tests/mybatis/src/main/java/org/apache/camel/quarkus/component/mybatis/it/MybatisResource.java
@@ -18,6 +18,7 @@ package org.apache.camel.quarkus.component.mybatis.it;
 
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
@@ -37,6 +38,9 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.quarkus.component.mybatis.it.entity.Account;
+import org.hamcrest.Matchers;
+
+import static org.awaitility.Awaitility.await;
 
 @Path("/mybatis")
 @ApplicationScoped
@@ -137,6 +141,11 @@ public class MybatisResource {
         context.getRouteController().startRoute("mybatis-consumer");
         MockEndpoint.assertIsSatisfied(context);
 
-        return template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class);
+        List<?> body = await()
+                .atMost(1, TimeUnit.SECONDS)
+                .until(() -> template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList", null, List.class),
+                        Matchers.notNullValue());
+
+        return body;
     }
 }