File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes DBUnit, why insert test data, only to delete/re-create tables after? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "DBUnit, why insert test data, only to delete/re-create tables after?" Watch "DBUnit, why insert test data, only to delete/re-create tables after?" New topic
Author

DBUnit, why insert test data, only to delete/re-create tables after?

James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Hi,

I'm having a rather strange issue with DBUnit, which I don't understand that well.

I'm reading through the output window in NetBeans to see what is happening when my application starts up, it seems that DBUnit is inserting my test data into my tables, but further down, the tables are dropped and re-created.

This seems to happen about 3 times over. I've cleared the output window and started up, so not sure why it has cycled 3 times over.

Anyway, from the code below, can anyone please hazzard a guess to where I have gone wrong?

My application starts up OK, I just have no data available, tables are all empty

Much appreciated

J


ApplicationContext.xml


DBUnitBootstrapper


Logs


testdata.xml


Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Sorry forgot to add,

What I'm trying to achieve is; to have an XML with all my test data, so everytime I start up I have the same clean set of data. Currently everytime I start up I have to manually run SQL insert statements due to derby not retaining data after restarting.

Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How many tests, or test suites, are you running?
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Hi David

I'm not running any tests, could this be the issue?

The above posted code is all I have used for dbunit (other than the mention of dbunit, ant, junit in my pom.xml)
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I've set a breakpoint on the setOperations and execute() methods on my bootstrapper, these breakpoints are not being caught which leads me to believe the bootstrapper is not being run on start up

Is there something wrong with my applicationContext that would not enable this feature?

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Does something look for a magic bean name? Like a context startup listener etc?
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Sorry Dave, not sure I follow you on that one?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Just defining a bean usually isn't enough to do anything--something needs to know to look for a bean with that name.

I missed the "init-method" attribute; so the question now is what in the code or startup is going to instantiate the bean in order for the init-method to run?
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I'm not sure, I was coming here hopeful of some advice.

I can't seem to find a tutorial that describes what I'm trying to do.

I just need to fire off that bean, the bootstrapper will read my testData xml file, insert it and hopefully be done
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How are you loading the Spring app context?
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I believe that my web.xml references Spring which in turn should relate to ApplicationContext in WEB-INF

James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Its strange, if I look at my test data, and change the value of the ID from an integer, to "abc", then when I start up my application it gives a numberFormatException

But it still never halts at any breakpoints I put on my DBUnitBootstrapper.

As far as I'm aware, when application loads up, it goes through application context to initialise all the beans. The DBUnit bean calls the init-method, which links to the execute() method on the bootstrapper, it should then populate the datasource with data from the XML.

Am I missing something obvious?

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DBUnit, why insert test data, only to delete/re-create tables after?
 
Similar Threads
could not parse mapping resource.
Hibernate: Found two representations of same collection
Simple But Crazy Cascade Problem
org.hibernate.exception.SQLGrammarException: could not insert:
Hibernate StackOverflowError: bidirectional many-to-many