25. How does it work?
https://github.com/docker-java/docker-java
Docker environment discovery
Will start docker machine if it’s not started yet
Containers cleanup on JVM shutdown
30. @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class)
public abstract class AbstractIntegrationTest {
@ClassRule
public static PostgreSQLContainer postgreSql = new PostgreSQLContainer();
@ClassRule
public static GenericContainer redis = new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
@ClassRule
public static MockServerContainer mockServer = new MockServerContainer();
31. @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class)
public abstract class AbstractIntegrationTest {
@ClassRule
public static PostgreSQLContainer postgreSql = new PostgreSQLContainer();
@ClassRule
public static GenericContainer redis = new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
@ClassRule
public static MockServerContainer mockServer = new MockServerContainer();
Still using all the
Spring goodies!
32. @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class,
webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class)
public abstract class AbstractIntegrationTest {
@ClassRule
public static PostgreSQLContainer postgreSql = new PostgreSQLContainer();
@ClassRule
public static GenericContainer redis = new GenericContainer("redis:3.0.6")
.withExposedPorts(6379);
@ClassRule
public static MockServerContainer mockServer = new MockServerContainer();
External
dependencies
33.
34. public class MockServerContainer<SELF extends MockServerContainer<SELF>>
extends GenericContainer<SELF> {
public MockServerContainer() {
super("jamesdbloom/mockserver:latest");
addExposedPorts(8080);
}
private MockServerClient client;
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
super.containerIsStarted(containerInfo);
client = new MockServerClient(getContainerIpAddress(),
getMappedPort(getExposedPorts().get(0)));
}
}
35. public class MockServerContainer<SELF extends MockServerContainer<SELF>>
extends GenericContainer<SELF> {
public MockServerContainer() {
super("jamesdbloom/mockserver:latest");
addExposedPorts(8080);
}
private MockServerClient client;
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
super.containerIsStarted(containerInfo);
client = new MockServerClient(getContainerIpAddress(),
getMappedPort(getExposedPorts().get(0)));
}
}