You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/12/17 10:06:33 UTC

[camel-kafka-connector] branch master updated: Align MongoDB tests with test infra from Camel 3.7

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

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git


The following commit(s) were added to refs/heads/master by this push:
     new ccc2d32  Align MongoDB tests with test infra from Camel 3.7
ccc2d32 is described below

commit ccc2d32ba69e4ddc40e84e6291a48f75bc62eac5
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Thu Dec 17 10:35:10 2020 +0100

    Align MongoDB tests with test infra from Camel 3.7
---
 tests/itests-mongodb/pom.xml                       | 21 ++++++--
 .../services/MongoDBLocalContainerService.java     | 56 ----------------------
 .../mongodb/services/MongoDBService.java           | 46 ------------------
 .../mongodb/services/MongoDBServiceFactory.java    | 44 -----------------
 .../mongodb/services/RemoteMongoDBService.java     | 35 --------------
 .../mongodb/sink/CamelSinkMongoDBITCase.java       |  6 +--
 .../mongodb/source/CamelSourceMongoDBITCase.java   |  6 +--
 7 files changed, 20 insertions(+), 194 deletions(-)

diff --git a/tests/itests-mongodb/pom.xml b/tests/itests-mongodb/pom.xml
index 0db665d..77bf271 100644
--- a/tests/itests-mongodb/pom.xml
+++ b/tests/itests-mongodb/pom.xml
@@ -37,20 +37,31 @@
             <scope>test</scope>
         </dependency>
 
+        <!-- test infra -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-mongodb</artifactId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${camel.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
-            <groupId>org.mongodb</groupId>
-            <artifactId>mongodb-driver-legacy</artifactId>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-mongodb</artifactId>
+            <version>${camel.version}</version>
+            <type>test-jar</type>
             <scope>test</scope>
         </dependency>
 
         <dependency>
-            <groupId>org.testcontainers</groupId>
-            <artifactId>mongodb</artifactId>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-mongodb</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.mongodb</groupId>
+            <artifactId>mongodb-driver-legacy</artifactId>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBLocalContainerService.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBLocalContainerService.java
deleted file mode 100644
index 860859f..0000000
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBLocalContainerService.java
+++ /dev/null
@@ -1,56 +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.kafkaconnector.mongodb.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.MongoDBContainer;
-
-public class MongoDBLocalContainerService implements MongoDBService {
-    private static final Logger LOG = LoggerFactory.getLogger(MongoDBLocalContainerService.class);
-    private static final int DEFAULT_MONGODB_PORT = 27017;
-    private final MongoDBContainer container;
-
-    public MongoDBLocalContainerService() {
-        String containerName = System.getProperty("mongodb.container");
-
-        if (containerName == null || containerName.isEmpty()) {
-            container = new MongoDBContainer();
-        } else {
-            container = new MongoDBContainer(containerName);
-        }
-
-        container.start();
-    }
-
-    @Override
-    public String getReplicaSetUrl() {    
-        return "mongodb://" + container.getContainerIpAddress() + ":" + container.getMappedPort(DEFAULT_MONGODB_PORT);
-    }
-
-    @Override
-    public void initialize() {
-        LOG.info("MongoDB service running at {}", container.getReplicaSetUrl());
-    }
-
-    @Override
-    public void shutdown() {
-        LOG.info("Stopping the MongoDB container");
-        container.stop();
-    }
-}
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBService.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBService.java
deleted file mode 100644
index 4822b49..0000000
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBService.java
+++ /dev/null
@@ -1,46 +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.kafkaconnector.mongodb.services;
-
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-public interface MongoDBService extends BeforeAllCallback, AfterAllCallback {
-    /**
-     * Perform any initialization necessary
-     */
-    void initialize();
-
-    /**
-     * Shuts down the service after the test has completed
-     */
-    void shutdown();
-
-    String getReplicaSetUrl();
-
-    @Override
-    default void beforeAll(ExtensionContext extensionContext) throws Exception {
-        initialize();
-    }
-
-    @Override
-    default void afterAll(ExtensionContext extensionContext) throws Exception {
-        shutdown();
-    }
-}
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBServiceFactory.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBServiceFactory.java
deleted file mode 100644
index f59682d..0000000
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/MongoDBServiceFactory.java
+++ /dev/null
@@ -1,44 +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.kafkaconnector.mongodb.services;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class MongoDBServiceFactory {
-    private static final Logger LOG = LoggerFactory.getLogger(MongoDBServiceFactory.class);
-
-    private MongoDBServiceFactory() {
-
-    }
-
-    public static MongoDBService createService() {
-        String instanceType = System.getProperty("mongodb.instance.type");
-
-        if (instanceType == null || instanceType.equals("local-mongodb-container")) {
-            return new MongoDBLocalContainerService();
-        }
-
-        if (instanceType.equals("remote")) {
-            return new RemoteMongoDBService();
-        }
-
-        LOG.error("MongoDB instance must be one of 'local-mongodb-container' or 'remote");
-        throw new UnsupportedOperationException("Invalid MongoDB instance type");
-    }
-}
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/RemoteMongoDBService.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/RemoteMongoDBService.java
deleted file mode 100644
index 175b49c..0000000
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/services/RemoteMongoDBService.java
+++ /dev/null
@@ -1,35 +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.kafkaconnector.mongodb.services;
-
-public class RemoteMongoDBService implements MongoDBService {
-
-    public String getReplicaSetUrl() {
-        return System.getProperty("mongodb.url");
-    }
-
-    @Override
-    public void initialize() {
-        // NO-OP
-    }
-
-    @Override
-    public void shutdown() {
-        // NO-OP
-    }
-}
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/sink/CamelSinkMongoDBITCase.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/sink/CamelSinkMongoDBITCase.java
index e4874db..aaf17c1 100644
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/sink/CamelSinkMongoDBITCase.java
+++ b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/sink/CamelSinkMongoDBITCase.java
@@ -28,8 +28,8 @@ import org.apache.camel.kafkaconnector.common.BasicConnectorPropertyFactory;
 import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
 import org.apache.camel.kafkaconnector.common.clients.kafka.KafkaClient;
 import org.apache.camel.kafkaconnector.common.utils.TestUtils;
-import org.apache.camel.kafkaconnector.mongodb.services.MongoDBService;
-import org.apache.camel.kafkaconnector.mongodb.services.MongoDBServiceFactory;
+import org.apache.camel.test.infra.mongodb.services.MongoDBService;
+import org.apache.camel.test.infra.mongodb.services.MongoDBServiceFactory;
 import org.bson.Document;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -37,12 +37,10 @@ import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testcontainers.junit.jupiter.Testcontainers;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.fail;
 
-@Testcontainers
 public class CamelSinkMongoDBITCase extends AbstractKafkaTest {
     @RegisterExtension
     public static MongoDBService mongoDBService = MongoDBServiceFactory.createService();
diff --git a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/source/CamelSourceMongoDBITCase.java b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/source/CamelSourceMongoDBITCase.java
index 340b07e..791635a 100644
--- a/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/source/CamelSourceMongoDBITCase.java
+++ b/tests/itests-mongodb/src/test/java/org/apache/camel/kafkaconnector/mongodb/source/CamelSourceMongoDBITCase.java
@@ -31,8 +31,8 @@ import org.apache.camel.kafkaconnector.common.BasicConnectorPropertyFactory;
 import org.apache.camel.kafkaconnector.common.ConnectorPropertyFactory;
 import org.apache.camel.kafkaconnector.common.clients.kafka.KafkaClient;
 import org.apache.camel.kafkaconnector.common.utils.TestUtils;
-import org.apache.camel.kafkaconnector.mongodb.services.MongoDBService;
-import org.apache.camel.kafkaconnector.mongodb.services.MongoDBServiceFactory;
+import org.apache.camel.test.infra.mongodb.services.MongoDBService;
+import org.apache.camel.test.infra.mongodb.services.MongoDBServiceFactory;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.bson.Document;
 import org.junit.jupiter.api.BeforeEach;
@@ -41,11 +41,9 @@ import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testcontainers.junit.jupiter.Testcontainers;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-@Testcontainers
 public class CamelSourceMongoDBITCase extends AbstractKafkaTest {
     @RegisterExtension
     public static MongoDBService mongoDBService = MongoDBServiceFactory.createService();