I am having trouble using the @ExpectedDatabase
annotation from springtestdbunit:
@SpringBootTest
@Transactional
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.H2)
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
TransactionDbUnitTestExecutionListener.class
})
@AutoConfigureMockMvc
class GroupControllerIntegrationTest {
@Autowired private MockMvc mvc;
@PersistenceContext private EntityManager entityManager;
@Test
@DatabaseSetup(value = "/createTwoGroups.xml")
@ExpectedDatabase(value = "/createSingleGroup.xml", table = "groups")
void givenGroups_deleteById_assert() throws Exception {
mvc.perform(delete("/groups/{id}", 1L))
.andDo(print())
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("/groups"))
.andExpect(model().hasNoErrors())
.andExpect(flash().attribute("message", "Gruppe erfolgreich gelöscht."));
// TODO: not working
// necessary due to:
// https://github.com/springtestdbunit/spring-test-dbunit/issues/75
entityManager.flush();
}
}
I receive
java.lang.Exception: org.dbunit.assertion.DbComparisonFailure[value (table=groups, row=0, col=id)expected:<1>but was:<2>]
As my comment in the integration test points out, the issue seems to be known. However, the suggested workaround with entityManager.flush()
does not work with MockMvc
.