use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testTransactionMemberFailed.
@Test
public void testTransactionMemberFailed() throws Exception {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("abc");
when(txMember.needsCommit()).thenReturn(true);
when(txMember.commitPhase1()).thenReturn(true);
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMembers(Arrays.asList(txMember)));
try {
chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
throw new RuntimeException("JUnit exception");
}
});
fail("exception expected");
} catch (RuntimeException e) {
// NOOP
}
InOrder inOrder = Mockito.inOrder(txMember);
inOrder.verify(txMember, never()).commitPhase1();
inOrder.verify(txMember, never()).commitPhase2();
inOrder.verify(txMember, times(1)).rollback();
inOrder.verify(txMember, times(1)).release();
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testTransactionMember_REQUIRED_TxNotPresent.
@Test
public void testTransactionMember_REQUIRED_TxNotPresent() throws Exception {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("abc");
when(txMember.needsCommit()).thenReturn(true);
when(txMember.commitPhase1()).thenReturn(true);
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRED).withTransactionMembers(Arrays.asList(txMember)));
chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
return null;
}
});
InOrder inOrder = Mockito.inOrder(txMember);
inOrder.verify(txMember, times(1)).commitPhase1();
inOrder.verify(txMember, times(1)).commitPhase2();
inOrder.verify(txMember, never()).rollback();
inOrder.verify(txMember, times(1)).release();
}
Aggregations