diff --git a/src/test/java/edu/stanford/protege/issues/service/GetGitHubIssuesRequestHandlerTest.java b/src/test/java/edu/stanford/protege/issues/service/GetGitHubIssuesRequestHandlerTest.java index b6f9b40..97bf5f6 100644 --- a/src/test/java/edu/stanford/protege/issues/service/GetGitHubIssuesRequestHandlerTest.java +++ b/src/test/java/edu/stanford/protege/issues/service/GetGitHubIssuesRequestHandlerTest.java @@ -8,6 +8,7 @@ import edu.stanford.protege.webprotege.ipc.WebProtegeHandler; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.semanticweb.owlapi.model.OWLEntity; import org.springframework.boot.test.context.SpringBootTest; @@ -19,6 +20,7 @@ import static org.mockito.Mockito.when; @SpringBootTest +@ExtendWith(MongoTestExtension.class) class GetGitHubIssuesRequestHandlerTest { private GetGitHubIssuesRequestHandler handler; diff --git a/src/test/java/edu/stanford/protege/issues/service/MongoTestExtension.java b/src/test/java/edu/stanford/protege/issues/service/MongoTestExtension.java index 789b161..6b588fe 100644 --- a/src/test/java/edu/stanford/protege/issues/service/MongoTestExtension.java +++ b/src/test/java/edu/stanford/protege/issues/service/MongoTestExtension.java @@ -3,8 +3,8 @@ import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.springframework.test.context.DynamicPropertySource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.MongoDBContainer; import org.testcontainers.utility.DockerImageName; @@ -15,6 +15,8 @@ */ public class MongoTestExtension implements BeforeAllCallback, AfterAllCallback { + private final Logger logger = LoggerFactory.getLogger(MongoTestExtension.class); + protected static final int MONGODB_PORT = 27017; private MongoDBContainer container; @@ -25,12 +27,8 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception { container = new MongoDBContainer(imageName) .withExposedPorts(MONGODB_PORT); container.start(); - } - - @DynamicPropertySource - public void setProperties(DynamicPropertyRegistry registry) { - registry.add("spring.data.mongodb.host", () -> "localhost"); - registry.add("spring.data.mongodb.port", () -> container.getMappedPort(MONGODB_PORT)); + logger.info("Started Mongo on port {}", container.getMappedPort(MONGODB_PORT)); + System.setProperty("spring.data.mongodb.port", Integer.toString(container.getMappedPort(MONGODB_PORT))); } @Override