views:

489

answers:

1

Hi, I have a strange problem with dbUnit. I use dbUnit 2.4.4, java 1.6, Spring (as db connection pool), Oracle 9 for my project with about 50 unit tests. For some of them (when I run whole set of tests) I get such exception:

Closed Statement
[junit] junit.framework.AssertionFailedError: Closed Statement
[junit]     at com.myproj.DataAccess.Internal.BaseDAOTest.importToDb(Unknown Source)
[junit]     at com.myproj.DataAccess.Internal.MyDAOTest.testGetBuyClientOrders(Unknown Source)
[junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

importToDb method loads test data from XML file to database via dbUnit's DatabaseOperation.REFRESH.execute method and it is used in ALL tests. If I run these tests with problems separately, there is no problems for them. Do you have any ideas? Thanks!

A: 

I guess some of your tests close the database connection when they clean up. The next test tries to use this connection again for the import and fails.

tangens
I don't close connection explicitly in any of the test. All of them use use jdbcTemplate from Spring DAO library, so I don't need to operate with connections manually. Connections are closed in import function, but this function is the same for all tests.
dbf
Which datasource do you use? Is it the `SingleConnectionDataSource`?
tangens
Datasource description from my Spring config:<bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" lazy-init="true" singleton="true"> <property name="driverClassName" value="${jdbc.driver.class}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="poolPreparedStatements" value="true"/> <property name="maxOpenPreparedStatements" value="20"/> </bean>
dbf