|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
wrong database snapshotI'm having trouble with my dbunit implementation, my tests to remove records from the database are failing although records are removed correctly. This is my Testcase: CompanyTest: public class CompanyTest extends TestCase { 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"));} } </dataset> <company id="1" name="Company1"/>< company id="2" name="Company2"/></dataset> company_empty.xml: <dataset>< company/></dataset>
________________________________________________________________ Diese Mitteilung wurde von http://www.breitband.ch uebermittelt. Einer der schnellsten Kabel-Internet Zugaenge! ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ dbunit-user mailing list dbunit-user@... https://lists.sourceforge.net/lists/listinfo/dbunit-user |
| Free Forum Powered by Nabble | Forum Help |