Skip to content

Commit

Permalink
Fix for some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed May 15, 2024
1 parent 0c00c10 commit 2d4b09e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,7 @@
import static org.mockito.Mockito.when;

@SpringBootTest
@ExtendWith(MongoTestExtension.class)
class GetGitHubIssuesRequestHandlerTest {

private GetGitHubIssuesRequestHandler handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 2d4b09e

Please sign in to comment.