Skip to content

Instantly share code, notes, and snippets.

@wkorando

wkorando/ITStormRepo.java

Last active Mar 27, 2019
Embed
What would you like to do?
@SpringJUnitConfig
@ContextConfiguration(classes = { StormTrackerApplication.class }, initializers = ITStormRepo.Initializer.class)
@TestPropertySource("classpath:application.properties")
@TestMethodOrder(OrderAnnotation.class)
public class ITStormRepo {
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of("spring.datasource.url=jdbc:tc:postgresql:11.2://arbitrary/arbitrary", //
"spring.datasource.username=test", //
"spring.datasource.password=test", //
"spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver")//
.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