Enable/Disable a database trigger when running a dbunit test
- From: Peter Fourneau <Peter.Fourneau@xxxxxxxxx>
- Date: Fri, 14 Aug 2009 04:36:39 -0700 (PDT)
Hi
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.
Thanks for the advice/help!
Regards
.
- Follow-Ups:
- Re: Enable/Disable a database trigger when running a dbunit test
- From: John B. Matthews
- Re: Enable/Disable a database trigger when running a dbunit test
- Prev by Date: heroin's black nipples in transparent
- Next by Date: Re: Enable/Disable a database trigger when running a dbunit test
- Previous by thread: heroin's black nipples in transparent
- Next by thread: Re: Enable/Disable a database trigger when running a dbunit test
- Index(es):
Relevant Pages
|