Having a simple Spring boot app, with following integration test configuration:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(ResourceUtils.CLASSPATH_URL_PREFIX + "application-test.properties")
@AutoConfigureMockMvc
@DBRider
@DBUnit(caseInsensitiveStrategy = Orthography.LOWERCASE, qualifiedTableNames = true)
public abstract class AbstractIntegrationTest {
protected static final PostgreSQLContainer<?> POSTGRESQL_CONTAINER; // shared among all test classes
static {
POSTGRESQL_CONTAINER = new PostgreSQLContainer<>("postgres:9.5-alpine");
POSTGRESQL_CONTAINER.start();
}
@Autowired
protected MockMvc mockMvc;
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", POSTGRESQL_CONTAINER::getJdbcUrl);
registry.add("spring.datasource.username", POSTGRESQL_CONTAINER::getUsername);
registry.add("spring.datasource.password", POSTGRESQL_CONTAINER::getPassword);
}
@Test
void contextLoads() {
Assertions.assertThat(mockMvc).isNotNull();
Assertions.assertThat(POSTGRESQL_CONTAINER.isRunning()).isTrue();
}
}
public class UserControllerTest extends AbstractIntegrationTest {
@Test
@DataSet(value = {"/dbunit/users.yml"}, cleanBefore = true)
void getUserTest() throws Exception {
var resultActions = mockMvc.perform(get("/api/users/{id}", 1)
.accept(MediaType.APPLICATION_JSON))
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
}
// Other tests ommitted.
}
I get following warning messages:
WARN com.github.database.rider.core.dataset.DataSetExecutorImpl - Could not clear table user, message:Cannot commit when autoCommit is enabled., cause: null
The cause of the error is the fact that I specified dbunit should clean before.
I'm not sure what I should do to get rid of this warning and the funny thing is, the table is cleared, even though the warning says otherwise.