views:

6

answers:

0

I have a JUnit4 test which extends AbstractTransactionalJUnit4SpringContextTests. I have a business object that I've marked as a unit of work with @Transactional. The unit of work updates the database that a user has been notified & then attempts to send them a notification message. I have configured the method to rollback for a MailException (spring simple mail api) and mocked out a MailSender to throw a SendMailException when it's called to validate the rollback functionality.

In my Unit Test though, the transaction does not rollback, I'm trying to figure out if it's because it's taking part in the transaction that is being opened for my actual test method, because at that point the test method hasn't commit or rolled back. The method which represents a unit of work is configured to require a new transaction, and I've tried configuring two transaction managers in spring config and specifying that the test case use the second transaction manager. No matter, when I check the data inside the unit test method, it remains modified even though it should have been rolled back by the application code encountering the mail send exception.

any insight would be great.