From 3953888426c5df7d95e6075bbc2a3e7a1e0de1fc Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 16 Aug 2024 13:01:35 +0200 Subject: [PATCH] Move Spring Data REST's multi-store example to Testcontainers. --- rest/multi-store/pom.xml | 15 +++++++++++---- .../multistore/ApplicationIntegrationTests.java | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/rest/multi-store/pom.xml b/rest/multi-store/pom.xml index b8dc70cfb..8163f5671 100644 --- a/rest/multi-store/pom.xml +++ b/rest/multi-store/pom.xml @@ -33,11 +33,18 @@ spring-boot-starter-data-mongodb + + + + org.springframework.boot + spring-boot-testcontainers + test + + - de.flapdoodle.embed - de.flapdoodle.embed.mongo - 4.16.2 - runtime + org.testcontainers + mongodb + test diff --git a/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java b/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java index 2c3e442e6..3c7363a67 100644 --- a/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java +++ b/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java @@ -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. @@ -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() {