...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Testcontainers @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @ContextConfiguration( initializers = DemoApplicationTests.Initializer.class, classes = DemoApplication.class) @TestPropertySource(locations = {"classpath:application_test.properties"}) class DemoApplicationTests { @Test void contextLoads() { } @Container public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:latest") .withDatabaseName("db_demo").withUsername("sa").withPassword("sa"); @Configuration static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { @Override public void initialize(ConfigurableApplicationContext configurableApplicationContext) { TestPropertyValues .of("spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(), "spring.datasource.username=" + postgreSQLContainer.getUsername(), "spring.datasource.password=" + postgreSQLContainer.getPassword()) .applyTo(configurableApplicationContext.getEnvironment()); } } } |
This example is available here (https://gerrit.nordix.org/c/local/onap/clamp-pilot/+/11966).