|
1 | 1 | package br.com.helpdev.atdd;
|
2 | 2 |
|
3 | 3 | import io.restassured.RestAssured;
|
| 4 | +import org.slf4j.LoggerFactory; |
4 | 5 | import org.testcontainers.containers.GenericContainer;
|
5 | 6 | import org.testcontainers.containers.MySQLContainer;
|
6 | 7 | import org.testcontainers.containers.Network;
|
| 8 | +import org.testcontainers.containers.output.Slf4jLogConsumer; |
7 | 9 | import org.testcontainers.containers.wait.strategy.Wait;
|
8 | 10 | import org.testcontainers.utility.MountableFile;
|
9 | 11 |
|
10 | 12 | abstract class AbstractContainerBaseTest {
|
11 | 13 |
|
12 | 14 | private static final GenericContainer<?> APP;
|
13 | 15 | private static final GenericContainer<?> FLYWAY;
|
14 |
| - private static final MySQLContainer<?> MY_SQL_CONTAINER; |
| 16 | + private static final GenericContainer<?> MY_SQL_CONTAINER; |
15 | 17 |
|
16 | 18 | static {
|
17 | 19 | final var network = Network.newNetwork();
|
18 | 20 |
|
19 |
| - MY_SQL_CONTAINER = (MySQLContainer) new MySQLContainer("mysql:5.7.22") |
| 21 | + MY_SQL_CONTAINER = new MySQLContainer<>("mysql:5.7.22") |
20 | 22 | .withNetwork(network)
|
21 | 23 | .withNetworkAliases("testdb");
|
22 | 24 |
|
23 |
| - FLYWAY = new GenericContainer("flyway/flyway") |
| 25 | + FLYWAY = new GenericContainer<>("flyway/flyway") |
24 | 26 | .dependsOn(MY_SQL_CONTAINER)
|
25 | 27 | .withNetwork(network)
|
26 |
| - .withCopyFileToContainer(MountableFile.forHostPath("../resources/flyway/db/"), "/flyway/sql") |
27 |
| - .withCommand("-url=jdbc:mysql://testdb -schemas=test -user=test -password=test -connectRetries=60 migrate") |
28 |
| - .waitingFor( |
29 |
| - Wait.forLogMessage("(?s).*No migration necessary(?s).*|(?s).*Successfully applied(?s).*", 1) |
30 |
| - ); |
| 28 | + .withCopyFileToContainer(MountableFile.forHostPath("../resources/flyway/db"), "/flyway/sql") |
| 29 | + .withCommand("-url=jdbc:mysql://testdb?useSSL=false -schemas=test -user=test -password=test -connectRetries=60 migrate") |
| 30 | + .waitingFor(Wait.forLogMessage("(?s).*No migration necessary(?s).*|(?s).*Successfully applied(?s).*", 1)) |
| 31 | + .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("FLYWAY"))); |
31 | 32 |
|
32 |
| - APP = new GenericContainer("app-test:integration") |
| 33 | + APP = new GenericContainer<>("app-test:integration") |
33 | 34 | .dependsOn(MY_SQL_CONTAINER, FLYWAY)
|
34 | 35 | .withNetwork(network)
|
35 | 36 | .withEnv("MYSQL_USER", "test")
|
36 | 37 | .withEnv("MYSQL_PASSWORD", "test")
|
37 | 38 | .withEnv("MYSQL_URL", "jdbc:mysql://testdb:" + MySQLContainer.MYSQL_PORT + "/test?autoReconnect=true&useSSL=false")
|
38 | 39 | .withExposedPorts(8080)
|
39 |
| - .waitingFor(Wait.forHttp("/health/ready") |
40 |
| - .forStatusCode(200)); |
| 40 | + .waitingFor(Wait.forHttp("/health/ready").forStatusCode(200)) |
| 41 | + .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("APP_CONTAINER"))); |
41 | 42 |
|
42 | 43 | MY_SQL_CONTAINER.start();
|
43 | 44 | FLYWAY.start();
|
|
0 commit comments