Slide 27
Slide 27 text
@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();
public static class Initializer implements ApplicationContextInitializer {
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
EnvironmentTestUtils.addEnvironment(configurableApplicationContext,
"spring.database.url=" + postgreSql.getJdbcUrl(),
"spring.database.username=" + postgreSql.getUsername(),
"spring.database.password=" + postgreSql.getPassword(),
"spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getMappedPort(6379),
"spring.redis.port=" + mockServer.getContainerIpAddress() + ":" + mockServer.getMappedPort(8080)
);
}
}
}
Still using all the
Spring goodies!