Skip to content

Commit 734b6a2

Browse files
committed
GH-1327 - Make sure all MongoDB-related integration tests use Docker image.
1 parent fc79174 commit 734b6a2

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

spring-modulith-events/spring-modulith-events-mongodb/src/test/java/org/springframework/modulith/events/mongodb/MongoDbEventPublicationRepositoryTest.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,17 @@
3232
import org.junit.jupiter.api.Test;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
35-
import org.springframework.boot.test.context.TestConfiguration;
36-
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
37-
import org.springframework.context.annotation.Bean;
3835
import org.springframework.context.annotation.Import;
3936
import org.springframework.core.env.Environment;
4037
import org.springframework.data.mongodb.core.MongoTemplate;
4138
import org.springframework.modulith.events.core.PublicationTargetIdentifier;
4239
import org.springframework.modulith.events.core.TargetEventPublication;
4340
import org.springframework.modulith.events.support.CompletionMode;
41+
import org.springframework.modulith.testapp.Infrastructure;
4442
import org.springframework.modulith.testapp.TestApplication;
4543
import org.springframework.test.context.ContextConfiguration;
4644
import org.springframework.test.context.TestPropertySource;
47-
import org.testcontainers.containers.MongoDBContainer;
4845
import org.testcontainers.junit.jupiter.Testcontainers;
49-
import org.testcontainers.utility.DockerImageName;
5046

5147
/**
5248
* @author Björn Kieling
@@ -58,16 +54,6 @@ class MongoDbEventPublicationRepositoryTest {
5854

5955
private static final PublicationTargetIdentifier TARGET_IDENTIFIER = PublicationTargetIdentifier.of("listener");
6056

61-
@TestConfiguration(proxyBeanMethods = false)
62-
static class Infrastructure {
63-
64-
@Bean
65-
@ServiceConnection
66-
MongoDBContainer mongoDBContainer() {
67-
return new MongoDBContainer(DockerImageName.parse("mongo:latest"));
68-
}
69-
}
70-
7157
@DataMongoTest
7258
@Import(Infrastructure.class)
7359
@ContextConfiguration(classes = TestApplication.class)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.modulith.testapp;
17+
18+
import org.springframework.boot.test.context.TestConfiguration;
19+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
20+
import org.springframework.context.annotation.Bean;
21+
import org.testcontainers.containers.MongoDBContainer;
22+
import org.testcontainers.utility.DockerImageName;
23+
24+
@TestConfiguration(proxyBeanMethods = false)
25+
public class Infrastructure {
26+
27+
@Bean
28+
@ServiceConnection
29+
MongoDBContainer mongoDBContainer() {
30+
return new MongoDBContainer(DockerImageName.parse("mongo:latest"));
31+
}
32+
}

spring-modulith-events/spring-modulith-events-mongodb/src/test/java/org/springframework/modulith/testapp/TestApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
package org.springframework.modulith.testapp;
1717

1818
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import org.springframework.context.annotation.Import;
1920

2021
/**
2122
* @author Dmitry Belyaev
2223
* @author Björn Kieling
2324
*/
2425
@SpringBootApplication
25-
public class TestApplication {
26-
}
26+
@Import(Infrastructure.class)
27+
public class TestApplication {}

0 commit comments

Comments
 (0)