wrong database snapshot

View: New views
1 Messages — Rating Filter:   Alert me  

wrong database snapshot

by Marco Lauper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hey there,

I'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"));

}

}

company.xml:
<dataset><

company id="1" name="Company1"/>

</dataset>

company_all.xm! l:<

dataset>

<company id="1" name="Company1"/><

company id="2" name="Company2"/>

</dataset>


company_empty.xml:

<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



________________________________________________________________
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
LightInTheBox - Buy quality products at wholesale price