Skip to content

Commit

Permalink
chore: clean codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Nov 13, 2021
1 parent 8747492 commit f843ba4
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
import org.testcontainers.containers.MongoDBContainer;

@Slf4j
class MongodbContainerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
var mongoDBContainer = new MongoDBContainer("mongo:4");
mongoDBContainer.start();
class MongodbContainerInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext> {

configurableApplicationContext
.addApplicationListener((ApplicationListener<ContextClosedEvent>) event -> mongoDBContainer.stop());
log.debug("mongoDBContainer.getReplicaSetUrl():" + mongoDBContainer.getReplicaSetUrl());
TestPropertyValues
.of("spring.data.mongodb.uri=mongodb://localhost:" + mongoDBContainer.getFirstMappedPort())
.applyTo(configurableApplicationContext.getEnvironment());
}
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
var mongoDBContainer = new MongoDBContainer("mongo:4");
mongoDBContainer.start();

configurableApplicationContext
.addApplicationListener(
(ApplicationListener<ContextClosedEvent>) event -> mongoDBContainer.stop());
log.debug("mongoDBContainer.getReplicaSetUrl():" + mongoDBContainer.getReplicaSetUrl());
TestPropertyValues
.of("spring.data.mongodb.uri=mongodb://localhost:" + mongoDBContainer.getFirstMappedPort()
+ "/blog")
.applyTo(configurableApplicationContext.getEnvironment());
}
}

0 comments on commit f843ba4

Please sign in to comment.