Fix mongodb-consumer
Replace embedded MongoDB w/ MongoDB testcontainer
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
<artifactId>mongodb-driver-reactivestreams</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mongodb</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -33,17 +33,26 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@SpringBootTest(properties = {
|
||||
"mongodb.consumer.collection=testing",
|
||||
"spring.mongodb.embedded.version=3.5.5" })
|
||||
class MongoDbConsumerApplicationTests {
|
||||
"mongodb.consumer.collection=testing"
|
||||
})
|
||||
class MongoDbConsumerApplicationTests implements MongoDbTestContainerSupport {
|
||||
|
||||
@DynamicPropertySource
|
||||
static void mongoDbProperties(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.data.mongodb.uri", MongoDbTestContainerSupport::mongoDbUri);
|
||||
registry.add("spring.data.mongodb.database", () -> "test");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private MongoDbConsumerProperties properties;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2022-2022 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.cloud.fn.consumer.mongo;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.testcontainers.containers.MongoDBContainer;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
/**
|
||||
* Provides a static {@link MongoDBContainer} that can be shared across test classes.
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public interface MongoDbTestContainerSupport {
|
||||
|
||||
MongoDBContainer MONGO_CONTAINER = new MongoDBContainer("mongo:5.0.9");
|
||||
|
||||
@BeforeAll
|
||||
static void startContainer() {
|
||||
MONGO_CONTAINER.start();
|
||||
}
|
||||
|
||||
static String mongoDbUri() {
|
||||
return "mongodb://localhost:" + MONGO_CONTAINER.getFirstMappedPort();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
|
||||
<logger name="org.testcontainers" level="INFO"/>
|
||||
<logger name="com.github.dockerjava" level="WARN"/>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user