3
3
import org .springframework .boot .test .context .TestConfiguration ;
4
4
import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
5
5
import org .springframework .context .annotation .Bean ;
6
+ import org .springframework .test .context .DynamicPropertyRegistrar ;
6
7
import org .springframework .test .context .DynamicPropertyRegistry ;
7
8
import org .testcontainers .containers .GenericContainer ;
8
9
import org .testcontainers .containers .PostgreSQLContainer ;
12
13
@ TestConfiguration (proxyBeanMethods = false )
13
14
public class TestcontainersConfig {
14
15
16
+ @ Bean
17
+ public DynamicPropertyRegistrar propertiesOverride (GenericContainer wiremockContainer ) {
18
+ return (registry ) ->
19
+ registry .add ("http.exchange-client.url" , () -> httpUrl (wiremockContainer , 8080 ));
20
+
21
+ }
22
+
15
23
@ Bean
16
24
@ ServiceConnection
17
25
public PostgreSQLContainer postgreSQLContainer () {
@@ -23,22 +31,21 @@ public PostgreSQLContainer postgreSQLContainer() {
23
31
}
24
32
25
33
@ Bean
26
- public GenericContainer wiremockContainer (DynamicPropertyRegistry registry ) {
27
- var container = new GenericContainer ("wiremock/wiremock:3.0.0-1" )
34
+ public GenericContainer wiremockContainer () {
35
+ return new GenericContainer ("wiremock/wiremock:3.0.0-1" )
28
36
.withExposedPorts (8080 )
29
37
.withCopyFileToContainer (MountableFile .forClasspathResource ("stubs" ), "/home/wiremock" )
30
38
.waitingFor (Wait
31
39
.forHttp ("/__admin/mappings" )
32
40
.withMethod ("GET" )
33
41
.forStatusCode (200 ));
34
-
35
-
36
- registry .add ("http.exchange-client.url" , () -> httpUrl (container .getHost (), container .getMappedPort (8080 )));
37
-
38
- return container ;
39
42
}
40
43
41
44
private static String httpUrl (String host , Integer port ) {
42
45
return String .format ("http://%s:%d" , host , port );
43
46
}
47
+
48
+ private static String httpUrl (GenericContainer container , Integer originalPort ) {
49
+ return httpUrl (container .getHost (), container .getMappedPort (originalPort ));
50
+ }
44
51
}
0 commit comments