Skip to content

Commit 3953888

Browse files
committed
Move Spring Data REST's multi-store example to Testcontainers.
1 parent ad27b23 commit 3953888

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

rest/multi-store/pom.xml

+11-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@
3333
<artifactId>spring-boot-starter-data-mongodb</artifactId>
3434
</dependency>
3535

36+
<!-- Testcontainers -->
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-testcontainers</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
3644
<dependency>
37-
<groupId>de.flapdoodle.embed</groupId>
38-
<artifactId>de.flapdoodle.embed.mongo</artifactId>
39-
<version>4.16.2</version>
40-
<scope>runtime</scope>
45+
<groupId>org.testcontainers</groupId>
46+
<artifactId>mongodb</artifactId>
47+
<scope>test</scope>
4148
</dependency>
4249

4350
</dependencies>

rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
import org.junit.jupiter.api.Test;
2525
import org.springframework.beans.factory.annotation.Autowired;
2626
import org.springframework.boot.test.context.SpringBootTest;
27+
import org.springframework.boot.test.context.TestConfiguration;
28+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
29+
import org.springframework.context.annotation.Bean;
30+
import org.testcontainers.containers.MongoDBContainer;
31+
import org.testcontainers.utility.DockerImageName;
2732

2833
/**
2934
* Integration test to show the usage of repositories backed by different stores.
@@ -37,6 +42,16 @@ public class ApplicationIntegrationTests {
3742
@Autowired PersonRepository personRepository;
3843
@Autowired TreasureRepository treasureRepository;
3944

45+
@TestConfiguration
46+
static class Infrastructure {
47+
48+
@Bean
49+
@ServiceConnection
50+
MongoDBContainer mongoDBContainer() {
51+
return new MongoDBContainer(DockerImageName.parse("mongodb/mongodb-community-server"));
52+
}
53+
}
54+
4055
@Test
4156
public void useMultipleRepositories() {
4257

0 commit comments

Comments
 (0)