Skip to content

Commit

Permalink
Switch Multi-Store sample to Testcontainers.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Aug 16, 2024
1 parent dba65e8 commit ad27b23
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
14 changes: 14 additions & 0 deletions multi-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@
<scope>test</scope>
</dependency>

<!-- Testcontainers -->

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

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,34 +15,46 @@
*/
package example.springdata.multistore;

import static org.assertj.core.api.Assertions.*;

import example.springdata.multistore.customer.Customer;
import example.springdata.multistore.shop.Order;

import org.junit.Test;
import org.junit.runner.RunWith;
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.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.repository.support.Repositories;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.utility.DockerImageName;

/**
* Integration test to check repository interfaces are assigned to the correct store modules.
*
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationConfigurationTest {
class ApplicationConfigurationTest {

@Autowired ApplicationContext context;

@TestConfiguration
static class Infrastructure {

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

@Test
public void repositoriesAreAssignedToAppropriateStores() {
void repositoriesAreAssignedToAppropriateStores() {

var repositories = new Repositories(context);

Expand Down
2 changes: 1 addition & 1 deletion multi-store/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<appender-ref ref="console" />
</root>

</configuration>
</configuration>
3 changes: 2 additions & 1 deletion rest/starbucks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@
<artifactId>webjars-locator-core</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Testcontainers -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
Expand Down

0 comments on commit ad27b23

Please sign in to comment.