Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many tests, or test suites, are you running?
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does something look for a magic bean name? Like a context startup listener etc?
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Dave, not sure I follow you on that one?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you loading the Spring app context?
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that my web.xml references Spring which in turn should relate to ApplicationContext in WEB-INF

 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic