tmControl.setReturnValue(Status.STATUS_ACTIVE, 6);
tm.getTransaction();
tmControl.setReturnValue(transaction, 6);
final MockControl sessionControl = MockControl.createControl(Session.class);
final Session session = (Session) sessionControl.getMock();
final SessionFactory sf = new SingleSessionFactory(session);
utControl.replay();
tmControl.replay();
sessionControl.replay();
JtaTransactionManager ptm = new JtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
final List l = new ArrayList();
l.add("test");
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
Object result = tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
try {
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
TopLinkTemplate ht = new TopLinkTemplate(sf);
List htl = ht.executeFind(new TopLinkCallback() {
public Object doInTopLink(Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
return l;
}
});
ht = new TopLinkTemplate(sf);
htl = ht.executeFind(new TopLinkCallback() {
public Object doInTopLink(Session sess) {
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
assertEquals(session, sess);
return l;
}
});
assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
sessionControl.verify();
sessionControl.reset();
try {
session.release();
sessionControl.setVoidCallable(1);
}
catch (TopLinkException e) {
}
sessionControl.replay();