I am a user of Spring Transactional Testing Support, which rolls back tests when they are done, and due to the design of changes, revisions are not created. I created a hack that apparently allows developers to βtellβ developers to do their work manually before a transaction is made, but allows Spring to continue rolling back.
These fragments should help. 1. Create your own auditor who overrides the existing audit auditor. This allows you to access the static element, visible for unit tests. There is probably a better way, but it works.
public class AuditEventListenerForUnitTesting extends AuditEventListener { public static AuditConfiguration auditConfig; @Override public void initialize(Configuration cfg) { super.initialize(cfg); auditConfig = super.getVerCfg(); } }
modify your persistence.xml to include this new listener class instead of the one provided by envers
(repeat for other listeners, if necessary)
Now in the "unit" test:
{ saveNewList(owner); //code that does usual entity creation em.flush(); EventSource hibSession = (EventSource) em.getDelegate(); AuditEventListenerForUnitTesting.auditConfig.getSyncManager().get(hibSession).doBeforeTransactionCompletion(hibSession); //look for envers revisions now, and they should be there }
I need this because I have some JDBC queries for hibernation objects related to version control tables.
jlawmi
source share