3 Replies Latest reply on Mar 24, 2010 4:56 PM by Adam Warski

    Using Envers in transactional Unit Tests

    Dirk Eismann Newbie



      what is the best practice to use Envers in a transactional unit test, e.g. for testing the integration of Envers with a service layer?


      In my current project we use Spring 2.5.6, Hibernate 3.3.2, Hibernate Annotations and of course Envers. The unit tests for our application are transactional, so that changes done to the database are rolled back and do never get committed (we base our unit tests on the convenience test class org.springframework.test.jpa.AbstractJpaTests)


      The problem was that due to the fact that the transaction never gets committed the AuditSync.beforeCompletion() method never gets called, thus Envers never wrote data which makes it impossible to check if data got revisioned correctly.


      Our whacky workaround was to add a method to our test class that forces the AuditSync.beforeCompletion() to get called so Envers writes to the ausiting tables but still at the end of a test run everything gets rolled back nicely... still, it feels wrong somehow - or at least like unsupported hacking.


      So how do other handle this?