« Return to Thread: wrong database snapshot
private IDatabaseConnection conn;
private DataSource dataSource;private CompanyDAO companyDao;
private Company company;
public void setUp() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"mysql-properties.xml", "applicationContext.xml"});
dataSource = (DataSource) context.getBean("dataSource");
companyDao = (CompanyDAO) context.getBean("companyDao");company = new Company();
conn = new DatabaseConnection(dataSource.getConnection());DatabaseOperation.
INSERT.execute(conn, getDataSet());}
public void tearDown() throws Exception {
DatabaseOperation.DELETE.execute(conn, getDataSet_all());
conn.close();conn = null;}
public void testAddCompany() throws Exception {
company.setId(2);company.setName("Company2");
company.setPassword("password2");companyDao.addCompany(company);
// get database snapshot
IDataSet databaseDataSet = conn.createDataSet();ITable actual = databaseDataSet.getTable("company");
// load expected data from XML dataset
IDataSet expectedDataSet = getDataSet_all();
ITable expected = expectedDataSet.getTable("company");
Assertion.assertEquals(exp! ected, actual);
}
public void testGetCompany() {
Company company2 = companyDao.getCompany(1);assertEquals(
"Company1", company2.getName());}
public void testRemoveCompany() throws Exception {
company.setId(1);
company.setName("Company1");companyDao.removeCompany(company);
// get database snapshot
IDataSet databaseDataSet = conn.createDataSet();ITable actual = databaseDataSet.getTable("company");
// load expected data from XML dataset
IDataSet expectedDataSet = getDataSet_empty();
ITa! ble expected = expectedDataSet.getTable("company");
Assertion.assertEquals(expected, actual);
}
protected IDataSet getDataSet() throws Exception {return new FlatXmlDataSet(new FileInputStream("resources/database/company.xml"));
}
protected IDataSet getDataSet_all() throws Exception {
return new FlatXmlDataSet(new FileInputStream("resources/database/company_all.xml"));}
protected IDataSet getDataSet_empty() throws Exception {return new FlatXmlDataSet(new FileInputStream("resources/database/company_empty.xml"));}
}
company.xml:
<dataset><
</dataset>
company_all.xm!
l:<
<company id="1" name="Company1"/><
company id="2" name="Company2"/></dataset>
<dataset><
company/></dataset>
One of the test I'm having trouble with is RemoveCompany (I have other testcases with the same result). Upon setup I insert 1 record into the database and with this test it should be removed and then checked if the database is empty. I've done a lot of manual checks and the record is removed correctly but junit says that the test failed:
junit.framework.AssertionFailedError: column count (table=company) expected:<0> but was:<4>
I don't understand why junit says!
there
are 4 records, there are none at all. What am I doing wrong, isnt "databaseDataSet.getTable("company")" supposed to fetsch the records out of the database?
I'd be grateful for any help.
greetz
Marco
« Return to Thread: wrong database snapshot
| Free Forum Powered by Nabble | Forum Help |