DBUnit test data export

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

DBUnit test data export

toomuchkevin
Hi all,
i'm running some tests on HSQLDB in memory using DBUnit. Each test execution adds, removes, updates the original dataset loaded from xml. After each test execution i would like to export the resulting set of data from the in memory DB to an outputstream for example.
I tried running following code after each test execution:

IDataSet fullDataSet = getConnection().createDataSet();
FlatXmlDataSet.write(fullDataSet, System.out);

but it always prints out the same result, that is the original dataset loaded from my xml file. No changes, no updates, nothing.
I tried flushing the entity manager before exporting, but didn't help.

I tried this too:

String[] depTableNames = TablesDependencyHelper.getAllDependentTables( connection, "MY_TABLE" );
IDataSet depDataset = connection.createDataSet( depTableNames );
FlatXmlDataSet.write(depTableNames , System.out);

Same result again.

Is there another way to export db content with dbunit?

Thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: DBUnit test data export

Jeff Jensen-2
My guess is it related to the connection/datasource - the
dbUnit connection does not see the uncommitted changes. 
To see them, it has to ride the same transaction.

How is the app and dbunit connection configured?  (e.g.
datasource, jndi)  Using JTA/global transactions or local?

If datasource, you will have to use the same datasource
instance.  For example, in my apps I make a Spring bean of
the datasource and inject it to dbUnit and the entity
manager config.


On Fri, 21 May 2010 06:12:20 -0700 (PDT)
  toomuchkevin <[hidden email]> wrote:

>
> Hi all,
> i'm running some tests on HSQLDB in memory using DBUnit.
>Each test execution
> adds, removes, updates the original dataset loaded from
>xml. After each test
> execution i would like to export the resulting set of
>data from the in
> memory DB to an outputstream for example.
> I tried running following code after each test
>execution:
>
> IDataSet fullDataSet = getConnection().createDataSet();
>FlatXmlDataSet.write(fullDataSet, System.out);
>
> but it always prints out the same result, that is the
>original dataset
> loaded from my xml file. No changes, no updates,
>nothing.
> I tried flushing the entity manager before exporting,
>but didn't help.
>
> I tried this too:
>
> String[] depTableNames =
>TablesDependencyHelper.getAllDependentTables(
> connection, "MY_TABLE" );
> IDataSet depDataset = connection.createDataSet(
>depTableNames );
>FlatXmlDataSet.write(depTableNames , System.out);
>
> Same result again.
>
> Is there another way to export db content with dbunit?
>
> Thank you in advance.
> --
> View this message in context:
>http://old.nabble.com/DBUnit-test-data-export-tp28633619p28633619.html
> Sent from the DBUnit - Users mailing list archive at
>Nabble.com.
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user