Re: Enable/Disable a database trigger when running a dbunit test
- From: Peter <peter.fourneau@xxxxxxxxx>
- Date: Thu, 20 Aug 2009 02:55:17 -0700 (PDT)
On 14 aug, 21:50, "John B. Matthews" <nos...@xxxxxxxxxxxxxx> wrote:
In article
<1c7f546f-680e-49ee-a302-4b2780ea9...@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Peter Fourneau <Peter.Fourn...@xxxxxxxxx> wrote:
I've created a testcase extending the
AbstractTransactionalDataSourceSpringContextTests. This testclass is
infact a dbunit test. I prepopulate the database with my own data,
perform a test and afterwords everything is rollbacked by the
TransactionalSpringTest (so original data in the db is preserved, my
own testdata should only exist in the test).
The dabase id's in this database are generated by a trigger. This
trigger calls the sequencer to create the next value. I don't want
this behaviour for my data I put in the table when running the test.
I want to define my own id's (so I can catchup the records after
calling te classToTest to check the changed values of this record) To
overcome this I ran an sql statement to disable the trigger. after
that I insert my own data and then I enable the trigger again. Than
I call the method I want to test on the classToTest. I've noticed
that the transaction is commited after enabling the trigger: the
original data in the database is lost, the testdata is now in place.
Is there a way to overcome this? (It's not an option to let our
sofware call the sequencer before inserting data so we don't need a
trigger anymore)
Normal flow dbunit test:
1) open transaction
2) insert testdata
3) perform test
4) verify test results
5) rollback transaction
--> gives normal behaviour
In my case:
1) open transaction
2) disable trigger
3) insert testdata
4) enable trigger
5) perform test
6) verify test
7) rollback transaction
--> original data is lost, testdata is commited to database.
Instead of disabling the trigger, would it make sense to replace the
trigger with one that records the identifiers needed for analysis?
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Issue solved by starting up a seperate thread for enabling/disabling
the trigger. In this case the orginal transaction started up by the
dbunit test will not be affected.
Regards,
Peter F
.
- References:
- Enable/Disable a database trigger when running a dbunit test
- From: Peter Fourneau
- Re: Enable/Disable a database trigger when running a dbunit test
- From: John B. Matthews
- Enable/Disable a database trigger when running a dbunit test
- Prev by Date: References and comparisons
- Next by Date: Re: References and comparisons
- Previous by thread: Re: Enable/Disable a database trigger when running a dbunit test
- Next by thread: Suggestions for email client using http
- Index(es):
Relevant Pages
|