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

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c9a724a  Migrates camel-couchdb to the new test infra (#4725)
c9a724a is described below

commit c9a724adc1097bc1de609f722a4020ba81d77c3b
Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com>
AuthorDate: Fri Dec 4 22:57:41 2020 +0100

    Migrates camel-couchdb to the new test infra (#4725)
---
 components/camel-couchdb/pom.xml                   | 22 ++++--
 .../camel/component/couchdb/CouchDbCrudTest.java   |  2 +-
 .../component/couchdb/CouchDbTestSupport.java      | 30 ++------
 test-infra/camel-test-infra-couchdb/pom.xml        | 60 +++++++++++++++
 .../src/main/resources/META-INF/MANIFEST.MF        |  0
 .../infra/couchdb/common/CouchDbProperties.java    | 29 +++++++
 .../services/CouchDbLocalContainerService.java     | 88 ++++++++++++++++++++++
 .../couchdb/services/CouchDbRemoteService.java     | 54 +++++++++++++
 .../infra/couchdb/services/CouchDbService.java     | 46 +++++++++++
 .../couchdb/services/CouchDbServiceFactory.java    | 43 +++++++++++
 test-infra/pom.xml                                 |  1 +
 11 files changed, 347 insertions(+), 28 deletions(-)

diff --git a/components/camel-couchdb/pom.xml b/components/camel-couchdb/pom.xml
index 3bf71bc..e6be5be 100644
--- a/components/camel-couchdb/pom.xml
+++ b/components/camel-couchdb/pom.xml
@@ -56,11 +56,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-testcontainers-junit5</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-junit-jupiter</artifactId>
             <scope>test</scope>
@@ -70,6 +65,23 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- test infra -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-couchdb</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>
diff --git 
a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbCrudTest.java
 
b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbCrudTest.java
index a7d1b65..86faf8e 100644
--- 
a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbCrudTest.java
+++ 
b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbCrudTest.java
@@ -54,7 +54,7 @@ public class CouchDbCrudTest extends CouchDbTestSupport {
     @Override
     protected RouteBuilder createRouteBuilder() {
         final String couchDbUrlFormat
-                = "couchdb:http://"; + getCouchDbHost() + ":" + 
getCouchDbPort() + "/camelcouchdb?createDatabase=true%s";
+                = 
"couchdb:http://{{couchdb.service.address}}/camelcouchdb?createDatabase=true%s";;
 
         return new RouteBuilder() {
             @Override
diff --git 
a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbTestSupport.java
 
b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbTestSupport.java
index 750552d..109d9f2 100644
--- 
a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbTestSupport.java
+++ 
b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbTestSupport.java
@@ -16,28 +16,14 @@
  */
 package org.apache.camel.component.couchdb;
 
-import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
-import org.testcontainers.containers.GenericContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.apache.camel.test.infra.couchdb.services.CouchDbService;
+import org.apache.camel.test.infra.couchdb.services.CouchDbServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
-public class CouchDbTestSupport extends ContainerAwareTestSupport {
-
-    public static final String CONTAINER_IMAGE = "couchdb:2.3.1"; // tested 
against 2.1.2, 2.2.0 & 2.3.1
-    public static final String CONTAINER_NAME = "couchdb";
-    public static final int BROKER_PORT = 5984;
-
-    @Override
-    protected GenericContainer<?> createContainer() {
-        return new 
GenericContainer<>(CONTAINER_IMAGE).withNetworkAliases(CONTAINER_NAME).withExposedPorts(BROKER_PORT)
-                .waitingFor(Wait.forListeningPort());
-    }
-
-    public String getCouchDbHost() {
-        return getContainer(CONTAINER_NAME).getContainerIpAddress();
-    }
-
-    public int getCouchDbPort() {
-        return 
getContainer(CONTAINER_NAME).getMappedPort(BROKER_PORT).intValue();
-    }
+public class CouchDbTestSupport extends CamelTestSupport {
+    @SuppressWarnings("unused")
+    @RegisterExtension
+    static CouchDbService service = CouchDbServiceFactory.createService();
 
 }
diff --git a/test-infra/camel-test-infra-couchdb/pom.xml 
b/test-infra/camel-test-infra-couchdb/pom.xml
new file mode 100644
index 0000000..b2794083
--- /dev/null
+++ b/test-infra/camel-test-infra-couchdb/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>camel-test-infra-parent</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+        <version>3.7.0-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-test-infra-couchdb</artifactId>
+    <name>Camel :: Test Infra :: CouchDb</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>testcontainers</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>
\ No newline at end of file
diff --git 
a/test-infra/camel-test-infra-couchdb/src/main/resources/META-INF/MANIFEST.MF 
b/test-infra/camel-test-infra-couchdb/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
diff --git 
a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/common/CouchDbProperties.java
 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/common/CouchDbProperties.java
new file mode 100644
index 0000000..1223a2d
--- /dev/null
+++ 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/common/CouchDbProperties.java
@@ -0,0 +1,29 @@
+/*
+ * 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.test.infra.couchdb.common;
+
+public final class CouchDbProperties {
+    public static final String SERVICE_ADDRESS = "couchdb.service.address";
+    public static final String HOST = "couchdb.host";
+    public static final String PORT = "couchdb.port";
+    public static final int DEFAULT_PORT = 5984;
+
+    private CouchDbProperties() {
+
+    }
+}
diff --git 
a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbLocalContainerService.java
 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbLocalContainerService.java
new file mode 100644
index 0000000..ae841a6
--- /dev/null
+++ 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbLocalContainerService.java
@@ -0,0 +1,88 @@
+/*
+ * 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.test.infra.couchdb.services;
+
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.couchdb.common.CouchDbProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.DockerImageName;
+
+public class CouchDbLocalContainerService implements CouchDbService, 
ContainerService<GenericContainer> {
+    public static final String CONTAINER_IMAGE = "couchdb:2.3.1"; // tested 
against 2.1.2, 2.2.0 & 2.3.1
+    public static final String CONTAINER_NAME = "couchdb";
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CouchDbLocalContainerService.class);
+
+    private GenericContainer container;
+
+    public CouchDbLocalContainerService() {
+        String containerName = System.getProperty("couchdb.container", 
CONTAINER_IMAGE);
+
+        initContainer(containerName);
+    }
+
+    public CouchDbLocalContainerService(String imageName) {
+        initContainer(imageName);
+    }
+
+    protected void initContainer(String imageName) {
+        container = new GenericContainer<>(DockerImageName.parse(imageName))
+                .withNetworkAliases(CONTAINER_NAME)
+                .withExposedPorts(CouchDbProperties.DEFAULT_PORT)
+                .waitingFor(Wait.forListeningPort());
+    }
+
+    @Override
+    public void registerProperties() {
+        System.setProperty(CouchDbProperties.SERVICE_ADDRESS, 
getServiceAddress());
+        System.setProperty(CouchDbProperties.PORT, String.valueOf(port()));
+        System.setProperty(CouchDbProperties.HOST, host());
+    }
+
+    @Override
+    public void initialize() {
+        LOG.info("Trying to start the CouchDb container");
+        container.start();
+
+        registerProperties();
+        LOG.info("CouchDb instance running at {}", getServiceAddress());
+    }
+
+    @Override
+    public void shutdown() {
+        LOG.info("Stopping the CouchDb container");
+        container.stop();
+    }
+
+    @Override
+    public GenericContainer getContainer() {
+        return container;
+    }
+
+    @Override
+    public String host() {
+        return container.getContainerIpAddress();
+    }
+
+    @Override
+    public int port() {
+        return container.getMappedPort(CouchDbProperties.DEFAULT_PORT);
+    }
+}
diff --git 
a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbRemoteService.java
 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbRemoteService.java
new file mode 100644
index 0000000..29c11af
--- /dev/null
+++ 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbRemoteService.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.test.infra.couchdb.services;
+
+import org.apache.camel.test.infra.couchdb.common.CouchDbProperties;
+
+public class CouchDbRemoteService implements CouchDbService {
+
+    @Override
+    public void registerProperties() {
+        // NO-OP
+    }
+
+    @Override
+    public void initialize() {
+        registerProperties();
+    }
+
+    @Override
+    public void shutdown() {
+        // NO-OP
+    }
+
+    @Override
+    public String host() {
+        return System.getProperty(CouchDbProperties.HOST);
+    }
+
+    @Override
+    public int port() {
+        String port = System.getProperty(CouchDbProperties.PORT);
+
+        if (port == null) {
+            return CouchDbProperties.DEFAULT_PORT;
+        }
+
+        return Integer.valueOf(port);
+    }
+
+}
diff --git 
a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbService.java
 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbService.java
new file mode 100644
index 0000000..4f4caf3
--- /dev/null
+++ 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbService.java
@@ -0,0 +1,46 @@
+/*
+ * 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.test.infra.couchdb.services;
+
+import org.apache.camel.test.infra.common.services.TestService;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Test infra service for CouchDb
+ */
+public interface CouchDbService extends BeforeAllCallback, AfterAllCallback, 
TestService {
+
+    String host();
+
+    int port();
+
+    default String getServiceAddress() {
+        return String.format("%s:%d", host(), port());
+    }
+
+    @Override
+    default void beforeAll(ExtensionContext extensionContext) throws Exception 
{
+        initialize();
+    }
+
+    @Override
+    default void afterAll(ExtensionContext extensionContext) throws Exception {
+        shutdown();
+    }
+}
diff --git 
a/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java
 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java
new file mode 100644
index 0000000..718e38a
--- /dev/null
+++ 
b/test-infra/camel-test-infra-couchdb/src/test/java/org/apache/camel/test/infra/couchdb/services/CouchDbServiceFactory.java
@@ -0,0 +1,43 @@
+/*
+ * 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.test.infra.couchdb.services;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class CouchDbServiceFactory {
+    private static final Logger LOG = 
LoggerFactory.getLogger(CouchDbServiceFactory.class);
+
+    private CouchDbServiceFactory() {
+
+    }
+
+    public static CouchDbService createService() {
+        String instanceType = System.getProperty("couchdb.instance.type");
+
+        if (instanceType == null || 
instanceType.equals("local-couchdb-container")) {
+            return new CouchDbLocalContainerService();
+        }
+
+        if (instanceType.equals("remote")) {
+            return new CouchDbRemoteService();
+        }
+
+        LOG.error("CouchDb instance must be one of 'local-couchdb-container' 
or 'remote");
+        throw new UnsupportedOperationException("Invalid CouchDb instance 
type");
+    }
+}
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index 5eb74b0..bd28c36 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -65,5 +65,6 @@
         <module>camel-test-infra-xmpp</module>
         <module>camel-test-infra-zookeeper</module>
         <module>camel-test-infra-postgres</module>
+        <module>camel-test-infra-couchdb</module>
     </modules>
 </project>

Reply via email to