Is there a way to create entirely new schema on every case? Using @DatabaseTearDown annotation is not the case here because i need to reset id generators as some of my test expectation rely on them (maybe it's a bad practice)
Update on rearrange my tests:
In one of my expected datasets i have:
<field oid="1" type="enumerated" name="simple enum field"
dict_oid="1" required="0"
level="1"/>
<field_enum_element field_oid="1"></field_enum_element>
<field_enum_element field_oid="1"></field_enum_element>
<field_enum_element field_oid="1"></field_enum_element>
where oid in term table is the generated id. I want to be sure that there are 3 rows were created in field_enum_element table but if i omit generated ids from expected data set as follows:
<field type="enumerated" name="simple enum field"
dict_oid="1" required="0"
level="1"/>
<field_enum_element></field_enum_element>
<field_enum_element></field_enum_element>
<field_enum_element></field_enum_element>
spring-test-db-unit thinks that there are 0 rows in the table
UPDATE:
@Test
@DatabaseSetup(value = "fieldServiceImplTest/testCreateEnumField.xml")
@ExpectedDatabase(value = "fieldServiceImplTest/testCreateEnumField.expected.xml",
assertionMode = DatabaseAssertionMode.NON_STRICT)
@DatabaseTearDown(value = "fieldServiceImplTest/clear.xml", type = DELETE_ALL)
public void testCreateEnumField() {
FieldDTO fieldDTO = new FieldDTO();
fieldDTO.setName("simple enum field");
fieldDTO.setType("enumerated");
fieldDTO.setLevel("term");
fieldDTO.setIsValueRequired(false);
fieldDTO.setDictionaryId(dictionaryService.findByOid(1L).get().returnIdentity());
List<ItemDTO> itemDTOs = Arrays.asList(new ItemDTO(null, "complete"), new ItemDTO(null, "draft"), new ItemDTO(null, "deleted"));
fieldDTO.setItems(new HashSet<>(itemDTOs));
fieldService.createField(fieldDTO);
}
testCreateEnumField.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<dictionary changed="2014-01-31 18:11:54" oid="1" client_oid="1" descr="descr" name="dictionary"/>
</dataset>
testCreateEnumField.expected.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset reset_sequences="hibernate_sequence">
<dictionary changed="2014-01-31 18:11:54" oid="1" client_oid="1" descr="descr" name="dictionary"/>
<field client_oid="1" oid="1" type="enumerated" name="simple enum field"
dict_oid="1" required="0"
level="1"></field>
<enum_element oid="11" client_oid="1" value="deleted"></enum_element>
<enum_element oid="12" client_oid="1" value="draft"></enum_element>
<enum_element oid="13" client_oid="1" value="complete"></enum_element>
<field_enum_element field_oid="1"></field_enum_element>
<field_enum_element field_oid="1"></field_enum_element>
<field_enum_element field_oid="1"></field_enum_element>
</dataset>
Ideally i would like to be able to drop sequence between tests and test cases.