Slide 59
Slide 59 text
Compose fixture
@Testcontainers
public class ToDoAppImplIntegrationTest {
private static final Logger logger = LoggerFactory.getLogger(ToDoAppImplIntegrationTest.class);
private final static String WEB_SERVICE_NAME = "webservice_1";
private final static int WEB_SERVICE_PORT = 8080;
private final static String DATABASE_NAME = "database_1";
private final static int DATABASE_PORT = 5432;
@Container
public static DockerComposeContainer environment = createComposeContainer();
private static DockerComposeContainer createComposeContainer() {
return new DockerComposeContainer(new File("src/integrationTest/resources/compose-test.yml"))
.withLogConsumer(WEB_SERVICE_NAME, new Slf4jLogConsumer(logger))
.withExposedService(WEB_SERVICE_NAME, WEB_SERVICE_PORT,
Wait.forHttp("/actuator/health")
.forStatusCode(200))
.withExposedService(DATABASE_NAME, DATABASE_PORT,
Wait.forLogMessage(".*database system is ready to accept connections.*\\s", 2));
}
}
Create Compose container