diff --git a/common/mongodb-common/pom.xml b/common/mongodb-common/pom.xml new file mode 100644 index 00000000..1eaeb2c3 --- /dev/null +++ b/common/mongodb-common/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + org.springframework.cloud.fn + spring-functions-parent + 4.0.0-SNAPSHOT + ../../spring-functions-parent/pom.xml + + + mongodb-common + mongodb-common + MongoDB Common + + + + org.testcontainers + mongodb + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + Jar Tests Package + package + + test-jar + + + + + + + diff --git a/common/mongodb-common/src/main/resources/application.properties b/common/mongodb-common/src/main/resources/application.properties new file mode 100644 index 00000000..1bb8bf6d --- /dev/null +++ b/common/mongodb-common/src/main/resources/application.properties @@ -0,0 +1 @@ +# empty diff --git a/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbTestContainerSupport.java b/common/mongodb-common/src/test/java/org/springframework/cloud/fn/common/mongo/MongoDbTestContainerSupport.java similarity index 95% rename from consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbTestContainerSupport.java rename to common/mongodb-common/src/test/java/org/springframework/cloud/fn/common/mongo/MongoDbTestContainerSupport.java index 5c0a8570..7e332b40 100644 --- a/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbTestContainerSupport.java +++ b/common/mongodb-common/src/test/java/org/springframework/cloud/fn/common/mongo/MongoDbTestContainerSupport.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.cloud.fn.consumer.mongo; +package org.springframework.cloud.fn.common.mongo; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.containers.MongoDBContainer; diff --git a/common/pom.xml b/common/pom.xml index c3f4a275..171739f4 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -17,6 +17,7 @@ ftp-common function-test-support metadata-store-common + mongodb-common mqtt-common redis-common tcp-common diff --git a/consumer/mongodb-consumer/pom.xml b/consumer/mongodb-consumer/pom.xml index fe1ef617..444f67ff 100644 --- a/consumer/mongodb-consumer/pom.xml +++ b/consumer/mongodb-consumer/pom.xml @@ -23,11 +23,18 @@ org.mongodb mongodb-driver-reactivestreams - - org.testcontainers - mongodb - test - + + org.testcontainers + mongodb + test + + + org.springframework.cloud.fn + mongodb-common + 4.0.0-SNAPSHOT + test-jar + test + diff --git a/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbConsumerApplicationTests.java b/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbConsumerApplicationTests.java index 4f633e0a..60f8580c 100644 --- a/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbConsumerApplicationTests.java +++ b/consumer/mongodb-consumer/src/test/java/org/springframework/cloud/fn/consumer/mongo/MongoDbConsumerApplicationTests.java @@ -30,6 +30,7 @@ import reactor.test.StepVerifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.fn.common.mongo.MongoDbTestContainerSupport; import org.springframework.data.mongodb.core.ReactiveMongoTemplate; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; diff --git a/supplier/mongodb-supplier/pom.xml b/supplier/mongodb-supplier/pom.xml index 30bff1d8..4d5a4ff7 100644 --- a/supplier/mongodb-supplier/pom.xml +++ b/supplier/mongodb-supplier/pom.xml @@ -33,11 +33,18 @@ splitter-function ${project.version} - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - test - + + org.testcontainers + mongodb + test + + + org.springframework.cloud.fn + mongodb-common + 4.0.0-SNAPSHOT + test-jar + test + diff --git a/supplier/mongodb-supplier/src/test/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierApplicationTests.java b/supplier/mongodb-supplier/src/test/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierApplicationTests.java index e4031719..9137cfbd 100644 --- a/supplier/mongodb-supplier/src/test/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierApplicationTests.java +++ b/supplier/mongodb-supplier/src/test/java/org/springframework/cloud/fn/supplier/mongo/MongodbSupplierApplicationTests.java @@ -33,7 +33,10 @@ import reactor.test.StepVerifier; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.fn.common.mongo.MongoDbTestContainerSupport; import org.springframework.messaging.Message; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -41,10 +44,15 @@ import static org.assertj.core.api.Assertions.entry; @SpringBootTest(properties = { "mongodb.supplier.collection=testing", "mongodb.supplier.query={ name: { $exists: true }}", - "mongodb.supplier.update-expression='{ $unset: { name: 0 } }'", - "spring.mongodb.embedded.version=3.5.5" + "mongodb.supplier.update-expression='{ $unset: { name: 0 } }'" }) -class MongodbSupplierApplicationTests { +class MongodbSupplierApplicationTests implements MongoDbTestContainerSupport { + + @DynamicPropertySource + static void mongoDbProperties(DynamicPropertyRegistry registry) { + registry.add("spring.data.mongodb.uri", MongoDbTestContainerSupport::mongoDbUri); + registry.add("spring.data.mongodb.database", () -> "test"); + } private ObjectMapper objectMapper = new ObjectMapper();