package demo;

import com.jayway.restassured.RestAssured;
import com.palantir.docker.compose.DockerComposeRule;
import com.palantir.docker.compose.connection.DockerPort;
import org.junit.*;

import java.util.function.Function;

import static com.jayway.restassured.RestAssured.get;
import static com.palantir.docker.compose.connection.waiting.HealthChecks.toRespondOverHttp;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;

public class IntegrationTest {

    private static final int INTERNAL_PORT = 8080;

    private static final Function<DockerPort, String> TO_EXTERNAL_URI =
            (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT");

    @Rule
    public DockerComposeRule docker = DockerComposeRule.builder()
            .file("../docker-compose.yml")
            .waitingForService("greeting-service", toRespondOverHttp(INTERNAL_PORT, TO_EXTERNAL_URI))
            .waitingForService("counter-service", toRespondOverHttp(INTERNAL_PORT, TO_EXTERNAL_URI))
            .waitingForService("master-service", toRespondOverHttp(INTERNAL_PORT, TO_EXTERNAL_URI))
            .saveLogsTo("build/docker-logs")
            .build();

    @Before
    public void setUp() throws Exception {
        docker.dockerCompose().up();

        DockerPort masterService = docker.containers().container("master-service").port(INTERNAL_PORT);
        RestAssured.baseURI = TO_EXTERNAL_URI.apply(masterService);
    }

    @After
    public void tearDown() throws Exception {
        docker.dockerCompose().down();
    }

    @Test
    public void shouldReturnData() throws Exception {
        get("/info")
            .then().assertThat()
            .body("counter", isA(Number.class))
            .body("greeting", is("Hello World"));
    }

    @Test
    public void shouldReturnDefaultGreetingWhenGreetingServiceDown() throws Exception {
        docker.dockerCompose().container("greeting-service").stop();

        get("/info")
            .then().assertThat()
            .body("greeting", is("Hola!"));
    }

    @Test
    public void shouldReturnDefaultCountWhenCounterServiceDown() throws Exception {
        docker.dockerCompose().container("counter-service").stop();

        get("/info")
            .then().assertThat()
            .body("counter", is(42));
    }
}

@@ -105,16 +105,73 @@
 seRule;%0A
+import com.palantir.docker.compose.connection.Container;%0A
 import c
@@ -1289,56 +1289,17 @@
     
-docker.dockerCompose().up();%0A%0A        DockerPort
+Container
  mas
@@ -1308,16 +1308,25 @@
 rService
+Container
  = docke
@@ -1371,28 +1371,8 @@
 ce%22)
-.port(INTERNAL_PORT)
 ;%0A  
@@ -1438,111 +1438,37 @@
 vice
-);%0A    %7D%0A%0A    @After%0A    public void tearDown() throws Exception %7B%0A        docker.dockerCompose().down(
+Container.port(INTERNAL_PORT)
 );%0A 

Remove unnecessary docker compose up/down from the before/after in test