1 |
|
package org.europa.together; |
2 |
|
|
3 |
|
import com.github.dockerjava.api.model.ExposedPort; |
4 |
|
import com.github.dockerjava.api.model.HostConfig; |
5 |
|
import com.github.dockerjava.api.model.PortBinding; |
6 |
|
import com.github.dockerjava.api.model.Ports; |
7 |
|
import java.sql.SQLException; |
8 |
|
import org.europa.together.application.JdbcActions; |
9 |
|
import org.europa.together.application.LogbackLogger; |
10 |
|
import org.europa.together.business.DatabaseActions; |
11 |
|
import org.europa.together.business.Logger; |
12 |
|
import org.europa.together.domain.LogLevel; |
13 |
|
import org.junit.ClassRule; |
14 |
|
import org.junit.jupiter.api.extension.BeforeAllCallback; |
15 |
|
import org.junit.jupiter.api.extension.ExtensionContext; |
16 |
|
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL; |
17 |
|
import org.testcontainers.containers.PostgreSQLContainer; |
18 |
|
import org.testcontainers.utility.DockerImageName; |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
|
|
| 95.2% |
Uncovered Elements: 1 (21) |
Complexity: 5 |
Complexity Density: 0.31 |
|
25 |
|
public class JUnit5Preperator implements BeforeAllCallback, ExtensionContext.Store.CloseableResource { |
26 |
|
|
27 |
|
private static final Logger LOGGER = new LogbackLogger(JUnit5Preperator.class); |
28 |
|
private static boolean started = false; |
29 |
|
|
30 |
|
@ClassRule |
31 |
|
private PostgreSQLContainer<?> postgreSQLContainer; |
32 |
|
|
33 |
|
public static final String JDBC_CONNECTION_STRING = "jdbc:tc:postgresql:14:///together-test"; |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
35 |
38 |
public JUnit5Preperator() {... |
36 |
38 |
int containerPort = 5432; |
37 |
38 |
int localPort = 5432; |
38 |
38 |
postgreSQLContainer |
39 |
|
= new PostgreSQLContainer<>(DockerImageName.parse("postgres:14")) |
40 |
|
.withExposedPorts(containerPort) |
41 |
|
.withDatabaseName("together-test") |
42 |
|
.withUsername("together") |
43 |
|
.withPassword("together") |
44 |
|
.withCreateContainerCmdModifier(cmd |
45 |
|
-> cmd.withHostConfig( |
46 |
|
new HostConfig().withPortBindings( |
47 |
|
new PortBinding(Ports.Binding.bindPort(localPort), |
48 |
|
new ExposedPort(containerPort)) |
49 |
|
) |
50 |
|
)); |
51 |
|
} |
52 |
|
|
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
53 |
38 |
@Override... |
54 |
|
public void beforeAll(ExtensionContext context) throws InterruptedException { |
55 |
|
|
56 |
38 |
if (!started) { |
57 |
1 |
LOGGER.log("TEST ENVIRONMENT will be prepared.", LogLevel.DEBUG); |
58 |
|
|
59 |
1 |
postgreSQLContainer.start(); |
60 |
|
|
61 |
1 |
DatabaseActions jdbcConection = new JdbcActions(); |
62 |
1 |
try { |
63 |
1 |
jdbcConection.connect("test"); |
64 |
1 |
LOGGER.log("JDBC: " + jdbcConection.getJdbcMetaData().toString(), LogLevel.DEBUG); |
65 |
|
|
66 |
1 |
started = true; |
67 |
1 |
context.getRoot().getStore(GLOBAL).put("TogetherPlatform", this); |
68 |
|
|
69 |
|
} catch (SQLException ex) { |
70 |
0 |
LOGGER.catchException(ex); |
71 |
|
} |
72 |
1 |
LOGGER.log("TEST ENVIRONMENT prepared...\n\n", LogLevel.DEBUG); |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
76 |
1 |
@Override... |
77 |
|
public void close() { |
78 |
1 |
LOGGER.log("TEST ENVIRONMENT will be shut down.", LogLevel.DEBUG); |
79 |
|
|
80 |
1 |
postgreSQLContainer.stop(); |
81 |
|
} |
82 |
|
|
83 |
|
} |