This is an automated email from the ASF dual-hosted git repository.
zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new fa8f9d9481 Fix #4793 to update MyBatisConsumerTest and keep awaitility
in the test scope (#4932)
fa8f9d9481 is described below
commit fa8f9d9481ce13e19c87b950c4b6bdf072a209b5
Author: Zheng Feng <[email protected]>
AuthorDate: Fri May 26 17:16:08 2023 +0800
Fix #4793 to update MyBatisConsumerTest and keep awaitility in the test
scope (#4932)
---
integration-tests/mybatis/pom.xml | 9 ++---
.../component/mybatis/it/MybatisResource.java | 20 +++++-------
.../component/mybatis/it/MyBatisConsumerTest.java | 38 ++++++++++++++++------
3 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/integration-tests/mybatis/pom.xml
b/integration-tests/mybatis/pom.xml
index 1aace23105..9bbfe5d450 100644
--- a/integration-tests/mybatis/pom.xml
+++ b/integration-tests/mybatis/pom.xml
@@ -59,10 +59,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
</dependency>
- <dependency>
- <groupId>org.awaitility</groupId>
- <artifactId>awaitility</artifactId>
- </dependency>
<!-- test dependencies -->
<dependency>
@@ -80,6 +76,11 @@
<artifactId>quarkus-test-h2</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
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 560fb5c72f..87761ec232 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,7 +18,6 @@ package org.apache.camel.quarkus.component.mybatis.it;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -37,9 +36,6 @@ 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
@@ -132,19 +128,21 @@ public class MybatisResource {
@Path("/consumer")
@GET
- @Produces(MediaType.APPLICATION_JSON)
- public List consumer() throws Exception {
+ @Produces(MediaType.TEXT_PLAIN)
+ public Integer consumer() throws Exception {
MockEndpoint results = context.getEndpoint("mock:results",
MockEndpoint.class);
results.expectedMessageCount(2);
context.getRouteController().startRoute("mybatis-consumer");
MockEndpoint.assertIsSatisfied(context);
- List<?> body = await()
- .atMost(1, TimeUnit.SECONDS)
- .until(() ->
template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList",
null, List.class),
- Matchers.notNullValue());
+ return results.getReceivedCounter();
+ }
- return body;
+ @Path("/afterConsumer")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public List afterConsumer() {
+ return
template.requestBody("mybatis:selectProcessedAccounts?statementType=SelectList",
null, List.class);
}
}
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
index fd138b29f0..f1e8f4673b 100644
---
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
@@ -17,13 +17,20 @@
package org.apache.camel.quarkus.component.mybatis.it;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.h2.H2DatabaseTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
+import io.restassured.path.json.JsonPath;
+import org.apache.camel.quarkus.component.mybatis.it.entity.Account;
+import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.Matchers.equalTo;
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
@QuarkusTest
@QuarkusTestResource(H2DatabaseTestResource.class)
@@ -34,14 +41,25 @@ public class MyBatisConsumerTest {
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("[email protected]"))
- .body("[1].id", equalTo(456))
- .body("[1].firstName", equalTo("Claus"))
- .body("[1].lastName", equalTo("Ibsen"))
- .body("[1].emailAddress", equalTo("[email protected]"));
+ .body(is("2"));
+
+ Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(10,
TimeUnit.SECONDS).until(() -> {
+ final JsonPath body =
given().get("/mybatis/afterConsumer").then().extract().body().jsonPath();
+ if (body != null) {
+ List<Account> accounts = body.getList("", Account.class);
+ return accounts.size() == 2 &&
+ accounts.get(0).getId() == 123 &&
+ accounts.get(0).getFirstName().equals("James") &&
+ accounts.get(0).getLastName().equals("Strachan") &&
+
accounts.get(0).getEmailAddress().equals("[email protected]") &&
+ accounts.get(1).getId() == 456 &&
+ accounts.get(1).getFirstName().equals("Claus") &&
+ accounts.get(1).getLastName().equals(("Ibsen")) &&
+
accounts.get(1).getEmailAddress().equals("[email protected]");
+
+ } else {
+ return false;
+ }
+ });
}
}