This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch 3.15.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 073e1dce83794c45c98c3f9bcf0436fc8007828c
Author: JiriOndrusek <ondrusek.j...@gmail.com>
AuthorDate: Thu Oct 17 16:56:58 2024 +0200

    Mysql testResource instead of devservices
---
 integration-test-groups/jdbc/mysql/README.adoc     | 26 ------
 integration-test-groups/jdbc/mysql/pom.xml         | 26 +++---
 .../jdbc/mysql/Sha256FIPSPasswordPlugin.java       | 38 ---------
 .../src/main/resources/application.properties      |  2 +-
 .../component/jdbc/mysql/CamelMysqlJdbcTest.java   |  3 +-
 .../component/jdbc/mysql/MysqlTestResource.java    | 92 ++++++++++++++++++++++
 integration-tests/jdbc-grouped/pom.xml             | 26 +++---
 7 files changed, 127 insertions(+), 86 deletions(-)

diff --git a/integration-test-groups/jdbc/mysql/README.adoc 
b/integration-test-groups/jdbc/mysql/README.adoc
deleted file mode 100644
index 14b0704560..0000000000
--- a/integration-test-groups/jdbc/mysql/README.adoc
+++ /dev/null
@@ -1,26 +0,0 @@
-== JDBC MySql tests
-
-=== FIPS
-
-* To execute the tests on FIPS enabled system add `-Dfips` property so that 
tests will use prooper transformation for the password. Example of usage:
-
-`mvn clean test -Dfips`
-
-* Dev service (MySql docker image) does not start correctly on FIPS enabled 
system. Please use external database.
-
-To execute the tests against external database, provide the database's 
connection information by setting environment variables
-
-```
-export MYSQL_JDBC_URL=#jdbc_url
-export MYSQL_JDBC_USERNAME=#username
-export MYSQL_JDBC_PASSWORD=#password
-```
-
-or for windows:
-
-```
-$Env:MYSQL_JDBC_URL = "#jdbc_url"
-$Env:MYSQL_JDBC_USERNAME="#username"
-$Env:MYSQL_JDBC_PASSWORD
-```
-.
\ No newline at end of file
diff --git a/integration-test-groups/jdbc/mysql/pom.xml 
b/integration-test-groups/jdbc/mysql/pom.xml
index b70d9d7ca3..43b3e033f2 100644
--- a/integration-test-groups/jdbc/mysql/pom.xml
+++ b/integration-test-groups/jdbc/mysql/pom.xml
@@ -99,6 +99,22 @@
             <type>test-jar</type>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit4-mock</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 
@@ -279,12 +295,7 @@
                         <artifactId>maven-surefire-plugin</artifactId>
                         <configuration>
                             <systemPropertyVariables>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>org.apache.camel.quarkus.component.jdbc.mysql.Sha256FIPSPasswordPlugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>cq_fips_plugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>
                                 
<quarkus.datasource.mysql.devservices.enabled>false</quarkus.datasource.mysql.devservices.enabled>
-                                
<quarkus.datasource.mysql.username>${env.MYSQL_JDBC_USERNAME}</quarkus.datasource.mysql.username>
-                                
<quarkus.datasource.mysql.password>${env.MYSQL_JDBC_PASSWORD}</quarkus.datasource.mysql.password>
-                                
<quarkus.datasource.mysql.jdbc.url>${env.MYSQL_JDBC_URL}</quarkus.datasource.mysql.jdbc.url>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>
@@ -293,12 +304,7 @@
                         <artifactId>maven-failsafe-plugin</artifactId>
                         <configuration>
                             <systemPropertyVariables>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>org.apache.camel.quarkus.component.jdbc.mysql.Sha256FIPSPasswordPlugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>cq_fips_plugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>
                                 
<quarkus.datasource.mysql.devservices.enabled>false</quarkus.datasource.mysql.devservices.enabled>
-                                
<quarkus.datasource.mysql.username>${env.MYSQL_JDBC_USERNAME}</quarkus.datasource.mysql.username>
-                                
<quarkus.datasource.mysql.password>${env.MYSQL_JDBC_PASSWORD}</quarkus.datasource.mysql.password>
-                                
<quarkus.datasource.mysql.jdbc.url>${env.MYSQL_JDBC_URL}</quarkus.datasource.mysql.jdbc.url>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>
diff --git 
a/integration-test-groups/jdbc/mysql/src/main/java/org/apache/camel/quarkus/component/jdbc/mysql/Sha256FIPSPasswordPlugin.java
 
b/integration-test-groups/jdbc/mysql/src/main/java/org/apache/camel/quarkus/component/jdbc/mysql/Sha256FIPSPasswordPlugin.java
deleted file mode 100644
index 70da05c5ad..0000000000
--- 
a/integration-test-groups/jdbc/mysql/src/main/java/org/apache/camel/quarkus/component/jdbc/mysql/Sha256FIPSPasswordPlugin.java
+++ /dev/null
@@ -1,38 +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.jdbc.mysql;
-
-import com.mysql.cj.protocol.a.authentication.Sha256PasswordPlugin;
-import io.quarkus.runtime.annotations.RegisterForReflection;
-
-@RegisterForReflection
-public class Sha256FIPSPasswordPlugin extends Sha256PasswordPlugin {
-
-    public Sha256FIPSPasswordPlugin() {
-        super();
-    }
-
-    @Override
-    public String getProtocolPluginName() {
-        return "cq_fips_plugin";
-    }
-
-    @Override
-    protected byte[] encryptPassword() {
-        return encryptPassword("RSA/ECB/PKCS1Padding");
-    }
-}
diff --git 
a/integration-test-groups/jdbc/mysql/src/main/resources/application.properties 
b/integration-test-groups/jdbc/mysql/src/main/resources/application.properties
index 0c3aafab07..6ee2c27fef 100644
--- 
a/integration-test-groups/jdbc/mysql/src/main/resources/application.properties
+++ 
b/integration-test-groups/jdbc/mysql/src/main/resources/application.properties
@@ -22,4 +22,4 @@
 quarkus.datasource.mysql.db-kind=mysql
 quarkus.datasource.mysql.jdbc.max-size=8
 
-quarkus.native.resources.includes=postgresql.sql,mysql.sql,mariadb.sql,oracle.sql,h2.sql,db2.sql,inserts.sql,mssql.sql,droptables.sql
\ No newline at end of file
+quarkus.native.resources.includes=postgresql.sql,mysql.sql,mariadb.sql,oracle.sql,h2.sql,db2.sql,inserts.sql,mssql.sql,droptables.sql
diff --git 
a/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/CamelMysqlJdbcTest.java
 
b/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/CamelMysqlJdbcTest.java
index 0cbfb3a01e..7ffdb5d5d5 100644
--- 
a/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/CamelMysqlJdbcTest.java
+++ 
b/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/CamelMysqlJdbcTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.quarkus.component.jdbc.mysql;
 
 import java.util.List;
 
+import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
@@ -34,7 +35,7 @@ import static org.wildfly.common.Assert.assertNotNull;
 
 @QuarkusTest
 @DisabledIfSystemProperty(named = "cq.jdbcKind", matches = "derby")
-//https://github.com/quarkusio/quarkus/issues/23083
+@QuarkusTestResource(value = MysqlTestResource.class)
 public class CamelMysqlJdbcTest {
     String dbKind = "mysql";
 
diff --git 
a/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/MysqlTestResource.java
 
b/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/MysqlTestResource.java
new file mode 100644
index 0000000000..135d9a6950
--- /dev/null
+++ 
b/integration-test-groups/jdbc/mysql/src/test/java/org/apache/camel/quarkus/component/jdbc/mysql/MysqlTestResource.java
@@ -0,0 +1,92 @@
+/*
+ * 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.jdbc.mysql;
+
+import java.util.Collections;
+import java.util.Map;
+
+import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+/**
+ * This is a workaround because of the FIPS environment.
+ * DevService does not work on FIS 
https://github.com/quarkusio/quarkus/issues/40526
+ *
+ * If devservice is disabled (by FIPS profile), this test resource starts a 
simple test container.
+ * (which works on FIPS, because the where the validation of the DB is not 
solved via connection ,but by the listening
+ * port.)
+ */
+public class MysqlTestResource implements QuarkusTestResourceLifecycleManager {
+    private static final Logger LOG = 
LoggerFactory.getLogger(MysqlTestResource.class);
+
+    public static final String DB_NAME = "test";
+    public static final String DB_USERNAME = "user";
+    public static final String DB_PASSWORD = "test";
+    private static final int DB_PORT = 3306;
+    private static final String MYSQL_IMAGE = 
ConfigProvider.getConfig().getValue("mysql.container.image", String.class);
+    private GenericContainer container;
+
+    @Override
+    public Map<String, String> start() {
+
+        //in dev service is not enabled, spawn a db
+        if 
(!ConfigProvider.getConfig().getOptionalValue("quarkus.datasource.mysql.devservices.enabled",
 Boolean.class)
+                .orElse(true)) {
+            LOG.info("DevService is disabled, MySql container is starting.");
+
+            container = new GenericContainer<>(MYSQL_IMAGE)
+                    .withExposedPorts(DB_PORT)
+                    .withEnv("MYSQL_USER", DB_USERNAME)
+                    .withEnv("MYSQL_ROOT_PASSWORD", DB_PASSWORD)
+                    .withEnv("MYSQL_PASSWORD", DB_PASSWORD)
+                    .withEnv("MYSQL_DATABASE", DB_NAME)
+                    .waitingFor(Wait.forListeningPort());
+
+            container.start();
+
+            return Map.of(
+                    "quarkus.datasource.mysql.jdbc.url", getJdbcUrl(),
+                    "quarkus.datasource.mysql.username", DB_USERNAME,
+                    "quarkus.datasource.mysql.password", DB_PASSWORD,
+                    "quarkus.datasource.mysql.devservices.enabled", "false");
+        }
+        //if devservice is running, nothing has to be done
+        return Collections.emptyMap();
+    }
+
+    @Override
+    public void stop() {
+        try {
+            if (container != null) {
+                container.stop();
+            }
+        } catch (Exception e) {
+            // Ignored
+        }
+    }
+
+    protected String getJdbcUrl() {
+        return "jdbc:mysql://" + container.getHost() + ":" + 
container.getMappedPort(DB_PORT) + "/"
+                + DB_NAME + "?user=" + DB_USERNAME
+                + "&password=" + DB_PASSWORD;
+    }
+
+}
diff --git a/integration-tests/jdbc-grouped/pom.xml 
b/integration-tests/jdbc-grouped/pom.xml
index 61a5d2409a..aab703d1cd 100644
--- a/integration-tests/jdbc-grouped/pom.xml
+++ b/integration-tests/jdbc-grouped/pom.xml
@@ -124,6 +124,22 @@
             <artifactId>camel-quarkus-integration-test-support</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-junit4-mock</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
@@ -297,12 +313,7 @@
                         <artifactId>maven-surefire-plugin</artifactId>
                         <configuration>
                             <systemPropertyVariables>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>org.apache.camel.quarkus.component.jdbc.mysql.Sha256FIPSPasswordPlugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>cq_fips_plugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>
                                 
<quarkus.datasource.mysql.devservices.enabled>false</quarkus.datasource.mysql.devservices.enabled>
-                                
<quarkus.datasource.mysql.username>${env.MYSQL_JDBC_USERNAME}</quarkus.datasource.mysql.username>
-                                
<quarkus.datasource.mysql.password>${env.MYSQL_JDBC_PASSWORD}</quarkus.datasource.mysql.password>
-                                
<quarkus.datasource.mysql.jdbc.url>${env.MYSQL_JDBC_URL}</quarkus.datasource.mysql.jdbc.url>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>
@@ -311,12 +322,7 @@
                         <artifactId>maven-failsafe-plugin</artifactId>
                         <configuration>
                             <systemPropertyVariables>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>org.apache.camel.quarkus.component.jdbc.mysql.Sha256FIPSPasswordPlugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.authenticationPlugins>
-                                
<quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>cq_fips_plugin</quarkus.datasource.mysql.jdbc.additional-jdbc-properties.defaultAuthenticationPlugin>
                                 
<quarkus.datasource.mysql.devservices.enabled>false</quarkus.datasource.mysql.devservices.enabled>
-                                
<quarkus.datasource.mysql.username>${env.MYSQL_JDBC_USERNAME}</quarkus.datasource.mysql.username>
-                                
<quarkus.datasource.mysql.password>${env.MYSQL_JDBC_PASSWORD}</quarkus.datasource.mysql.password>
-                                
<quarkus.datasource.mysql.jdbc.url>${env.MYSQL_JDBC_URL}</quarkus.datasource.mysql.jdbc.url>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>

Reply via email to