You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2023/03/24 13:27:09 UTC
[camel-quarkus] branch main updated: Ref #4596: Expand JDBC tests - named parameters and samples (#4655)
This is an automated email from the ASF dual-hosted git repository.
aldettinger 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 b5a0a66588 Ref #4596: Expand JDBC tests - named parameters and samples (#4655)
b5a0a66588 is described below
commit b5a0a66588db48aa5d5c8dcaf54cfc1214c9ec31
Author: Lucia Drozdová <89...@users.noreply.github.com>
AuthorDate: Fri Mar 24 14:27:02 2023 +0100
Ref #4596: Expand JDBC tests - named parameters and samples (#4655)
* Ref #4596: Expand JDBC tests - named parameters and samples
* Fix imports
---
integration-tests/jdbc/pom.xml | 43 ++++++++++++++++
.../quarkus/component/jdbc/CamelResource.java | 45 +++++++++++++++++
.../camel/quarkus/component/jdbc/JdbcRoutes.java | 18 +++++++
.../quarkus/component/jdbc/CamelJdbcTest.java | 58 +++++++++++++++++++---
4 files changed, 158 insertions(+), 6 deletions(-)
diff --git a/integration-tests/jdbc/pom.xml b/integration-tests/jdbc/pom.xml
index 209c724663..1fa8ecc7fc 100644
--- a/integration-tests/jdbc/pom.xml
+++ b/integration-tests/jdbc/pom.xml
@@ -40,6 +40,14 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-timer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean</artifactId>
+ </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
@@ -56,6 +64,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-mock</artifactId>
+ </dependency>
<!-- test dependencies -->
<dependency>
@@ -73,6 +85,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -139,6 +156,32 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-timer-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bean-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
</profile>
</profiles>
diff --git a/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/CamelResource.java b/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/CamelResource.java
index 84ead295cb..e10f1f1bb4 100644
--- a/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/CamelResource.java
+++ b/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/CamelResource.java
@@ -22,6 +22,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import io.agroal.api.AgroalDataSource;
import io.quarkus.agroal.DataSource;
@@ -35,7 +36,9 @@ import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.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.jdbc.model.Camel;
@Path("/test")
@@ -48,6 +51,9 @@ public class CamelResource {
@Inject
ProducerTemplate template;
+ @Inject
+ CamelContext context;
+
@PostConstruct
void postConstruct() throws SQLException {
try (Connection con = dataSource.getConnection()) {
@@ -59,6 +65,8 @@ public class CamelResource {
}
statement.execute("create table camels (id int primary key, species varchar(255))");
statement.execute("create table camelsGenerated (id int primary key auto_increment, species varchar(255))");
+ statement.execute("create table camelsProcessed (id int primary key auto_increment, species varchar(255))");
+ statement.execute("insert into camelsGenerated (species) values ('Camelus status'), ('Camelus linus')");
statement.execute("insert into camels (id, species) values (1, 'Camelus dromedarius')");
statement.execute("insert into camels (id, species) values (2, 'Camelus bactrianus')");
statement.execute("insert into camels (id, species) values (3, 'Camelus ferus')");
@@ -137,4 +145,41 @@ public class CamelResource {
public String headersFromSelect() throws Exception {
return template.requestBody("direct://get-headers", "select * from camelsGenerated", String.class);
}
+
+ @Path("/named-parameters/headers-as-parameters")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public String headersAsParameters() throws Exception {
+ return template.requestBodyAndHeader("direct://headers-as-parameters",
+ "select * from camels where id < :?idmax order by id",
+ "idmax", "3", String.class);
+ }
+
+ @Path("/named-parameters/headers-as-parameters-map")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public String headersAsParametersMap() throws Exception {
+ Map<String, String> headersMap = Map.of("idmax", "3", "specs", "Camelus bactrianus");
+ return template.requestBodyAndHeader("direct://headers-as-parameters",
+ "select * from camels where id < :?idmax and species = :?specs order by id",
+ "CamelJdbcParameters", headersMap, String.class);
+ }
+
+ @Path("/interval-polling")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public void intervalPolling(String selectResult) throws Exception {
+ MockEndpoint mockEndpoint = context.getEndpoint("mock:interval-polling", MockEndpoint.class);
+ mockEndpoint.expectedBodiesReceived(selectResult);
+
+ mockEndpoint.assertIsSatisfied();
+ }
+
+ @Path("/move-between-datasources")
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ public String moveBetweenDatasources() throws Exception {
+ return template.requestBody("direct://move-between-datasources", null, String.class);
+ }
+
}
diff --git a/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/JdbcRoutes.java b/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/JdbcRoutes.java
index 843ef19fae..8a5141a7a4 100644
--- a/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/JdbcRoutes.java
+++ b/integration-tests/jdbc/src/main/java/org/apache/camel/quarkus/component/jdbc/JdbcRoutes.java
@@ -20,9 +20,12 @@ import jakarta.enterprise.context.ApplicationScoped;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.jboss.logging.Logger;
@ApplicationScoped
public class JdbcRoutes extends RouteBuilder {
+ private static final Logger LOG = Logger.getLogger(JdbcRoutes.class);
+
@Override
public void configure() {
from("direct://get-generated-keys")
@@ -44,5 +47,20 @@ public class JdbcRoutes extends RouteBuilder {
exchange.getIn().setBody(in);
}
});
+
+ from("direct://headers-as-parameters")
+ .to("jdbc:camel-ds?useHeadersAsParameters=true");
+
+ from("timer://interval-polling?delay=2000&repeatCount=1")
+ .setBody(constant("select * from camelsGenerated order by id desc"))
+ .to("jdbc:camel-ds")
+ .to("mock:interval-polling");
+
+ from("direct://move-between-datasources")
+ .setBody(constant("select * from camels"))
+ .to("jdbc:camel-ds")
+ .split(body())
+ .setBody(simple("insert into camelsProcessed values('${body[ID]}','${body[SPECIES]}')"))
+ .to("jdbc:camel-ds");
}
}
diff --git a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java b/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java
index 45e7255c31..9fe7dad4af 100644
--- a/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java
+++ b/integration-tests/jdbc/src/test/java/org/apache/camel/quarkus/component/jdbc/CamelJdbcTest.java
@@ -26,6 +26,7 @@ import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -96,11 +97,6 @@ public class CamelJdbcTest {
@Test
void testHeadersFromSelectQuery() {
- RestAssured.given()
- .contentType(ContentType.TEXT)
- .body("insert into camelsGenerated (species) values ('Camelus status'), ('Camelus linus')")
- .post("/test/execute");
-
RestAssured.given()
.get("test/headers/select")
.then()
@@ -114,8 +110,58 @@ public class CamelJdbcTest {
.and()
.body(not(containsString("CamelGeneratedColumns")))
.and()
- .body(containsString("CamelJdbcRowCount=2"))
+ .body(containsString("CamelJdbcRowCount"))
.and()
.body(containsString("CamelJdbcColumnNames=[ID, SPECIES]"));
}
+
+ @Test
+ void testNamedParameters() {
+ RestAssured.given()
+ .get("test/named-parameters/headers-as-parameters")
+ .then()
+ .body(containsString("{ID=1, SPECIES=Camelus dromedarius}"))
+ .and()
+ .body(containsString("{ID=2, SPECIES=Camelus bactrianus}"));
+ }
+
+ @Test
+ void testCamelJdbcParametersHeader() {
+ RestAssured.given()
+ .get("test/named-parameters/headers-as-parameters-map")
+ .then()
+ .body(containsString("{ID=2, SPECIES=Camelus bactrianus}"));
+ }
+
+ @Test
+ void testTimeIntervalDatabasePolling() {
+ String selectResult = RestAssured.given()
+ .contentType(ContentType.TEXT).body("select * from camelsGenerated order by id desc")
+ .post("/test/execute")
+ .then().extract().body().asString();
+
+ RestAssured.given()
+ .body(selectResult)
+ .get("/test/interval-polling")
+ .then()
+ .statusCode(204);
+ }
+
+ @Test
+ void testMoveDataBetweenDatasources() {
+ String camelsDbResult = RestAssured.given()
+ .contentType(ContentType.TEXT).body("select * from camels order by id desc")
+ .post("/test/execute")
+ .then().extract().body().asString();
+
+ RestAssured.given()
+ .post("test/move-between-datasources");
+
+ RestAssured.given()
+ .contentType(ContentType.TEXT).body("select * from camelsProcessed order by id desc")
+ .post("/test/execute")
+ .then()
+ .body(equalTo(camelsDbResult));
+ }
+
}