Skip to content

Commit

Permalink
Move Spring Data REST's multi-store example to Testcontainers.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Aug 16, 2024
1 parent ad27b23 commit 3953888
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 11 additions & 4 deletions rest/multi-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- Testcontainers -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>4.16.2</version>
<scope>runtime</scope>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.utility.DockerImageName;

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

@TestConfiguration
static class Infrastructure {

@Bean
@ServiceConnection
MongoDBContainer mongoDBContainer() {
return new MongoDBContainer(DockerImageName.parse("mongodb/mongodb-community-server"));
}
}

@Test
public void useMultipleRepositories() {

Expand Down

0 comments on commit 3953888

Please sign in to comment.