Skip to content

Commit f183c92

Browse files
author
akuksin
committed
refactoring
1 parent 51be895 commit f183c92

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spring-boot/testcontainers/src/test/java/de/kuksin/testcontainers/AbstractIntegrationTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.kuksin.testcontainers;
22

3+
import org.jetbrains.annotations.NotNull;
34
import org.springframework.context.ApplicationContextInitializer;
45
import org.springframework.context.ConfigurableApplicationContext;
56
import org.springframework.core.env.ConfigurableEnvironment;
@@ -19,10 +20,13 @@ static class Initializer
1920

2021
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>();
2122

22-
public static Map<String, String> getProperties() {
23+
private static void startContainers() {
2324
Startables.deepStart(Stream.of(postgres)).join();
2425
// we can add further containers here like rabbitmq or other database
26+
}
2527

28+
@NotNull
29+
private static Map<String, String> createConnectionConfiguration() {
2630
return Map.of(
2731
"spring.datasource.url", postgres.getJdbcUrl(),
2832
"spring.datasource.username", postgres.getUsername(),
@@ -33,10 +37,11 @@ public static Map<String, String> getProperties() {
3337

3438
@Override
3539
public void initialize(ConfigurableApplicationContext applicationContext) {
40+
startContainers();
3641
ConfigurableEnvironment environment = applicationContext.getEnvironment();
3742
MapPropertySource testcontainers = new MapPropertySource(
3843
"testcontainers",
39-
(Map) getProperties()
44+
(Map) createConnectionConfiguration()
4045
);
4146
environment.getPropertySources().addFirst(testcontainers);
4247
}

0 commit comments

Comments
 (0)