@DatabaseSetup(value = "/dbunit/dao/admin/consumption-empty_beforesave.xml")
@DatabaseTearDown(value = CREATE_DATASET, type = DatabaseOperation.DELETE_ALL)
@Override
public void testSave() throws Exception {
try {
DatabaseConnection connection = new DatabaseConnection(dataSource.getConnection());
IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(this.getClass()
.getResource("/dbunit/dao/admin/consumption-create_no-id.xml").openStream());
Consumption consumption = new Consumption();
Consumption nconsumption;
Program program = new Program();
Item item = new Item();
DSP5 dsp5 = new DSP5();
consumption.setId(null);
consumption.setQuantity(1);
program.setId(1L);
program.setName(PROGRAM_NAME);
program.setVersion(1);
consumption.setProgram(program);
dsp5.setId(1L);
dsp5.setLicenseNumber(DSP5_LICENSE_NUMBER);
dsp5.setVersion(1);
item.setId(1L);
item.setQuantity(5);
item.setDsp5(dsp5);
item.setVersion(1);
consumption.setItem(item);
consumption.setVersion(1);
nconsumption = consumptionDAO.save(consumption);
assertNotNull(nconsumption);
assertEquals(nconsumption.getQuantity(), consumption.getQuantity());
entityManager.getTransaction().commit();
DatabaseAssertionMode.NON_STRICT.getDatabaseAssertion().assertEquals(expectedDataSet,
connection.createDataSet(expectedDataSet.getTableNames()));
connection.close();
} catch (DatabaseUnitException e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
} catch (SQLException e) {
e.printStackTrace();