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 bcfe8e0e92 Ref#4596 Cover different db types for jdbc bcfe8e0e92 is described below commit bcfe8e0e92f5e8f81abe93de48aec26c93bdd8fb Author: Lucia Drozdova <ldro...@redhat.com> AuthorDate: Thu Apr 6 14:57:04 2023 +0200 Ref#4596 Cover different db types for jdbc --- integration-tests/jdbc/README.adoc | 26 +++++ integration-tests/jdbc/pom.xml | 16 +-- .../quarkus/component/jdbc/CamelResource.java | 116 ++++++++++++++++----- .../camel/quarkus/component/jdbc/JdbcRoutes.java | 28 +++-- .../jdbc/src/main/resources/application.properties | 7 +- .../jdbc/src/main/resources/sql/db2.sql | 20 ++++ .../jdbc/src/main/resources/sql/derby.sql | 20 ++++ .../jdbc/src/main/resources/sql/droptables.sql | 20 ++++ .../jdbc/src/main/resources/sql/h2.sql | 20 ++++ .../jdbc/src/main/resources/sql/inserts.sql | 22 ++++ .../jdbc/src/main/resources/sql/mariadb.sql | 20 ++++ .../jdbc/src/main/resources/sql/mssql.sql | 20 ++++ .../jdbc/src/main/resources/sql/mysql.sql | 20 ++++ .../jdbc/src/main/resources/sql/oracle.sql | 20 ++++ .../jdbc/src/main/resources/sql/postgresql.sql | 20 ++++ .../quarkus/component/jdbc/CamelJdbcTest.java | 73 ++++++------- 16 files changed, 387 insertions(+), 81 deletions(-) diff --git a/integration-tests/jdbc/README.adoc b/integration-tests/jdbc/README.adoc new file mode 100644 index 0000000000..76b30862b5 --- /dev/null +++ b/integration-tests/jdbc/README.adoc @@ -0,0 +1,26 @@ +== JDBC integration tests + +=== Default database type + +When the tests are executed without any special configuration, dev-service `H2` database is used (more details will follow). + +=== Dev-service databases + +As is described in the https://quarkus.io/guides/datasource#dev-services[documentation], several database types could be started in dev-service mode. +Running the tests against a database in dev-service mode could be achieved by addition of build property `cq.jdbcKind`. Example of usage: + +`mvn clean test -f integration-tests/jdbc/ -Dcq.jdbcKind=postgresql` + +Following databases could be started in the dev-service mode: + +- Postgresql (container) - add `-Dcq.jdbcKind=postgresql` +- MySQL (container) - add `-Dcq.jdbcKind=mysql` +- MariaDB (container) - add `-Dcq.jdbcKind=mariadb` +- H2 (in-process) used by default +- Apache Derby (in-process) - add `-Dcq.jdbcKind=derby` +- DB2 (container) (requires license acceptance) - add `-Dcq.jdbcKind=db2` +- MSSQL (container) (requires license acceptance) - add `-Dcq.jdbcKind=mssql` +- Oracle (container) - add `-Dcq.jdbcKind=oracle` + +For more information about dev-service mode, see https://quarkus.io/guides/datasource#dev-services[documentation]. + diff --git a/integration-tests/jdbc/pom.xml b/integration-tests/jdbc/pom.xml index 1194478d0b..e6352b9c22 100644 --- a/integration-tests/jdbc/pom.xml +++ b/integration-tests/jdbc/pom.xml @@ -31,6 +31,10 @@ <name>Camel Quarkus :: Integration Tests :: JDBC</name> <description>Integration tests for Camel JDBC extension</description> + <properties> + <cq.jdbcKind>h2</cq.jdbcKind> + </properties> + <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -54,7 +58,7 @@ </dependency> <dependency> <groupId>io.quarkus</groupId> - <artifactId>quarkus-jdbc-h2</artifactId> + <artifactId>quarkus-jdbc-${cq.jdbcKind}</artifactId> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> @@ -75,11 +79,6 @@ <artifactId>quarkus-junit5</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-test-h2</artifactId> - <scope>test</scope> - </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> @@ -117,6 +116,11 @@ </goals> </execution> </executions> + <configuration> + <systemPropertyVariables> + <quarkus.test.arg-line>-Dcq.jdbcKind=${cq.jdbcKind}</quarkus.test.arg-line> + </systemPropertyVariables> + </configuration> </plugin> </plugins> </build> 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 68d7258e40..04a8205c45 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 @@ -16,7 +16,12 @@ */ package org.apache.camel.quarkus.component.jdbc; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.sql.Connection; +import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -39,12 +44,16 @@ 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; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Path("/test") @ApplicationScoped public class CamelResource { + private static final Logger LOGGER = LoggerFactory.getLogger(CamelResource.class); @Inject - @DataSource("camel-ds") + @DataSource("cameldb") AgroalDataSource dataSource; @Inject @@ -53,33 +62,24 @@ public class CamelResource { @Inject CamelContext context; + @ConfigProperty(name = "quarkus.datasource.cameldb.db-kind") + String dbKind; + @PostConstruct void postConstruct() throws Exception { - try (Connection con = dataSource.getConnection()) { - try (Statement statement = con.createStatement()) { - try { - statement.execute("drop table camels"); - statement.execute("drop table camelsGenerated"); - } catch (Exception ignored) { - } - 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')"); - - context.getRouteController().startRoute("jdbc-poll"); - } - } + Connection conn = dataSource.getConnection(); + runScripts(conn, "droptables.sql"); + runScripts(conn, dbKind + ".sql"); + runScripts(conn, "inserts.sql"); + + context.getRouteController().startRoute("jdbc-poll"); } @Path("/species/{id}") @GET @Produces(MediaType.TEXT_PLAIN) public String getSpeciesById(@PathParam("id") String id) throws Exception { - return template.requestBody("jdbc:camel-ds", "select species from camels where id = " + id, String.class); + return template.requestBody("jdbc:cameldb", "select species from camels where id = " + id, String.class); } @SuppressWarnings("unchecked") @@ -88,14 +88,14 @@ public class CamelResource { @Produces(MediaType.TEXT_PLAIN) public String getSpeciesByIdWithSelectList(@PathParam("id") String id) throws Exception { List<LinkedHashMap<String, Object>> result = template - .requestBody("jdbc:camel-ds?outputType=SelectList", "select * from camels where id = " + id, List.class); + .requestBody("jdbc:cameldb?outputType=SelectList", "select * from camels where id = " + id, List.class); if (result.isEmpty()) { throw new IllegalStateException("Expected at least 1 camel result but none were found"); } LinkedHashMap<String, Object> data = result.get(0); - return data.get("SPECIES") + " " + data.get("ID"); + return data.get(getSpeciesRowName()) + " " + data.get(getIdRowName()); } @SuppressWarnings("unchecked") @@ -103,7 +103,7 @@ public class CamelResource { @GET @Produces(MediaType.TEXT_PLAIN) public String getSpeciesByIdWithDefinedType(@PathParam("id") String id) throws Exception { - List<Camel> results = template.requestBody("jdbc:camel-ds?outputClass=" + Camel.class.getName(), + List<Camel> results = template.requestBody("jdbc:cameldb?outputClass=" + Camel.class.getName(), "select * from camels where id = " + id, List.class); if (results.isEmpty()) { @@ -119,7 +119,7 @@ public class CamelResource { @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public String executeStatement(String statement) throws Exception { - return template.requestBody("jdbc:camel-ds", statement, String.class); + return template.requestBody("jdbc:cameldb", statement, String.class); } @Path("/generated-keys/rows") @@ -127,7 +127,7 @@ public class CamelResource { @Produces(MediaType.APPLICATION_JSON) public List generatedKeysRows() throws Exception { return template.requestBodyAndHeader("direct://get-generated-keys", - "insert into camelsGenerated (species) values ('Camelus testus'), ('Camelus legendarius')", + "insert into camelsGenerated (species) values ('Camelus testus')", "CamelRetrieveGeneratedKeys", "true", ArrayList.class); } @@ -136,7 +136,7 @@ public class CamelResource { @Produces(MediaType.APPLICATION_JSON) public String headersFromInsertOrUpdate() throws Exception { return template.requestBodyAndHeader("direct://get-headers", - "insert into camelsGenerated (species) values ('Camelus status'), ('Camelus linus')", + "insert into camelsGenerated (species) values ('Camelus testus')", "CamelRetrieveGeneratedKeys", "true", String.class); } @@ -151,16 +151,17 @@ public class CamelResource { @GET @Produces(MediaType.APPLICATION_JSON) public String headersAsParameters() throws Exception { + int id = 3; return template.requestBodyAndHeader("direct://headers-as-parameters", "select * from camels where id < :?idmax order by id", - "idmax", "3", String.class); + "idmax", id, 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"); + Map<String, Object> 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); @@ -183,4 +184,63 @@ public class CamelResource { return template.requestBody("direct://move-between-datasources", null, String.class); } + private void runScripts(Connection conn, String fileName) throws SQLException, IOException { + try (Statement statement = conn.createStatement()) { + try (InputStream is = Thread.currentThread().getContextClassLoader() + .getResourceAsStream("sql/" + fileName); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader reader = new BufferedReader(isr)) { + + //execute each line from the sql script as separate statement + reader.lines().filter(s -> s != null && !"".equals(s) && !s.startsWith("--")).forEach(s -> { + try { + statement.execute(s); + } catch (SQLException e) { + if (!s.toUpperCase().startsWith("DROP")) { + throw new RuntimeException(e); + } else { + LOGGER.debug(String.format("Command '%s' failed.", s)); //use debug logging + } + } + }); + } + } + + } + + @Path("/get-id-key") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getIdKey() { + switch (dbKind) { + case "postgresql": + return "id"; + case "oracle": + return "ROWID"; + case "mssql": + return "GENERATED_KEYS"; + case "mariadb": + return "insert_id"; + case "mysql": + return "GENERATED_KEY"; + default: + return "ID"; + } + } + + private String getIdRowName() { + if (dbKind.equals("h2") || dbKind.equals("oracle") || dbKind.equals("db2")) { + return "ID"; + } else { + return "id"; + } + } + + private String getSpeciesRowName() { + if (dbKind.equals("h2") || dbKind.equals("oracle") || dbKind.equals("db2")) { + return "SPECIES"; + } else { + return "species"; + } + } } 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 bab2f851ce..7b5f977cea 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,26 +20,29 @@ 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; +import org.eclipse.microprofile.config.inject.ConfigProperty; @ApplicationScoped public class JdbcRoutes extends RouteBuilder { - private static final Logger LOG = Logger.getLogger(JdbcRoutes.class); + + @ConfigProperty(name = "quarkus.datasource.cameldb.db-kind") + String dbKind; @Override public void configure() { from("direct://get-generated-keys") - .to("jdbc:camel-ds") + .to("jdbc:cameldb") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { + System.out.println(exchange.getIn().getHeaders()); Object in = exchange.getIn().getHeader("CamelGeneratedKeysRows"); exchange.getIn().setBody(in); } }); from("direct://get-headers") - .to("jdbc:camel-ds") + .to("jdbc:cameldb") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { @@ -49,18 +52,25 @@ public class JdbcRoutes extends RouteBuilder { }); from("direct://headers-as-parameters") - .to("jdbc:camel-ds?useHeadersAsParameters=true"); + .to("jdbc:cameldb?useHeadersAsParameters=true"); from("timer://interval-polling?delay=2000&repeatCount=1").routeId("jdbc-poll").autoStartup(false) .setBody(constant("select * from camelsGenerated order by id desc")) - .to("jdbc:camel-ds") + .to("jdbc:cameldb") .to("mock:interval-polling"); + String species; + if (dbKind.equals("postgresql") || dbKind.equals("mysql") || dbKind.equals("mariadb") || dbKind.equals("mssql")) { + species = "species"; + } else { + species = "SPECIES"; + } + from("direct://move-between-datasources") .setBody(constant("select * from camels")) - .to("jdbc:camel-ds") + .to("jdbc:cameldb") .split(body()) - .setBody(simple("insert into camelsProcessed values('${body[ID]}','${body[SPECIES]}')")) - .to("jdbc:camel-ds"); + .setBody(simple("insert into camelsProcessed (species) values('${body[" + species + "]}')")) + .to("jdbc:cameldb"); } } diff --git a/integration-tests/jdbc/src/main/resources/application.properties b/integration-tests/jdbc/src/main/resources/application.properties index 778b1490c7..3fae84e7b2 100644 --- a/integration-tests/jdbc/src/main/resources/application.properties +++ b/integration-tests/jdbc/src/main/resources/application.properties @@ -18,6 +18,7 @@ # # Quarkus :: DS # -quarkus.datasource.camel-ds.jdbc.url=jdbc:h2:tcp://localhost/mem:test -quarkus.datasource.camel-ds.db-kind=h2 -quarkus.datasource.camel-ds.jdbc.max-size=8 +quarkus.datasource.cameldb.db-kind=${cq.jdbcKind:h2} +quarkus.datasource.cameldb.jdbc.max-size=8 + +quarkus.native.resources.includes=sql/${cq.jdbcKind:h2}.sql,sql/inserts.sql,sql/droptables.sql \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/db2.sql b/integration-tests/jdbc/src/main/resources/sql/db2.sql new file mode 100644 index 0000000000..48e78bc85f --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/db2.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +CREATE TABLE camels (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, species VARCHAR(50) NOT NULL,PRIMARY KEY (id)) +CREATE TABLE camelsGenerated (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, species VARCHAR(50) NOT NULL,PRIMARY KEY (id)) +CREATE TABLE camelsProcessed (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, species VARCHAR(50) NOT NULL,PRIMARY KEY (id)) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/derby.sql b/integration-tests/jdbc/src/main/resources/sql/derby.sql new file mode 100644 index 0000000000..1f5485efe6 --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/derby.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +CREATE TABLE camels (id INT NOT NULL GENERATED ALWAYS AS IDENTITY,species VARCHAR(50) NOT NULL) +CREATE TABLE camelsGenerated (id INT NOT NULL GENERATED ALWAYS AS IDENTITY,species VARCHAR(50) NOT NULL) +CREATE TABLE camelsProcessed (id INT NOT NULL GENERATED ALWAYS AS IDENTITY,species VARCHAR(50) NOT NULL) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/droptables.sql b/integration-tests/jdbc/src/main/resources/sql/droptables.sql new file mode 100644 index 0000000000..7a77034cc8 --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/droptables.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +drop table camels +drop table camelsGenerated +drop table camelsProcessed \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/h2.sql b/integration-tests/jdbc/src/main/resources/sql/h2.sql new file mode 100644 index 0000000000..e54ab07edd --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/h2.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +create table camels (id int auto_increment primary key, species varchar(50)) +create table camelsGenerated (id int auto_increment primary key, species varchar(50)) +create table camelsProcessed (id int auto_increment primary key , species varchar(50)) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/inserts.sql b/integration-tests/jdbc/src/main/resources/sql/inserts.sql new file mode 100644 index 0000000000..fce3a151ca --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/inserts.sql @@ -0,0 +1,22 @@ +-- +-- 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. +-- + +insert into camelsGenerated (species) values ('Camelus status') +insert into camelsGenerated (species) values ('Camelus linus') +insert into camels (species) values ('Camelus dromedarius') +insert into camels (species) values ('Camelus bactrianus') +insert into camels (species) values ('Camelus ferus') \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/mariadb.sql b/integration-tests/jdbc/src/main/resources/sql/mariadb.sql new file mode 100644 index 0000000000..e54ab07edd --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/mariadb.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +create table camels (id int auto_increment primary key, species varchar(50)) +create table camelsGenerated (id int auto_increment primary key, species varchar(50)) +create table camelsProcessed (id int auto_increment primary key , species varchar(50)) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/mssql.sql b/integration-tests/jdbc/src/main/resources/sql/mssql.sql new file mode 100644 index 0000000000..c603f48434 --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/mssql.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +create table camels (id int IDENTITY(1,1) PRIMARY KEY, species varchar(255)) +create table camelsGenerated (id int IDENTITY(1,1) PRIMARY KEY, species varchar(255)) +create table camelsProcessed (id int IDENTITY(1,1) PRIMARY KEY, species varchar(255)) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/mysql.sql b/integration-tests/jdbc/src/main/resources/sql/mysql.sql new file mode 100644 index 0000000000..e54ab07edd --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/mysql.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +create table camels (id int auto_increment primary key, species varchar(50)) +create table camelsGenerated (id int auto_increment primary key, species varchar(50)) +create table camelsProcessed (id int auto_increment primary key , species varchar(50)) \ No newline at end of file diff --git a/integration-tests/jdbc/src/main/resources/sql/oracle.sql b/integration-tests/jdbc/src/main/resources/sql/oracle.sql new file mode 100644 index 0000000000..a127ab480b --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/oracle.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +CREATE TABLE camels(id NUMBER GENERATED by default on null as IDENTITY, species VARCHAR2(50) NOT NULL, PRIMARY KEY(id)) +CREATE TABLE camelsGenerated(id NUMBER GENERATED by default on null as IDENTITY, species VARCHAR2(50) NOT NULL, PRIMARY KEY(id)) +CREATE TABLE camelsProcessed(id NUMBER GENERATED by default on null as IDENTITY, species VARCHAR2(50) NOT NULL, PRIMARY KEY(id)) diff --git a/integration-tests/jdbc/src/main/resources/sql/postgresql.sql b/integration-tests/jdbc/src/main/resources/sql/postgresql.sql new file mode 100644 index 0000000000..b31dc12ef6 --- /dev/null +++ b/integration-tests/jdbc/src/main/resources/sql/postgresql.sql @@ -0,0 +1,20 @@ +-- +-- 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. +-- + +CREATE TABLE camels (id serial PRIMARY KEY, species VARCHAR ( 50 ) NOT NULL) +CREATE TABLE camelsGenerated (id serial PRIMARY KEY, species VARCHAR ( 50 ) NOT NULL) +CREATE TABLE camelsProcessed (id serial PRIMARY KEY, species VARCHAR ( 50 ) NOT NULL) \ No newline at end of file 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 9fe7dad4af..9c8dce2d81 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 @@ -18,28 +18,29 @@ package org.apache.camel.quarkus.component.jdbc; import java.util.List; -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.http.ContentType; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; -import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; @QuarkusTest -@QuarkusTestResource(H2DatabaseTestResource.class) +@DisabledIfSystemProperty(named = "cq.jdbcKind", matches = "derby") +//https://github.com/quarkusio/quarkus/issues/23083 public class CamelJdbcTest { - @Test void testGetSpeciesById() { - RestAssured.when().get("/test/species/1").then().body(is("[{SPECIES=Camelus dromedarius}]")); - RestAssured.when().get("/test/species/2").then().body(is("[{SPECIES=Camelus bactrianus}]")); - RestAssured.when().get("/test/species/3").then().body(is("[{SPECIES=Camelus ferus}]")); + RestAssured.when().get("/test/species/1").then().body(equalToIgnoringCase("[{SPECIES=Camelus dromedarius}]")); + RestAssured.when().get("/test/species/2").then().body(equalToIgnoringCase("[{SPECIES=Camelus bactrianus}]")); + RestAssured.when().get("/test/species/3").then().body(equalToIgnoringCase("[{SPECIES=Camelus ferus}]")); } @Test @@ -49,7 +50,7 @@ public class CamelJdbcTest { @Test void testGetSpeciesByIdWithDefinedType() { - RestAssured.when().get("/test/species/1/type").then().body(is("Camelus dromedarius 1")); + RestAssured.when().get("/test/species/1/type").then().body(equalToIgnoringCase("Camelus dromedarius 1")); } @Test @@ -57,22 +58,25 @@ public class CamelJdbcTest { RestAssured.given() .contentType(ContentType.TEXT).body("select id from camels order by id desc") .post("/test/execute") - .then().body(is("[{ID=3}, {ID=2}, {ID=1}]")); + .then().body(equalToIgnoringCase("[{ID=3}, {ID=2}, {ID=1}]")); } @Test void testCamelRetrieveGeneratedKeysHeader() { + String idKey = RestAssured.when() + .get("/test/get-id-key") + .then() + .extract() + .body().asString(); + List generatedIDs = RestAssured.given() .get("test/generated-keys/rows") .then().extract().body() - .jsonPath().getList("ID"); + .jsonPath().getList(idKey); - String selectResult = RestAssured.given() - .contentType(ContentType.TEXT).body("select id from camelsGenerated") - .post("/test/execute") - .then().extract().body().asString(); + assertFalse(generatedIDs.isEmpty()); + assertNotNull(generatedIDs.get(0)); - generatedIDs.forEach(generatedID -> assertTrue(selectResult.contains(generatedID.toString()))); } @Test @@ -80,19 +84,19 @@ public class CamelJdbcTest { RestAssured.given() .get("test/headers/insert") .then() - .body(containsString("CamelGeneratedKeysRowCount=2")) + .body(containsStringIgnoringCase("CamelGeneratedKeysRowCount=1")) .and() - .body(containsString("CamelJdbcUpdateCount=2")) + .body(containsStringIgnoringCase("CamelJdbcUpdateCount=1")) .and() - .body(containsString("CamelRetrieveGeneratedKeys=true")) + .body(containsStringIgnoringCase("CamelRetrieveGeneratedKeys=true")) .and() - .body(not(containsString("CamelJdbcRowCount"))) + .body(not(containsStringIgnoringCase("CamelJdbcRowCount"))) .and() - .body(not(containsString("CamelJdbcColumnNames"))) + .body(not(containsStringIgnoringCase("CamelJdbcColumnNames"))) .and() - .body(not(containsString("CamelJdbcParameters"))) + .body(not(containsStringIgnoringCase("CamelJdbcParameters"))) .and() - .body(not(containsString("CamelGeneratedColumns"))); + .body(not(containsStringIgnoringCase("CamelGeneratedColumns"))); } @Test @@ -100,19 +104,19 @@ public class CamelJdbcTest { RestAssured.given() .get("test/headers/select") .then() - .body(not(containsString("CamelGeneratedKeysRowCount"))) + .body(not(containsStringIgnoringCase("CamelGeneratedKeysRowCount"))) .and() - .body(not(containsString("CamelJdbcUpdateCount"))) + .body(not(containsStringIgnoringCase("CamelJdbcUpdateCount"))) .and() - .body(not(containsString("CamelRetrieveGeneratedKeys"))) + .body(not(containsStringIgnoringCase("CamelRetrieveGeneratedKeys"))) .and() - .body(not(containsString("CamelJdbcParameters"))) + .body(not(containsStringIgnoringCase("CamelJdbcParameters"))) .and() - .body(not(containsString("CamelGeneratedColumns"))) + .body(not(containsStringIgnoringCase("CamelGeneratedColumns"))) .and() - .body(containsString("CamelJdbcRowCount")) + .body(containsStringIgnoringCase("CamelJdbcRowCount")) .and() - .body(containsString("CamelJdbcColumnNames=[ID, SPECIES]")); + .body(containsStringIgnoringCase("CamelJdbcColumnNames=[ID, SPECIES]")); } @Test @@ -120,9 +124,9 @@ public class CamelJdbcTest { RestAssured.given() .get("test/named-parameters/headers-as-parameters") .then() - .body(containsString("{ID=1, SPECIES=Camelus dromedarius}")) + .body(containsStringIgnoringCase("{ID=1, SPECIES=Camelus dromedarius}")) .and() - .body(containsString("{ID=2, SPECIES=Camelus bactrianus}")); + .body(containsStringIgnoringCase("{ID=2, SPECIES=Camelus bactrianus}")); } @Test @@ -130,7 +134,7 @@ public class CamelJdbcTest { RestAssured.given() .get("test/named-parameters/headers-as-parameters-map") .then() - .body(containsString("{ID=2, SPECIES=Camelus bactrianus}")); + .body(containsStringIgnoringCase("{ID=2, SPECIES=Camelus bactrianus}")); } @Test @@ -163,5 +167,4 @@ public class CamelJdbcTest { .then() .body(equalTo(camelsDbResult)); } - }