Last active
March 27, 2019 10:29
-
-
Save wkorando/2b9a1490a24735ba4f6bfc114f5d8991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Testcontainers | |
@SpringJUnitConfig | |
@ContextConfiguration(classes = { | |
StormTrackerApplication.class }, initializers = ITStormRepoAlternate.Initializer.class) | |
@TestPropertySource("classpath:application.properties") | |
@TestMethodOrder(OrderAnnotation.class) | |
public class ITStormRepoAlternate { | |
@Container | |
private static PostgreSQLContainer container = new PostgreSQLContainer("postgres:11.2");//Can be an arbitrary image name and tag | |
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
@Override | |
public void initialize(ConfigurableApplicationContext applicationContext) { | |
TestPropertyValues.of("spring.datasource.url=" + container.getJdbcUrl(), | |
"spring.datasource.username=" + container.getUsername(), | |
"spring.datasource.password=" + container.getPassword(), | |
.applyTo(applicationContext); | |
} | |
} | |
@Autowired | |
private StormRepo repo; | |
@Test | |
@Order(1) | |
public void testReadFromStormsTable() { | |
assertThat(repo.count()).isEqualTo(2); | |
} | |
@Test | |
public void testWriteToStormsTable() { | |
Storm savedStorm = repo.save(new Storm("03-17-2019", "03-20-2019", "South Atlantic", "Knoxville, Tennesee", | |
"Tropical Depression", 3)); | |
assertThat(savedStorm.getId()).isEqualTo(12); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment