|
4 | 4 | import org.apache.http.client.HttpClient;
|
5 | 5 | import org.apache.http.client.methods.HttpGet;
|
6 | 6 | import org.apache.http.impl.client.HttpClientBuilder;
|
7 |
| -import org.junit.jupiter.api.BeforeEach; |
8 | 7 | import org.junit.jupiter.api.Test;
|
9 |
| -import org.testcontainers.containers.DockerComposeContainer; |
| 8 | +import org.testcontainers.containers.ComposeContainer; |
10 | 9 | import org.testcontainers.containers.wait.strategy.Wait;
|
11 | 10 |
|
12 | 11 | import java.io.File;
|
|
17 | 16 | class ComposeContainerTests {
|
18 | 17 |
|
19 | 18 | @Container
|
20 |
| - private DockerComposeContainer composeContainer = new DockerComposeContainer( |
21 |
| - new File("src/test/resources/docker-compose.yml") |
22 |
| - ) |
23 |
| - .withExposedService("whoami_1", 80, Wait.forHttp("/")); |
24 |
| - |
25 |
| - private String host; |
26 |
| - |
27 |
| - private int port; |
28 |
| - |
29 |
| - @BeforeEach |
30 |
| - void setup() { |
31 |
| - host = composeContainer.getServiceHost("whoami_1", 80); |
32 |
| - port = composeContainer.getServicePort("whoami_1", 80); |
33 |
| - } |
| 19 | + private ComposeContainer composeContainer = new ComposeContainer(new File("src/test/resources/docker-compose.yml")) |
| 20 | + .withExposedService("whoami-1", 80, Wait.forHttp("/")); |
34 | 21 |
|
35 | 22 | @Test
|
36 | 23 | void running_compose_defined_container_is_accessible_on_configured_port() throws Exception {
|
37 | 24 | HttpClient client = HttpClientBuilder.create().build();
|
38 | 25 |
|
| 26 | + String host = composeContainer.getServiceHost("whoami-1", 80); |
| 27 | + int port = composeContainer.getServicePort("whoami-1", 80); |
| 28 | + |
39 | 29 | HttpResponse response = client.execute(new HttpGet("http://" + host + ":" + port));
|
40 | 30 |
|
41 | 31 | assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
|
|
0 commit comments