This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SpringBootTest | |
| class TestcontainersDemoApplicationTests { | |
| public static final String DATABASE_NAME = "/demo-application"; | |
| @Autowired | |
| private UserRepository userRepository; | |
| private static final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @DynamicPropertySource | |
| static void registerMongoProperties(DynamicPropertyRegistry registry) { | |
| registry.add("spring.data.mongodb.uri", () -> mongoDBContainer.getConnectionString() + DATABASE_NAME); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); | |
| mongoDBContainer.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class User { | |
| @Id | |
| private String id; | |
| private String name; | |
| private int age; | |
| public User(String name, int age) { | |
| this.name = name; | |
| this.age = age; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface UserRepository extends MongoRepository<User, String> { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependency> | |
| <groupId>org.springframework.boot</groupId> | |
| <artifactId>spring-boot-starter-data-mongodb</artifactId> | |
| </dependency> | |
| <!-- Needed to start the test container--> | |
| <dependency> | |
| <groupId>org.testcontainers</groupId> | |
| <artifactId>mongodb</artifactId> | |
| <version>1.17.6</version> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| "response": { | |
| "status": 200, | |
| "bodyFileName": "firstResponse.json", | |
| "headers": { | |
| "Content-Type": "application/json" | |
| } | |
| } | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "request": { | |
| "method": "GET", | |
| "url": "/api/first" | |
| }, | |
| "response": { | |
| "status": 200, | |
| "body": "Hello, Sourcelabs!" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WireMockServer wireMockServer = new WireMockServer(wireMockConfig().port(8089)); | |
| wireMockServer.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <dependency> | |
| <groupId>com.github.tomakehurst</groupId> | |
| <artifactId>wiremock</artifactId> | |
| <version>2.17.0</version> | |
| <scope>test</scope> | |
| </dependency> |