You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2022/11/14 13:35:28 UTC
[nifi] branch main updated: NIFI-10562 Moved MongoDB to testcontainers for integration-tests
This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 00da6d5ead NIFI-10562 Moved MongoDB to testcontainers for integration-tests
00da6d5ead is described below
commit 00da6d5ead7671543bb1583a39845ad683fda843
Author: Mike Thomsen <mt...@apache.org>
AuthorDate: Wed Nov 9 17:45:48 2022 -0500
NIFI-10562 Moved MongoDB to testcontainers for integration-tests
This closes #6642
Signed-off-by: David Handermann <ex...@apache.org>
---
.../nifi-mongodb-processors/pom.xml | 37 ++++++++++++++++++++++
.../processors/mongodb/GetMongoRecordIT.groovy | 9 ++++--
.../nifi/processors/mongodb/AbstractMongoIT.java | 32 +++++++++++++++++++
.../nifi/processors/mongodb/DeleteMongoIT.java | 2 +-
.../apache/nifi/processors/mongodb/GetMongoIT.java | 13 ++++----
.../processors/mongodb/MongoWriteTestBase.java | 7 ++--
.../apache/nifi/processors/mongodb/PutMongoIT.java | 4 +--
.../nifi/processors/mongodb/PutMongoRecordIT.java | 4 +--
.../processors/mongodb/RunMongoAggregationIT.java | 9 +++---
.../mongodb/gridfs/GridFSITTestBase.java | 8 ++---
.../nifi-mongodb-services/pom.xml | 37 ++++++++++++++++++++++
.../org/apache/nifi/mongodb/AbstractMongoIT.java | 32 +++++++++++++++++++
.../nifi/mongodb/MongoDBControllerServiceIT.java | 4 +--
.../nifi/mongodb/MongoDBLookupServiceIT.java | 4 +--
pom.xml | 6 ++++
15 files changed, 176 insertions(+), 32 deletions(-)
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/pom.xml b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/pom.xml
index 50a7af8a2e..378306cfbe 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/pom.xml
@@ -113,5 +113,42 @@
<version>${nifi.groovy.version}</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mongodb</artifactId>
+ </dependency>
</dependencies>
+
+ <profiles>
+ <profile>
+ <id>integration-tests</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <mongo.docker.string>mongo:5</mongo.docker.string>
+ </properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <mongo.docker.image>${mongo.docker.string}</mongo.docker.image>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy
index 510222b170..dd2027286e 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy
@@ -35,17 +35,20 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
+import org.testcontainers.containers.MongoDBContainer
+import org.testcontainers.junit.jupiter.Container
+import org.testcontainers.junit.jupiter.Testcontainers
+import org.testcontainers.utility.DockerImageName
import static groovy.json.JsonOutput.*
-class GetMongoRecordIT {
+class GetMongoRecordIT extends AbstractMongoIT {
TestRunner runner
MongoDBClientService service
static RecordSchema SCHEMA
static final String DB_NAME = GetMongoRecord.class.simpleName + Calendar.instance.timeInMillis
static final String COL_NAME = "test"
- static final String URI = "mongodb://localhost:27017"
static {
def fields = [
@@ -67,7 +70,7 @@ class GetMongoRecordIT {
runner = TestRunners.newTestRunner(GetMongoRecord.class)
service = new MongoDBControllerService()
runner.addControllerService("client", service)
- runner.setProperty(service, MongoDBControllerService.URI, URI)
+ runner.setProperty(service, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString())
runner.enableControllerService(service)
def writer = new JsonRecordSetWriter()
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoIT.java
new file mode 100644
index 0000000000..4eac6c3b0d
--- /dev/null
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoIT.java
@@ -0,0 +1,32 @@
+/*
+ * 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.nifi.processors.mongodb;
+
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+@Testcontainers
+public class AbstractMongoIT {
+ private static final String DOCKER_IMAGE = System.getProperty("mongo.docker.image");
+ @Container
+ protected static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse(DOCKER_IMAGE));
+}
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java
index 6cadcf65cb..ab79a599ee 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java
@@ -128,7 +128,7 @@ public class DeleteMongoIT extends MongoWriteTestBase {
runner.addControllerService("clientService", clientService);
runner.removeProperty(DeleteMongo.URI);
runner.setProperty(DeleteMongo.DELETE_MODE, DeleteMongo.DELETE_MANY);
- runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(DeleteMongo.CLIENT_SERVICE, "clientService");
runner.enableControllerService(clientService);
runner.assertValid();
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
index 6f5207c59f..de6c71d654 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java
@@ -55,8 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class GetMongoIT {
- private static final String MONGO_URI = "mongodb://localhost";
+public class GetMongoIT extends AbstractMongoIT {
private static final String DB_NAME = GetMongoIT.class.getSimpleName().toLowerCase();
private static final String COLLECTION_NAME = "test";
@@ -78,7 +77,7 @@ public class GetMongoIT {
@BeforeEach
public void setup() {
runner = TestRunners.newTestRunner(GetMongo.class);
- runner.setVariable("uri", MONGO_URI);
+ runner.setVariable("uri", MONGO_CONTAINER.getConnectionString());
runner.setVariable("db", DB_NAME);
runner.setVariable("collection", COLLECTION_NAME);
runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
@@ -87,7 +86,7 @@ public class GetMongoIT {
runner.setProperty(GetMongo.USE_PRETTY_PRINTING, GetMongo.YES_PP);
runner.setIncomingConnection(false);
- mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
+ mongoClient = new MongoClient(new MongoClientURI(MONGO_CONTAINER.getConnectionString()));
MongoCollection<Document> collection = mongoClient.getDatabase(DB_NAME).getCollection(COLLECTION_NAME);
collection.insertMany(DOCUMENTS);
@@ -120,7 +119,7 @@ public class GetMongoIT {
assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required"));
// missing query - is ok
- runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI);
+ runner.setProperty(AbstractMongoProcessor.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME);
runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME);
runner.enqueue(new byte[0]);
@@ -530,7 +529,7 @@ public class GetMongoIT {
for (Map.Entry<String, Map<String, String>> entry : vals.entrySet()) {
// Creating a new runner for each set of attributes map since every subsequent runs will attempt to take the top most enqueued FlowFile
tmpRunner = TestRunners.newTestRunner(GetMongo.class);
- tmpRunner.setProperty(AbstractMongoProcessor.URI, MONGO_URI);
+ tmpRunner.setProperty(AbstractMongoProcessor.URI, MONGO_CONTAINER.getConnectionString());
tmpRunner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME);
tmpRunner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME);
tmpRunner.setIncomingConnection(true);
@@ -592,7 +591,7 @@ public class GetMongoIT {
MongoDBClientService clientService = new MongoDBControllerService();
runner.addControllerService("clientService", clientService);
runner.removeProperty(GetMongo.URI);
- runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(GetMongo.CLIENT_SERVICE, "clientService");
runner.enableControllerService(clientService);
runner.assertValid();
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/MongoWriteTestBase.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/MongoWriteTestBase.java
index 814d78fd19..ce43966bec 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/MongoWriteTestBase.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/MongoWriteTestBase.java
@@ -27,8 +27,7 @@ import org.bson.Document;
import java.util.Arrays;
import java.util.List;
-public class MongoWriteTestBase {
- protected static final String MONGO_URI = "mongodb://localhost";
+public class MongoWriteTestBase extends AbstractMongoIT {
protected static final String COLLECTION_NAME = "test";
protected String DATABASE_NAME;
@@ -45,13 +44,13 @@ public class MongoWriteTestBase {
public void setup(Class processor) {
DATABASE_NAME = processor.getSimpleName().toLowerCase();
- mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
+ mongoClient = new MongoClient(new MongoClientURI(MONGO_CONTAINER.getConnectionString()));
collection = mongoClient.getDatabase(DATABASE_NAME).getCollection(COLLECTION_NAME);
}
public TestRunner init(Class processor) {
TestRunner runner = TestRunners.newTestRunner(processor);
- runner.setVariable("uri", MONGO_URI);
+ runner.setVariable("uri", MONGO_CONTAINER.getConnectionString());
runner.setVariable("db", DATABASE_NAME);
runner.setVariable("collection", COLLECTION_NAME);
runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java
index 93bda501c3..be0271fcd8 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java
@@ -78,7 +78,7 @@ public class PutMongoIT extends MongoWriteTestBase {
assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required"));
// invalid write concern
- runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI);
+ runner.setProperty(AbstractMongoProcessor.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DATABASE_NAME);
runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME);
runner.setProperty(PutMongo.WRITE_CONCERN, "xyz");
@@ -532,7 +532,7 @@ public class PutMongoIT extends MongoWriteTestBase {
TestRunner runner = init(PutMongo.class);
runner.addControllerService("clientService", clientService);
runner.removeProperty(PutMongo.URI);
- runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(PutMongo.CLIENT_SERVICE, "clientService");
runner.enableControllerService(clientService);
runner.assertValid();
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java
index a8fe7c85db..76e12791e3 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java
@@ -107,7 +107,7 @@ public class PutMongoRecordIT extends MongoWriteTestBase {
assertTrue(it.next().toString().contains("is invalid because Record Reader is required"));
// invalid write concern
- runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI);
+ runner.setProperty(AbstractMongoProcessor.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DATABASE_NAME);
runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME);
runner.setProperty(PutMongoRecord.RECORD_READER_FACTORY, "reader");
@@ -163,7 +163,7 @@ public class PutMongoRecordIT extends MongoWriteTestBase {
MongoDBClientService clientService = new MongoDBControllerService();
runner.addControllerService("clientService", clientService);
runner.removeProperty(PutMongoRecord.URI);
- runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(PutMongoRecord.CLIENT_SERVICE, "clientService");
runner.enableControllerService(clientService);
runner.assertValid();
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java
index 1050a466d8..979875f85b 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java
@@ -45,9 +45,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class RunMongoAggregationIT {
+public class RunMongoAggregationIT extends AbstractMongoIT {
- private static final String MONGO_URI = "mongodb://localhost";
private static final String DB_NAME = String.format("agg_test-%s", Calendar.getInstance().getTimeInMillis());
private static final String COLLECTION_NAME = "agg_test_data";
private static final String AGG_ATTR = "mongo.aggregation.query";
@@ -60,7 +59,7 @@ public class RunMongoAggregationIT {
@BeforeEach
public void setup() {
runner = TestRunners.newTestRunner(RunMongoAggregation.class);
- runner.setVariable("uri", MONGO_URI);
+ runner.setVariable("uri", MONGO_CONTAINER.getConnectionString());
runner.setVariable("db", DB_NAME);
runner.setVariable("collection", COLLECTION_NAME);
runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
@@ -68,7 +67,7 @@ public class RunMongoAggregationIT {
runner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, "${collection}");
runner.setProperty(RunMongoAggregation.QUERY_ATTRIBUTE, AGG_ATTR);
- mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
+ mongoClient = new MongoClient(new MongoClientURI(MONGO_CONTAINER.getConnectionString()));
MongoCollection<Document> collection = mongoClient.getDatabase(DB_NAME).getCollection(COLLECTION_NAME);
String[] values = new String[] { "a", "b", "c" };
@@ -224,7 +223,7 @@ public class RunMongoAggregationIT {
MongoDBClientService clientService = new MongoDBControllerService();
runner.addControllerService("clientService", clientService);
runner.removeProperty(RunMongoAggregation.URI);
- runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(RunMongoAggregation.CLIENT_SERVICE, "clientService");
runner.setProperty(RunMongoAggregation.QUERY, "[\n" +
" {\n" +
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/GridFSITTestBase.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/GridFSITTestBase.java
index 45e7cb244b..b91a3fc612 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/GridFSITTestBase.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/GridFSITTestBase.java
@@ -27,6 +27,7 @@ import com.mongodb.client.gridfs.model.GridFSFile;
import com.mongodb.client.gridfs.model.GridFSUploadOptions;
import org.apache.nifi.mongodb.MongoDBClientService;
import org.apache.nifi.mongodb.MongoDBControllerService;
+import org.apache.nifi.processors.mongodb.AbstractMongoIT;
import org.apache.nifi.util.TestRunner;
import org.bson.Document;
import org.bson.types.ObjectId;
@@ -34,8 +35,7 @@ import org.bson.types.ObjectId;
import java.io.ByteArrayInputStream;
import java.util.Map;
-public class GridFSITTestBase {
- static final String URI = "mongodb://localhost:27017";
+public class GridFSITTestBase extends AbstractMongoIT {
static final String DB = "gridfs_test_database";
MongoClient client;
@@ -47,7 +47,7 @@ public class GridFSITTestBase {
MongoDBClientService clientService = new MongoDBControllerService();
runner.addControllerService("clientService", clientService);
runner.setProperty(AbstractGridFSProcessor.CLIENT_SERVICE, "clientService");
- runner.setProperty(clientService, MongoDBControllerService.URI, URI);
+ runner.setProperty(clientService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(AbstractGridFSProcessor.BUCKET_NAME, bucketName);
runner.setProperty(AbstractGridFSProcessor.DATABASE_NAME, DB);
runner.enableControllerService(clientService);
@@ -56,7 +56,7 @@ public class GridFSITTestBase {
runner.assertValid();
}
- client = new MongoClient("localhost", 27017);
+ client = new MongoClient(MONGO_CONTAINER.getConnectionString());
}
public void tearDown() {
client.dropDatabase(DB);
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/pom.xml b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/pom.xml
index 304322fd77..c96cbc0be2 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/pom.xml
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/pom.xml
@@ -80,6 +80,16 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mongodb</artifactId>
+ </dependency>
+
</dependencies>
<build>
@@ -98,4 +108,31 @@
</plugin>
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <id>integration-tests</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <mongo.docker.string>mongo:5</mongo.docker.string>
+ </properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <mongo.docker.image>${mongo.docker.string}</mongo.docker.image>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/AbstractMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/AbstractMongoIT.java
new file mode 100644
index 0000000000..02eb4923df
--- /dev/null
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/AbstractMongoIT.java
@@ -0,0 +1,32 @@
+/*
+ * 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.nifi.mongodb;
+
+import org.testcontainers.containers.MongoDBContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+@Testcontainers
+public class AbstractMongoIT {
+ private static final String DOCKER_IMAGE = System.getProperty("mongo.docker.image");
+ @Container
+ protected static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse(DOCKER_IMAGE));
+}
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java
index d75ad01da6..c89844e845 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java
@@ -35,7 +35,7 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class MongoDBControllerServiceIT {
+public class MongoDBControllerServiceIT extends AbstractMongoIT {
private static final String IDENTIFIER = "Client Service";
@@ -47,7 +47,7 @@ public class MongoDBControllerServiceIT {
runner = TestRunners.newTestRunner(TestControllerServiceProcessor.class);
service = new MongoDBControllerService();
runner.addControllerService(IDENTIFIER, service);
- runner.setProperty(service, MongoDBControllerService.URI, "mongodb://localhost:27017");
+ runner.setProperty(service, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.enableControllerService(service);
}
diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java
index 2ab890d253..be21a6ab5d 100644
--- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java
+++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java
@@ -50,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
-public class MongoDBLookupServiceIT {
+public class MongoDBLookupServiceIT extends AbstractMongoIT {
private static final String DB_NAME = String.format("nifi_test-%d", Calendar.getInstance().getTimeInMillis());
private static final String COL_NAME = String.format("nifi_test-%d", Calendar.getInstance().getTimeInMillis());
@@ -70,7 +70,7 @@ public class MongoDBLookupServiceIT {
runner.setProperty(TestLookupServiceProcessor.CLIENT_SERVICE, "Client Service");
runner.setProperty(service, MongoDBLookupService.DATABASE_NAME, DB_NAME);
runner.setProperty(service, MongoDBLookupService.COLLECTION_NAME, COL_NAME);
- runner.setProperty(controllerService, MongoDBControllerService.URI, "mongodb://localhost:27017");
+ runner.setProperty(controllerService, MongoDBControllerService.URI, MONGO_CONTAINER.getConnectionString());
runner.setProperty(service, MongoDBLookupService.LOOKUP_VALUE_FIELD, "message");
runner.setProperty(service, MongoDBLookupService.CONTROLLER_SERVICE, "Client Service 2");
SchemaRegistry registry = new StubSchemaRegistry();
diff --git a/pom.xml b/pom.xml
index fda3b275b1..2abd9858bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -365,6 +365,12 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>mongodb</artifactId>
+ <version>${testcontainers.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>neo4j</artifactId>