Skip to content

Commit ad27b23

Browse files
committed
Switch Multi-Store sample to Testcontainers.
1 parent dba65e8 commit ad27b23

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

multi-store/pom.xml

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030
<scope>test</scope>
3131
</dependency>
3232

33+
<!-- Testcontainers -->
34+
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-testcontainers</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.testcontainers</groupId>
43+
<artifactId>mongodb</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
3347
</dependencies>
3448

3549
</project>

multi-store/src/test/java/example/springdata/multistore/ApplicationConfigurationTest.java

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,34 +15,46 @@
1515
*/
1616
package example.springdata.multistore;
1717

18+
import static org.assertj.core.api.Assertions.*;
19+
1820
import example.springdata.multistore.customer.Customer;
1921
import example.springdata.multistore.shop.Order;
2022

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2324
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.boot.test.context.TestConfiguration;
27+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
2528
import org.springframework.context.ApplicationContext;
29+
import org.springframework.context.annotation.Bean;
2630
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
2731
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
2832
import org.springframework.data.repository.support.Repositories;
29-
import org.springframework.test.context.junit4.SpringRunner;
30-
31-
import static org.assertj.core.api.Assertions.assertThat;
33+
import org.testcontainers.containers.MongoDBContainer;
34+
import org.testcontainers.utility.DockerImageName;
3235

3336
/**
3437
* Integration test to check repository interfaces are assigned to the correct store modules.
3538
*
3639
* @author Oliver Gierke
3740
*/
38-
@RunWith(SpringRunner.class)
3941
@SpringBootTest
40-
public class ApplicationConfigurationTest {
42+
class ApplicationConfigurationTest {
4143

4244
@Autowired ApplicationContext context;
4345

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

4759
var repositories = new Repositories(context);
4860

multi-store/src/test/resources/logback.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
<appender-ref ref="console" />
1414
</root>
1515

16-
</configuration>
16+
</configuration>

rest/starbucks/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@
9393
<artifactId>webjars-locator-core</artifactId>
9494
<scope>runtime</scope>
9595
</dependency>
96-
96+
9797
<!-- Testcontainers -->
98+
9899
<dependency>
99100
<groupId>org.springframework.boot</groupId>
100101
<artifactId>spring-boot-testcontainers</artifactId>

0 commit comments

Comments
 (0)