You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/11/04 07:24:57 UTC
[camel-quarkus] branch main updated: Sql - enable stored procedure
test for different db types #3080
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton 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 dc433f7 Sql - enable stored procedure test for different db types #3080
dc433f7 is described below
commit dc433f7d00de425f81f9b21550af5cfdbfedb9ec
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Wed Nov 3 16:35:23 2021 +0100
Sql - enable stored procedure test for different db types #3080
---
integration-tests/sql/README.adoc | 2 +-
.../camel/quarkus/component/sql/it/SqlDbInitializer.java | 2 +-
.../camel/quarkus/component/sql/it/SqlResource.java | 16 +++++++++++++++-
.../sql/src/main/resources/sql/db2/initDb.sql | 7 +++++++
.../sql/src/main/resources/sql/mariadb/initDb.sql | 8 ++++++++
.../sql/src/main/resources/sql/mssql/initDb.sql | 9 ++++++++-
.../sql/src/main/resources/sql/mysql/initDb.sql | 7 +++++++
.../sql/src/main/resources/sql/postgresql/initDb.sql | 1 +
.../apache/camel/quarkus/component/sql/it/SqlTest.java | 2 +-
9 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/integration-tests/sql/README.adoc b/integration-tests/sql/README.adoc
index b66edd3..2b93edd 100644
--- a/integration-tests/sql/README.adoc
+++ b/integration-tests/sql/README.adoc
@@ -9,7 +9,7 @@ When the tests are executed without any special configuration, dev-service `H2`
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`
+`mvn clean test -f integration-tests/sql/ -Dcq.sqlJdbcKind=postgresql`
Following databases could be started in the dev-service mode:
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 796aeb0..ec400e7 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
@@ -56,7 +56,7 @@ public class SqlDbInitializer {
try {
statement.execute(s);
} catch (SQLException e) {
- if (!s.toUpperCase().startsWith("DROP TABLE")) {
+ if (!s.toUpperCase().startsWith("DROP")) {
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/SqlResource.java b/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlResource.java
index c20cf1b..702b5ba 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
@@ -162,7 +162,21 @@ public class SqlResource {
.requestBodyAndHeaders("sql-stored:ADD_NUMS(INTEGER ${headers.num1},INTEGER ${headers.num2})", null, args,
Map.class);
- return results.get("#result-set-1").get(0).get("PUBLIC.ADD_NUMS(?1, ?2)").toString();
+ //different db types behaves differently
+ switch (dbKind) {
+ case "db2":
+ case "mssql":
+ case "mariadb":
+ case "mysql":
+ List<LinkedCaseInsensitiveMap> addNumsResults = producerTemplate.requestBody(
+ "sql:SELECT * FROM ADD_NUMS_RESULTS WHERE id = 1?outputType=SelectList",
+ null,
+ List.class);
+
+ return String.valueOf(addNumsResults.get(0).get("value"));
+ default:
+ return results.get("#result-set-1").get(0).values().iterator().next().toString();
+ }
}
@Path("/get/results/{resultId}")
diff --git a/integration-tests/sql/src/main/resources/sql/db2/initDb.sql b/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
index 895b56a..c38db89 100644
--- a/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/db2/initDb.sql
@@ -36,3 +36,10 @@ CREATE TABLE aggregation (id VARCHAR(255) NOT NULL, exchange BLOB, version BIGIN
DROP TABLE AGGREGATION_COMPLETED
CREATE TABLE aggregation_completed (id VARCHAR(255) NOT NULL, exchange BLOB, version BIGINT)
+-- stored procedure
+
+DROP TABLE ADD_NUMS_RESULTS
+CREATE TABLE ADD_NUMS_RESULTS (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, value INT NOT NULL)
+
+DROP PROCEDURE ADD_NUMS
+CREATE PROCEDURE ADD_NUMS (IN A INT, IN B INT) LANGUAGE SQL P1: BEGIN insert into ADD_NUMS_RESULTS (id, value) VALUES (1, A + B); END P1
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql b/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
index 8b5788a..c3ec3b1 100644
--- a/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mariadb/initDb.sql
@@ -35,3 +35,11 @@ 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));
+
+
+
+DROP TABLE IF EXISTS ADD_NUMS_RESULTS
+CREATE TABLE ADD_NUMS_RESULTS (id INT PRIMARY KEY, value INT NOT NULL);
+
+DROP PROCEDURE IF EXISTS ADD_NUMS
+CREATE PROCEDURE ADD_NUMS(a integer,b integer) insert into ADD_NUMS_RESULTS (id, value) VALUES (1, a + b);
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql b/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
index a61b4b2..2ac49b8 100644
--- a/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mssql/initDb.sql
@@ -35,4 +35,11 @@ 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
+CREATE TABLE aggregation_completed (id varchar(255), exchange Image, version bigint);
+
+-- stored procedure
+DROP TABLE ADD_NUMS_RESULTS
+CREATE TABLE ADD_NUMS_RESULTS (id int NOT NULL IDENTITY PRIMARY KEY, value int not null )
+
+DROP PROCEDURE ADD_NUMS
+CREATE PROCEDURE ADD_NUMS(@A INT, @B INT) AS BEGIN SET NOCOUNT ON insert into ADD_NUMS_RESULTS (value) VALUES (@A + @B); END
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql b/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
index da8ff4c..8e79aee 100644
--- a/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/mysql/initDb.sql
@@ -36,3 +36,10 @@ 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));
+
+-- stored procedure
+DROP TABLE IF EXISTS ADD_NUMS_RESULTS
+CREATE TABLE ADD_NUMS_RESULTS (id INT PRIMARY KEY, value INT NOT NULL);
+
+DROP PROCEDURE IF EXISTS ADD_NUMS
+CREATE PROCEDURE ADD_NUMS(a integer,b integer) insert into ADD_NUMS_RESULTS (id, value) VALUES (1, a + b);
\ No newline at end of file
diff --git a/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql b/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
index f47eaf1..fd24a24 100644
--- a/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
+++ b/integration-tests/sql/src/main/resources/sql/postgresql/initDb.sql
@@ -36,3 +36,4 @@ CREATE TABLE aggregation (id varchar(255) NOT NULL, exchange BYTEA NOT NULL, ver
DROP TABLE IF EXISTS aggregation_completed
CREATE TABLE aggregation_completed (id varchar(255) NOT NULL, exchange BYTEA NOT NULL, version BIGINT NOT NULL, constraint aggregation_completed_pk PRIMARY KEY (id));
+CREATE OR REPLACE FUNCTION ADD_NUMS(a integer,b integer) RETURNS integer AS 'BEGIN RETURN a + b; END;' LANGUAGE plpgsql
\ No newline at end of file
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 9cd6393..c696896 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
@@ -71,7 +71,7 @@ class SqlTest {
}
@Test
- @DisabledIfSystemProperty(named = "cq.sqlJdbcKind", matches = "[^h][^2].*", disabledReason = "https://github.com/apache/camel-quarkus/issues/3080")
+ @DisabledIfSystemProperty(named = "cq.sqlJdbcKind", matches = "derby", disabledReason = "https://github.com/apache/camel-quarkus/issues/3260")
public void testSqlStoredComponent() {
// Invoke ADD_NUMS stored procedure
RestAssured.given()