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 6a1134dd20 Simplify running SQL test against external database servers
6a1134dd20 is described below

commit 6a1134dd201007bf0486f4f2e007713376c80551
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Tue May 6 11:06:40 2025 +0100

    Simplify running SQL test against external database servers
    
    Fixes #7316
---
 integration-tests/sql/README.adoc                  | 73 +++++++++-------------
 .../component/sql/it/SqlConfigSourceFactory.java   | 63 -------------------
 .../camel/quarkus/component/sql/it/SqlHelper.java  | 12 +---
 .../io.smallrye.config.ConfigSourceFactory         |  1 -
 4 files changed, 30 insertions(+), 119 deletions(-)

diff --git a/integration-tests/sql/README.adoc 
b/integration-tests/sql/README.adoc
index 67c66e4901..d11b9554ed 100644
--- a/integration-tests/sql/README.adoc
+++ b/integration-tests/sql/README.adoc
@@ -2,69 +2,54 @@
 
 === Default database type
 
-When the tests are executed without any special configuration, dev-service 
`H2` database is used (more details will follow).
+When the tests are executed without any special configuration, dev service 
`H2` database is used (more details will follow).
 
-=== Dev-service databases
+=== Quarkus 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:
+As described in the 
https://quarkus.io/guides/datasource#dev-services[documentation], several 
database types can be started in dev service mode.
+Running the tests against a database in dev service mode can be achieved by 
addition of build property `cq.sqlJdbcKind`. For example.
 
-`mvn clean test -f integration-tests/sql/ -Dcq.sqlJdbcKind=postgresql`
+[source]
+----
+mvn clean test -f integration-tests/sql/ -Dcq.sqlJdbcKind=postgresql
+----
 
-Following databases could be started in the dev-service mode:
+The following databases can be started in 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`
+- Apache Derby (container) - add `-Dcq.sqlJdbcKind=derby`
 - DB2 (container) (requires license acceptance) - add `-Dcq.sqlJdbcKind=db2`
 - MSSQL (container) (requires license acceptance) - add 
`-Dcq.sqlJdbcKind=mssql`
+- Oracle (container) - add `-Dcq.sqlJdbcKind=oracle`
 
-For more information about dev-service mode, see 
https://quarkus.io/guides/datasource#dev-services[documentation].
+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
+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).
 
-```
-export SQL_JDBC_URL=#jdbc_url
-export SQL_JDBC_USERNAME=#username
-export SQL_JDBC_PASSWORD=#password
-```
+The database JDBC connection URL and username / password credentials can be 
provided via environment variables.
 
-or for windows:
+[source]
+----
+export QUARKUS_DATASOURCE_JDBC_URL=#jdbc_url
+export QUARKUS_DATASOURCE_USERNAME=#username
+export QUARKUS_DATASOURCE_PASSWORD=#password
+----
 
-```
-$Env:SQL_JDBC_URL = "#jdbc_url"
-$Env:SQL_JDBC_USERNAME="#username"
-$Env:SQL_JDBC_PASSWORD="#password"
-```
+or for windows:
 
-Oracle database could be used as external db. In that case use parameter 
`-Dcq.sqlJdbcKind=oracle`.
+[source]
+----
+$Env:QUARKUS_DATASOURCE_JDBC_URL="#jdbc_url"
+$Env:QUARKUS_DATASOURCE_USERNAME="#username"
+$Env:QUARKUS_DATASOURCE_PASSWORD="#password"
+----
 
 === External Derby database
 
-To execute tests against external Derby database, stored procedure has to be 
uploaded into the database classpath.
-Jar with stored procedure for the derby database is creaed by module 
`sql-derby`.
-Jar could be uploaded via following commands through `ij`:
-```
-CALL 
sqlj.install_jar('/PATH_TO_JAR/camel-quarkus-integration-test-sql-derby-stored-procedure-*.jar',
 'AddNumsProcedure' , 0)
-
-CALL syscs_util.syscs_set_database_property('derby.database.classpath', 
'APP.ADDNUMSPROCEDURE')
-```
-
-=== External Derby database via Docker
-
-To avoid manual upload of the jar, test can automatically use external derby 
database created via docker.
-To execute the tests against external derby database, set the environment 
variable `SQL_USE_DERBY_DOCKER` to value `true`:
-
-```
-export SQL_USE_DERBY_DOCKER=true
-```
-
-or for windows:
-
-```
-$Env:SQL_USE_DERBY_DOCKER = "true"
+To avoid complexities around having to upload stored procedure JARs to the DB 
server, Apache Derby is always tested within a container.
+Therefore, you should avoid setting `QUARKUS_DATASOURCE` environment variables 
for Derby.
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
deleted file mode 100644
index 403a922ddc..0000000000
--- 
a/integration-tests/sql/src/main/java/org/apache/camel/quarkus/component/sql/it/SqlConfigSourceFactory.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 java.util.Map;
-import java.util.OptionalInt;
-
-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 static final MapBackedConfigSource source;
-
-    static {
-        String jdbcUrl = System.getenv("SQL_JDBC_URL");
-
-        Map<String, String> props = new HashMap<>();
-        //external db
-        if (jdbcUrl != null) {
-            props.put("quarkus.datasource.jdbc.url", jdbcUrl);
-            props.put("quarkus.datasource.username", 
System.getenv("SQL_JDBC_USERNAME"));
-            props.put("quarkus.datasource.password", 
System.getenv("SQL_JDBC_PASSWORD"));
-        } else {
-            //derby could be started in container
-            boolean useDocker = 
Boolean.parseBoolean(System.getenv("SQL_USE_DERBY_DOCKER")) &&
-                    "derby".equals(System.getProperty("cq.sqlJdbcKind"));
-            props.put("quarkus.devservices.enabled", 
String.valueOf(!useDocker));
-        }
-
-        source = new MapBackedConfigSource("env_database", props) {
-        };
-    }
-
-    @Override
-    public Iterable<ConfigSource> getConfigSources(ConfigSourceContext 
configSourceContext) {
-        return Collections.singletonList(source);
-    }
-
-    @Override
-    public OptionalInt getPriority() {
-        return OptionalInt.of(999);
-    }
-
-}
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
index 8f79182d47..65df4d3c70 100644
--- 
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
@@ -20,11 +20,9 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.eclipse.microprofile.config.ConfigProvider;
-
 public class SqlHelper {
 
-    private static Set<String> BOOLEAN_AS_NUMBER = new 
HashSet<>(Arrays.asList("db2", "mssql", "oracle"));
+    private static final Set<String> BOOLEAN_AS_NUMBER = new 
HashSet<>(Arrays.asList("db2", "mssql", "oracle"));
 
     static String convertBooleanToSqlDialect(String dbKind, boolean value) {
         return convertBooleanToSqlResult(dbKind, value).toString();
@@ -41,12 +39,4 @@ public class SqlHelper {
     static String getSelectProjectsScriptName(String dbKind) {
         return BOOLEAN_AS_NUMBER.contains(dbKind) ? 
"selectProjectsAsNumber.sql" : "selectProjectsAsBoolean.sql";
     }
-
-    public static boolean useDocker() {
-        return Boolean.parseBoolean(System.getenv("SQL_USE_DERBY_DOCKER")) &&
-                
"derby".equals(ConfigProvider.getConfig().getOptionalValue("quarkus.datasource.db-kind",
 String.class)
-                        .orElse(System.getProperty("cq.sqlJdbcKind")))
-                && System.getenv("SQL_JDBC_URL") == null;
-    }
-
 }
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
deleted file mode 100644
index 28d2ad648d..0000000000
--- 
a/integration-tests/sql/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.camel.quarkus.component.sql.it.SqlConfigSourceFactory
\ No newline at end of file

Reply via email to