This is an automated email from the ASF dual-hosted git repository.
ppalaga 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 4ec0c8a Sql - enable test with different databases #3053
4ec0c8a is described below
commit 4ec0c8a33df09c31748aeb5866a000af5e587dda
Author: JiriOndrusek <[email protected]>
AuthorDate: Fri Sep 3 09:27:52 2021 +0200
Sql - enable test with different databases #3053
---
integration-tests/sql/README.adoc | 45 +++++++++++++
integration-tests/sql/pom.xml | 8 ++-
.../component/sql/it/SqlConfigSourceFactory.java | 54 ++++++++++++++++
.../quarkus/component/sql/it/SqlDbInitializer.java | 25 ++++++--
.../camel/quarkus/component/sql/it/SqlHelper.java | 42 ++++++++++++
.../quarkus/component/sql/it/SqlResource.java | 35 ++++------
.../camel/quarkus/component/sql/it/SqlRoutes.java | 40 ++++++++----
.../io.smallrye.config.ConfigSourceFactory | 1 +
.../sql/src/main/resources/application.properties | 6 +-
.../main/resources/sql/{ => common}/get-camels.sql | 0
.../selectProjectsAsBoolean.sql} | 2 +-
.../selectProjectsAsNumber.sql} | 4 +-
.../sql/src/main/resources/sql/db2/initDb.sql | 38 +++++++++++
.../sql/src/main/resources/sql/derby/initDb.sql | 37 +++++++++++
.../sql/src/main/resources/sql/{ => h2}/initDb.sql | 20 +++---
.../main/resources/sql/{ => mariadb}/initDb.sql | 18 ++++--
.../src/main/resources/sql/{ => mssql}/initDb.sql | 25 +++++---
.../src/main/resources/sql/{ => mysql}/initDb.sql | 19 ++++--
.../sql/src/main/resources/sql/oracle/initDb.sql | 37 +++++++++++
.../main/resources/sql/{ => postgresql}/initDb.sql | 17 +++--
.../camel/quarkus/component/sql/it/SqlTest.java | 74 +++++++++++++---------
21 files changed, 432 insertions(+), 115 deletions(-)
diff --git a/integration-tests/sql/README.adoc
b/integration-tests/sql/README.adoc
new file mode 100644
index 0000000..01c02a9
--- /dev/null
+++ b/integration-tests/sql/README.adoc
@@ -0,0 +1,45 @@
+== SQL 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.sqlJdbcKind`. Example of usage:
+
+`mvn clean test -f integration-tests/sql/ -cq.sqlJdbcKind=postgresql`
+
+Following databases could be started in the dev-service mode:
+
+- Postgresql (container) - add `-Dcq.sqlJdbcKind=postgresql`
+- MySQL (container) - add `-Dcq.sqlJdbcKind=mysql`
+- MariaDB (container) - add `-Dcq.sqlJdbcKind=mariadb`
+- H2 (in-process) used by default
+- Apache Derby (in-process) - add `-Dcq.sqlJdbcKind=derby`
+- DB2 (container) (requires license acceptance) - add `-Dcq.sqlJdbcKind=db2`
+- MSSQL (container) (requires license acceptance) - add
`-Dcq.sqlJdbcKind=mssql`
+
+For more information about dev-service mode, see
https://quarkus.io/guides/datasource#dev-services[documentation].
+
+=== External databases
+
+To execute the tests against external database, configure database type by
providing a build property in the same way as with dev-service mode (see
previous chapter).
+Provide the rest of database's connection information by setting environment
variables
+
+```
+export SQL_JDBC_URL=#jdbc_url
+export SQL_JDBC_USERNAME=#username
+export SQL_JDBC_PASSWORD=#password
+```
+
+or for windows:
+
+```
+$Env:SQL_JDBC_URL = "#jdbc_url"
+$Env:SQL_JDBC_USERNAME="#username"
+$Env:SQL_JDBC_PASSWORD="#password"
+```
+
+Oracle database could be used as external db. In that case use parameter
`-DSQL_JDBC_DB_KIND=oracle`.
\ No newline at end of file
diff --git a/integration-tests/sql/pom.xml b/integration-tests/sql/pom.xml
index 002f84d..e0b9002 100644
--- a/integration-tests/sql/pom.xml
+++ b/integration-tests/sql/pom.xml
@@ -27,7 +27,10 @@
<artifactId>camel-quarkus-integration-test-sql</artifactId>
<name>Camel Quarkus :: Integration Tests :: SQL</name>
- <description>Integration tests for Camel Quarkus SQL
extension</description>
+
+ <properties>
+ <cq.sqlJdbcKind>h2</cq.sqlJdbcKind>
+ </properties>
<dependencies>
<dependency>
@@ -44,7 +47,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
- <artifactId>quarkus-jdbc-h2</artifactId>
+ <artifactId>quarkus-jdbc-${cq.sqlJdbcKind}</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
@@ -144,5 +147,4 @@
</build>
</profile>
</profiles>
-
</project>
diff --git
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlConfigSourceFactory.java
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlConfigSourceFactory.java
new file mode 100644
index 0000000..24316c2
--- /dev/null
+++
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlConfigSourceFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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.sql.it;
+
+import java.util.Collections;
+import java.util.HashMap;
+
+import io.smallrye.config.ConfigSourceContext;
+import io.smallrye.config.ConfigSourceFactory;
+import io.smallrye.config.common.MapBackedConfigSource;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+
+public class SqlConfigSourceFactory implements ConfigSourceFactory {
+
+ private final static MapBackedConfigSource source;
+
+ static {
+ String jdbcUrl = System.getenv("SQL_JDBC_URL");
+
+ //external db
+ if (jdbcUrl != null) {
+ source = new MapBackedConfigSource("env_database", new HashMap() {
+ {
+ put("quarkus.datasource.jdbc.url", jdbcUrl);
+ put("quarkus.datasource.username",
System.getenv("SQL_JDBC_USERNAME"));
+ put("quarkus.datasource.password",
System.getenv("SQL_JDBC_PASSWORD"));
+ }
+ }) {
+ };
+ } else {
+ source = new MapBackedConfigSource("env_database", new HashMap()) {
+ };
+ }
+ }
+
+ @Override
+ public Iterable<ConfigSource> getConfigSources(ConfigSourceContext
configSourceContext) {
+ return Collections.singletonList(source);
+ }
+}
diff --git
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java
index f368c51..796aeb0 100644
---
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java
+++
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlDbInitializer.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.quarkus.component.sql.it;
-import java.io.*;
+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;
@@ -25,17 +28,27 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import io.agroal.api.AgroalDataSource;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@ApplicationScoped
public class SqlDbInitializer {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(SqlDbInitializer.class);
+
@Inject
AgroalDataSource dataSource;
+ @ConfigProperty(name = "quarkus.datasource.db-kind")
+ String dbKind;
+
public void initDb() throws SQLException, IOException {
+
try (Connection conn = dataSource.getConnection()) {
try (Statement statement = conn.createStatement()) {
- try (InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("sql/initDb.sql");
+ try (InputStream is =
Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream("sql/" + dbKind + "/initDb.sql");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr)) {
@@ -43,12 +56,16 @@ public class SqlDbInitializer {
try {
statement.execute(s);
} catch (SQLException e) {
- throw new RuntimeException(e);
+ if (!s.toUpperCase().startsWith("DROP TABLE")) {
+ throw new RuntimeException(e);
+ } else {
+ LOGGER.debug(String.format("Command '%s'
failed.", s)); //use debug logging
+ }
}
});
}
}
}
- }
+ }
}
diff --git
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlHelper.java
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlHelper.java
new file mode 100644
index 0000000..80b7510
--- /dev/null
+++
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlHelper.java
@@ -0,0 +1,42 @@
+/*
+ * 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.sql.it;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class SqlHelper {
+
+ private static Set<String> BOOLEAN_AS_NUMBER = new
HashSet<>(Arrays.asList("db2", "mssql", "oracle"));
+
+ static String convertBooleanToSqlDialect(String dbKind, boolean value) {
+ return convertBooleanToSqlResult(dbKind, value).toString();
+ }
+
+ static Object convertBooleanToSqlResult(String dbKind, boolean value) {
+
+ if (value) {
+ return BOOLEAN_AS_NUMBER.contains(dbKind) ? 1 : true;
+ }
+ return BOOLEAN_AS_NUMBER.contains(dbKind) ? 0 : false;
+ }
+
+ static String getSelectProjectsScriptName(String dbKind) {
+ return BOOLEAN_AS_NUMBER.contains(dbKind) ?
"selectProjectsAsNumber.sql" : "selectProjectsAsBoolean.sql";
+ }
+}
diff --git
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
index 89c7ff9..c20cf1b 100644
---
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
+++
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
@@ -37,13 +37,18 @@ import io.agroal.api.AgroalDataSource;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.sql.SqlConstants;
import org.apache.camel.quarkus.component.sql.it.model.Camel;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.springframework.util.LinkedCaseInsensitiveMap;
@Path("/sql")
@ApplicationScoped
public class SqlResource {
+ @ConfigProperty(name = "quarkus.datasource.db-kind")
+ String dbKind;
+
@Inject
AgroalDataSource dataSource;
@@ -64,7 +69,7 @@ public class SqlResource {
Map<String, Object> params = new HashMap<>();
params.put("species", species);
- return
producerTemplate.requestBodyAndHeaders("sql:classpath:sql/get-camels.sql",
+ return
producerTemplate.requestBodyAndHeaders("sql:classpath:sql/common/get-camels.sql",
null, params,
String.class);
}
@@ -110,6 +115,7 @@ public class SqlResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
+ @SuppressWarnings("unchecked")
public Response insert(@QueryParam("table") String table, Map<String,
Object> values) throws Exception {
LinkedHashMap linkedHashMap = new LinkedHashMap(values);
@@ -168,33 +174,18 @@ public class SqlResource {
return list;
}
- @GET
- @Path("/route/{routeId}/{operation}")
- @Produces(MediaType.TEXT_PLAIN)
- public String route(@PathParam("routeId") String routeId,
@PathParam("operation") String operation)
- throws Exception {
- //is start enough
- switch (operation) {
- case "stop":
- camelContext.getRouteController().stopRoute(routeId);
- break;
- case "start":
- camelContext.getRouteController().startRoute(routeId);
- break;
- case "status":
- return
camelContext.getRouteController().getRouteStatus(routeId).name();
-
- }
-
- return null;
- }
-
@Path("/toDirect/{directId}")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Object toDirect(@PathParam("directId") String directId,
@QueryParam("body") String body, Map<String, Object> headers)
throws Exception {
+ String sql = (String) headers.get(SqlConstants.SQL_QUERY);
+ if (sql != null) {
+ headers.put(SqlConstants.SQL_QUERY,
+ sql.replaceAll("BOOLEAN_FALSE",
SqlHelper.convertBooleanToSqlDialect(dbKind, false)));
+ }
+
try {
return producerTemplate.requestBodyAndHeaders("direct:" +
directId, body, headers, Object.class);
} catch (CamelExecutionException e) {
diff --git
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlRoutes.java
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlRoutes.java
index 23a3af0..565277f 100644
---
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlRoutes.java
+++
b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlRoutes.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.sql.it;
import java.io.*;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.HashMap;
@@ -37,11 +38,15 @@ import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.processor.aggregate.jdbc.JdbcAggregationRepository;
import org.apache.camel.processor.idempotent.jdbc.JdbcMessageIdRepository;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.springframework.transaction.jta.JtaTransactionManager;
@ApplicationScoped
public class SqlRoutes extends RouteBuilder {
+ @ConfigProperty(name = "quarkus.datasource.db-kind")
+ String dbKind;
+
@Inject
@Named("results")
Map<String, List> results;
@@ -63,18 +68,25 @@ public class SqlRoutes extends RouteBuilder {
//db has to be initialized before routes are started
sqlDbInitializer.initDb();
- from("sql:select * from projects where processed = false order by
id?initialDelay=0&delay=50&consumer.onConsume=update projects set processed =
true where id = :#id")
- .id("consumerRoute").autoStartup(false)
- .process(e ->
results.get("consumerRoute").add(e.getMessage().getBody(Map.class)));
-
-
from("sql:classpath:sql/selectProjects.sql?initialDelay=0&delay=50&consumer.onConsume=update
projects set processed = true")
- .id("consumerClasspathRoute").autoStartup(false)
- .process(e ->
results.get("consumerClasspathRoute").add(e.getMessage().getBody(Map.class)));
-
- Path tmpFile = createTmpFileFrom("sql/selectProjects.sql");
- from("sql:file:" + tmpFile
- + "?initialDelay=0&delay=50&consumer.onConsume=update projects
set processed = true")
- .id("consumerFileRoute").autoStartup(false)
+ String representationOfTrue =
SqlHelper.convertBooleanToSqlDialect(dbKind, true);
+ String representationOfFalse =
SqlHelper.convertBooleanToSqlDialect(dbKind, false);
+ String selectProjectsScriptName =
SqlHelper.getSelectProjectsScriptName(dbKind);
+
+ from(String.format("sql:select * from projectsViaSql where processed =
%s"
+ + " order by
id?initialDelay=0&delay=50&consumer.onConsume=update projectsViaSql set
processed = %s"
+ + " where id = :#id", representationOfFalse,
representationOfTrue))
+ .process(e ->
results.get("consumerRoute").add(e.getMessage().getBody(Map.class)));
+
+
from(String.format("sql:classpath:sql/common/%s?initialDelay=0&delay=50&" +
+ "consumer.onConsume=update projectsViaClasspath set processed
= %s", selectProjectsScriptName,
+ representationOfTrue))
+ .process(e ->
results.get("consumerClasspathRoute").add(e.getMessage().getBody(Map.class)));
+
+ //File `sql/common/selectProjectsAs*.sql` is copied and modified to
create tmp file for another test case
+ // (to have different file for the sql request from file and from
classpath)
+ Path tmpFile = createTmpFileFrom("sql/common/" +
selectProjectsScriptName);
+ from(String.format("sql:file:%s?initialDelay=0&delay=50&" +
+ "consumer.onConsume=update projectsViaFile set processed =
%s", tmpFile, representationOfTrue))
.process(e ->
results.get("consumerFileRoute").add(e.getMessage().getBody(Map.class)));
from("direct:transacted")
@@ -114,7 +126,9 @@ public class SqlRoutes extends RouteBuilder {
while ((c = is.read()) >= 0) {
baos.write(c);
}
- fos.write(baos.toByteArray());
+ String content = new String(baos.toByteArray(),
StandardCharsets.UTF_8);
+ content = content.replaceAll("projectsViaClasspath",
"projectsViaFile");
+ fos.write(content.getBytes(StandardCharsets.UTF_8));
}
return tmpFile.toPath();
}
diff --git
a/integration-tests/sql/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
b/integration-tests/sql/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
new file mode 100644
index 0000000..28d2ad6
--- /dev/null
+++
b/integration-tests/sql/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
@@ -0,0 +1 @@
+org.apache.camel.quarkus.component.sql.it.SqlConfigSourceFactory
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/application.properties
b/integration-tests/sql/src/main/resources/application.properties
index 8dc76ac..1003220 100644
--- a/integration-tests/sql/src/main/resources/application.properties
+++ b/integration-tests/sql/src/main/resources/application.properties
@@ -15,7 +15,9 @@
## limitations under the License.
## ---------------------------------------------------------------------------
+quarkus.datasource.db-kind=${cq.sqlJdbcKind:h2}
+
+#
# Camel Quarkus SQL
#
-quarkus.native.resources.includes=sql/*.sql
-
+quarkus.native.resources.includes=sql/${SQL_JDBC_DB_KIND:h2}/*.sql,sql/common/*.sql
diff --git a/integration-tests/sql/src/main/resources/sql/get-camels.sql
b/integration-tests/sql/src/main/resources/sql/common/get-camels.sql
similarity index 100%
rename from integration-tests/sql/src/main/resources/sql/get-camels.sql
rename to integration-tests/sql/src/main/resources/sql/common/get-camels.sql
diff --git a/integration-tests/sql/src/main/resources/sql/selectProjects.sql
b/integration-tests/sql/src/main/resources/sql/common/selectProjectsAsBoolean.sql
similarity index 95%
copy from integration-tests/sql/src/main/resources/sql/selectProjects.sql
copy to
integration-tests/sql/src/main/resources/sql/common/selectProjectsAsBoolean.sql
index 5f3ee5b..a782832 100644
--- a/integration-tests/sql/src/main/resources/sql/selectProjects.sql
+++
b/integration-tests/sql/src/main/resources/sql/common/selectProjectsAsBoolean.sql
@@ -16,6 +16,6 @@
--
select *
-from projects
+from projectsViaClasspath
where processed = false
order by id
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/selectProjects.sql
b/integration-tests/sql/src/main/resources/sql/common/selectProjectsAsNumber.sql
similarity index 93%
rename from integration-tests/sql/src/main/resources/sql/selectProjects.sql
rename to
integration-tests/sql/src/main/resources/sql/common/selectProjectsAsNumber.sql
index 5f3ee5b..a0ccd71 100644
--- a/integration-tests/sql/src/main/resources/sql/selectProjects.sql
+++
b/integration-tests/sql/src/main/resources/sql/common/selectProjectsAsNumber.sql
@@ -16,6 +16,6 @@
--
select *
-from projects
-where processed = false
+from projectsViaClasspath
+where processed = 0
order by id
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
b/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
new file mode 100644
index 0000000..895b56a
--- /dev/null
+++ b/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
@@ -0,0 +1,38 @@
+--
+-- 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 CAMEL
+CREATE TABLE camel (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, species
VARCHAR(50) NOT NULL,PRIMARY KEY (id))
+
+-- for consumer
+DROP TABLE PROJECTSVIACLASSPATH
+CREATE TABLE projectsViaClasspath (id INT GENERATED BY DEFAULT AS IDENTITY NOT
NULL, project VARCHAR(25), license VARCHAR(25), processed SMALLINT,PRIMARY KEY
(id))
+DROP TABLE PROJECTSVIASQL
+CREATE TABLE projectsViaSql (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
project VARCHAR(25), license VARCHAR(25), processed SMALLINT,PRIMARY KEY (id))
+DROP TABLE PROJECTSVIAFILE
+CREATE TABLE projectsViaFile (id INT GENERATED BY DEFAULT AS IDENTITY NOT
NULL, project VARCHAR(25), license VARCHAR(25), processed SMALLINT,PRIMARY KEY
(id))
+
+-- idempotent repo
+DROP TABLE CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED (processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP)
+
+-- aggregation repo
+DROP TABLE AGGREGATION
+CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB, version
BIGINT)
+DROP TABLE AGGREGATION_COMPLETED
+CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB,
version BIGINT)
+
diff --git a/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
b/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
new file mode 100644
index 0000000..9782095
--- /dev/null
+++ b/integration-tests/sql/src/main/resources/sql/derby/initDb.sql
@@ -0,0 +1,37 @@
+--
+-- 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 camel
+CREATE TABLE camel (id INT NOT NULL GENERATED ALWAYS AS IDENTITY,species
VARCHAR(50) NOT NULL)
+
+-- for consumer
+DROP TABLE projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id INT NOT NULL, project VARCHAR(25),
license VARCHAR(5), processed BOOLEAN, PRIMARY KEY (id))
+DROP TABLE projectsViaSql
+CREATE TABLE projectsViaSql (id INT NOT NULL, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN, PRIMARY KEY (id))
+DROP TABLE projectsViaFile
+CREATE TABLE projectsViaFile (id INT NOT NULL, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN, PRIMARY KEY (id))
+
+-- idempotent repo
+DROP TABLE CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED ( processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP )
+
+-- aggregation repo
+DROP TABLE aggregation
+CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id))
+DROP TABLE aggregation_completed
+CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id))
diff --git a/integration-tests/sql/src/main/resources/sql/initDb.sql
b/integration-tests/sql/src/main/resources/sql/h2/initDb.sql
similarity index 64%
copy from integration-tests/sql/src/main/resources/sql/initDb.sql
copy to integration-tests/sql/src/main/resources/sql/h2/initDb.sql
index f6896f7..40e6f74 100644
--- a/integration-tests/sql/src/main/resources/sql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/h2/initDb.sql
@@ -15,19 +15,23 @@
-- limitations under the License.
--
-DROP TABLE IF EXISTS camel
-CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255))
-CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers"
+DROP TABLE IF EXISTS camel;
+CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255));
+CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers";
-- for consumer
-DROP TABLE IF EXISTS projects
-create table projects (id integer primary key, project varchar(25), license
varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaClasspath;
+create table projectsViaClasspath (id integer primary key, project
varchar(25), license varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaSql;
+create table projectsViaSql (id integer primary key, project varchar(25),
license varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaFile;
+create table projectsViaFile(id integer primary key, project varchar(25),
license varchar(5), processed BOOLEAN);
-- idempotent repo
-DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED
+DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED;
-- aggregation repo
-DROP TABLE IF EXISTS aggregation
+DROP TABLE IF EXISTS aggregation;
CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange blob NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
-DROP TABLE IF EXISTS aggregation_completed
+DROP TABLE IF EXISTS aggregation_completed;
CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange blob
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/initDb.sql
b/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
similarity index 50%
copy from integration-tests/sql/src/main/resources/sql/initDb.sql
copy to integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
index f6896f7..8b5788a 100644
--- a/integration-tests/sql/src/main/resources/sql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
@@ -15,19 +15,23 @@
-- limitations under the License.
--
-DROP TABLE IF EXISTS camel
-CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255))
-CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers"
+DROP TABLE IF EXISTS camel;
+CREATE TABLE camel (id INT AUTO_INCREMENT PRIMARY KEY,species VARCHAR(50) NOT
NULL);
-- for consumer
-DROP TABLE IF EXISTS projects
-create table projects (id integer primary key, project varchar(25), license
varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id INT PRIMARY KEY, project VARCHAR(25),
license VARCHAR(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaFile
+CREATE TABLE projectsViaFile (id INT PRIMARY KEY, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaSql
+CREATE TABLE projectsViaSql (id INT PRIMARY KEY, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN);
-- idempotent repo
DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED ( processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP )
-- aggregation repo
DROP TABLE IF EXISTS aggregation
-CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange blob NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
+CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
DROP TABLE IF EXISTS aggregation_completed
-CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange blob
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
\ No newline at end of file
+CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
diff --git a/integration-tests/sql/src/main/resources/sql/initDb.sql
b/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
similarity index 50%
copy from integration-tests/sql/src/main/resources/sql/initDb.sql
copy to integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
index f6896f7..a61b4b2 100644
--- a/integration-tests/sql/src/main/resources/sql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
@@ -15,19 +15,24 @@
-- limitations under the License.
--
-DROP TABLE IF EXISTS camel
-CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255))
-CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers"
+DROP TABLE camel
+CREATE TABLE camel (id int NOT NULL IDENTITY PRIMARY KEY,species varchar(50));
-- for consumer
-DROP TABLE IF EXISTS projects
-create table projects (id integer primary key, project varchar(25), license
varchar(5), processed BOOLEAN);
+DROP TABLE projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id int NOT NULL, project varchar(25),
license varchar(5), processed BIT);
+DROP TABLE projectsViaFile
+CREATE TABLE projectsViaFile (id int NOT NULL, project varchar(25), license
varchar(5), processed BIT);
+DROP TABLE projectsViaSql
+CREATE TABLE projectsViaSql (id int NOT NULL, project varchar(25), license
varchar(5), processed BIT);
-- idempotent repo
-DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED
+DROP TABLE CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED (processorName varchar(255), messageId
varchar(100), createdAt datetime)
-- aggregation repo
-DROP TABLE IF EXISTS aggregation
-CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange blob NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
-DROP TABLE IF EXISTS aggregation_completed
-CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange blob
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
\ No newline at end of file
+DROP TABLE aggregation
+CREATE TABLE aggregation (id varchar(255), exchange Image, version bigint);
+
+DROP TABLE aggregation_completed
+CREATE TABLE aggregation_completed (id varchar(255), exchange Image, version
bigint);
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/initDb.sql
b/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
similarity index 50%
copy from integration-tests/sql/src/main/resources/sql/initDb.sql
copy to integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
index f6896f7..da8ff4c 100644
--- a/integration-tests/sql/src/main/resources/sql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
@@ -15,19 +15,24 @@
-- limitations under the License.
--
-DROP TABLE IF EXISTS camel
-CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255))
-CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers"
+
+DROP TABLE IF EXISTS camel;
+CREATE TABLE camel (id INT AUTO_INCREMENT PRIMARY KEY,species VARCHAR(50) NOT
NULL);
-- for consumer
-DROP TABLE IF EXISTS projects
-create table projects (id integer primary key, project varchar(25), license
varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id INT PRIMARY KEY, project VARCHAR(25),
license VARCHAR(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaSql
+CREATE TABLE projectsViaSql (id INT PRIMARY KEY, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaFile
+CREATE TABLE projectsViaFile (id INT PRIMARY KEY, project VARCHAR(25), license
VARCHAR(5), processed BOOLEAN);
-- idempotent repo
DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED ( processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP )
-- aggregation repo
DROP TABLE IF EXISTS aggregation
-CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange blob NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
+CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
DROP TABLE IF EXISTS aggregation_completed
-CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange blob
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
\ No newline at end of file
+CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
diff --git a/integration-tests/sql/src/main/resources/sql/oracle/initDb.sql
b/integration-tests/sql/src/main/resources/sql/oracle/initDb.sql
new file mode 100644
index 0000000..234247d
--- /dev/null
+++ b/integration-tests/sql/src/main/resources/sql/oracle/initDb.sql
@@ -0,0 +1,37 @@
+--
+-- 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 camel
+CREATE TABLE camel(id NUMBER GENERATED BY DEFAULT AS IDENTITY, species
VARCHAR2(50) NOT NULL, PRIMARY KEY(id))
+
+-- for consumer
+DROP TABLE projectsViaSql
+CREATE TABLE projectsViaSql (id NUMBER, project VARCHAR2(50) NOT NULL, license
VARCHAR2(25) NOT NULL, processed NUMBER(1), PRIMARY KEY(id))
+DROP TABLE projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id NUMBER, project VARCHAR2(50) NOT NULL,
license VARCHAR2(25) NOT NULL, processed NUMBER(1), PRIMARY KEY(id))
+DROP TABLE projectsViaFile
+CREATE TABLE projectsViaFile (id NUMBER, project VARCHAR2(50) NOT NULL,
license VARCHAR2(25) NOT NULL, processed NUMBER(1), PRIMARY KEY(id))
+
+-- idempotent repo
+DROP TABLE CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED ( processorName VARCHAR2(255), messageId
VARCHAR2(100), createdAt TIMESTAMP )
+
+-- aggregation repo
+DROP TABLE aggregation
+CREATE TABLE aggregation (id VARCHAR2(255) NOT NULL, exchange BLOB NOT NULL,
version INT, PRIMARY KEY (id))
+DROP TABLE aggregation_completed CASCADE CONSTRAINTS
+CREATE TABLE aggregation_completed (id VARCHAR2(255) NOT NULL, exchange BLOB
NOT NULL, version INT, PRIMARY KEY (id))
diff --git a/integration-tests/sql/src/main/resources/sql/initDb.sql
b/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
similarity index 54%
rename from integration-tests/sql/src/main/resources/sql/initDb.sql
rename to integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
index f6896f7..f47eaf1 100644
--- a/integration-tests/sql/src/main/resources/sql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
@@ -16,18 +16,23 @@
--
DROP TABLE IF EXISTS camel
-CREATE TABLE camel (id int AUTO_INCREMENT, species VARCHAR(255))
-CREATE ALIAS ADD_NUMS FOR
"org.apache.camel.quarkus.component.sql.it.storedproc.NumberAddStoredProcedure.addNumbers"
+CREATE TABLE camel (id serial PRIMARY KEY, species VARCHAR ( 50 ) NOT NULL)
-- for consumer
-DROP TABLE IF EXISTS projects
-create table projects (id integer primary key, project varchar(25), license
varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaSql
+CREATE TABLE projectsViaSql (id integer primary key, project varchar(25),
license varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaClasspath
+CREATE TABLE projectsViaClasspath (id integer primary key, project
varchar(25), license varchar(5), processed BOOLEAN);
+DROP TABLE IF EXISTS projectsViaFile
+CREATE TABLE projectsViaFile (id integer primary key, project varchar(25),
license varchar(5), processed BOOLEAN);
-- idempotent repo
DROP TABLE IF EXISTS CAMEL_MESSAGEPROCESSED
+CREATE TABLE CAMEL_MESSAGEPROCESSED ( processorName VARCHAR(255), messageId
VARCHAR(100), createdAt TIMESTAMP )
-- aggregation repo
DROP TABLE IF EXISTS aggregation
-CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange blob NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
+CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange BYTEA NOT NULL,
version BIGINT NOT NULL, constraint aggregation_pk PRIMARY KEY (id));
DROP TABLE IF EXISTS aggregation_completed
-CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange blob
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
\ No newline at end of file
+CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange BYTEA
NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY
KEY (id));
+
diff --git
a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
b/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
index 49f695c..9cd6393 100644
---
a/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
+++
b/integration-tests/sql/src/test/java/org/apache/camel/quarkus/component/sql/it/SqlTest.java
@@ -27,7 +27,11 @@ import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.apache.camel.component.sql.SqlConstants;
import org.apache.camel.util.CollectionHelper;
+import org.hamcrest.Matcher;
+import org.hamcrest.collection.IsMapContaining;
+import org.hamcrest.text.IsEqualIgnoringCase;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
@@ -51,7 +55,7 @@ class SqlTest {
RestAssured.get("/sql/get/Dromedarius")
.then()
.statusCode(200)
- .body(is("[{ID=1, SPECIES=Dromedarius}]"));
+ .body(containsStringIgnoringCase("[{ID=1,
SPECIES=Dromedarius}]"));
// Retrieve camel species as list
RestAssured.get("/sql/get/Dromedarius/list")
@@ -67,6 +71,7 @@ class SqlTest {
}
@Test
+ @DisabledIfSystemProperty(named = "cq.sqlJdbcKind", matches =
"[^h][^2].*", disabledReason =
"https://github.com/apache/camel-quarkus/issues/3080")
public void testSqlStoredComponent() {
// Invoke ADD_NUMS stored procedure
RestAssured.given()
@@ -80,82 +85,80 @@ class SqlTest {
@Test
public void testConsumer() throws InterruptedException {
- testConsumer(1, "consumerRoute");
+ testConsumer(1, "consumerRoute", "ViaSql");
}
@Test
public void testClasspathConsumer() throws InterruptedException {
- testConsumer(2, "consumerClasspathRoute");
+ testConsumer(2, "consumerClasspathRoute", "ViaClasspath");
}
@Test
public void testFileConsumer() throws InterruptedException {
- testConsumer(3, "consumerFileRoute");
+ testConsumer(3, "consumerFileRoute", "ViaFile");
}
- private void testConsumer(int id, String routeId) throws
InterruptedException {
- route(routeId, "start", "Started");
-
+ @SuppressWarnings("unchecked")
+ private void testConsumer(int id, String routeId, String via) throws
InterruptedException {
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",
+ "table", "projects" + via,
project)
.statusCode(201);
//wait for the record to be caught
- await().atMost(5, TimeUnit.SECONDS).until(() -> (Iterable<Object>)
RestAssured
+ await().atMost(30, TimeUnit.SECONDS).until(() -> (Iterable<Object>)
RestAssured
.get("/sql/get/results/" +
routeId).then().extract().as(List.class),
- both(iterableWithSize(1)).and(contains(project)));
+ hasItem(matchMapIgnoringCase(project)));
//update
postMapWithParam("/sql/update",
- "table", "projects",
+ "table", "projects" + via,
updatedProject)
.statusCode(201);
//wait for the record to be caught
- await().atMost(5, TimeUnit.SECONDS).until(() -> (Iterable<Object>)
RestAssured
+ await().atMost(30, TimeUnit.SECONDS).until(() -> (Iterable<Object>)
RestAssured
.get("/sql/get/results/" +
routeId).then().extract().as(List.class),
- both(iterableWithSize(1)).and(contains(updatedProject)));
-
- route(routeId, "stop", "Stopped");
+ hasItem(matchMapIgnoringCase(updatedProject)));
}
@Test
public void testTransacted() throws InterruptedException {
postMap("/sql/toDirect/transacted",
CollectionHelper.mapOf(SqlConstants.SQL_QUERY,
- "insert into projects values (5, 'Transacted', 'ASF', false)",
+ "insert into projectsViaSql values (5, 'Transacted', 'ASF',
BOOLEAN_FALSE)",
"rollback", false))
.statusCode(204);
postMap("/sql/toDirect/transacted",
CollectionHelper.mapOf(SqlConstants.SQL_QUERY,
- "select * from projects where project = 'Transacted'"))
+ "select * from projectsViaSql 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)",
+ "insert into projectsViaSql values (6, 'Transacted', 'ASF',
BOOLEAN_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'"))
+ CollectionHelper.mapOf(SqlConstants.SQL_QUERY, "select * from
projectsViaSql 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"))
+ postMap("/sql/toDirect/transacted",
CollectionHelper.mapOf(SqlConstants.SQL_QUERY, "select * from NOT_EXIST"))
.statusCode(200)
.body(startsWith("org.springframework.jdbc.BadSqlGrammarException"));
}
@Test
+ @SuppressWarnings("unchecked")
public void testIdempotentRepository() {
// add value with key 1
postMapWithParam("/sql/toDirect/idempotent",
@@ -188,6 +191,7 @@ class SqlTest {
}
@Test
+ @SuppressWarnings("unchecked")
public void testAggregationRepository() {
postMapWithParam("/sql/toDirect/aggregation", "body", "A",
CollectionHelper.mapOf("messageId", "123"))
.statusCode(200);
@@ -224,16 +228,26 @@ class SqlTest {
.then();
}
- private void route(String routeId, String operation, String
expectedOutput) {
- RestAssured.given()
- .get("/sql/route/" + routeId + "/" + operation)
- .then().statusCode(204);
-
- if (expectedOutput != null) {
- await().atMost(5, TimeUnit.SECONDS).until(() -> RestAssured
- .get("/sql/route/" + routeId + "/status")
- .then()
- .extract().asString(), equalTo(expectedOutput));
+ @SuppressWarnings("unchecked")
+ public static org.hamcrest.Matcher<java.util.Map<String, Object>>
matchMapIgnoringCase(Map<String, Object> map) {
+ Matcher m = null;
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ Matcher fieldCondition;
+ if (entry.getValue() instanceof Boolean) {
+ //it is boolean type and different dbs return different
representations of boolean
+ fieldCondition = either(new IsMapContaining(new
IsEqualIgnoringCase(entry.getKey()), is(entry.getValue())))
+ .or(new IsMapContaining(new
IsEqualIgnoringCase(entry.getKey()),
+ is((Boolean) entry.getValue() ? 1 : 0)));
+ } else {
+ fieldCondition = new IsMapContaining(new
IsEqualIgnoringCase(entry.getKey()), is(entry.getValue()));
+ }
+
+ if (m == null) {
+ m = fieldCondition;
+ } else {
+ m = both(m).and(fieldCondition);
+ }
}
+ return m;
}
}