use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class RunContextTest method testTransactionMember_TxRequiresNew.
@Test
public void testTransactionMember_TxRequiresNew() {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("abc");
when(txMember.needsCommit()).thenReturn(true);
when(txMember.commitPhase1()).thenReturn(true);
RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMember(txMember).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
}
});
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();
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class RunContextTest method testCopyCurrent_TransactionMember.
@Test
public void testCopyCurrent_TransactionMember() {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("txMember");
RunContexts.empty().withTransactionMember(txMember).run(new IRunnable() {
@Override
public void run() throws Exception {
final ITransaction tx = ITransaction.CURRENT.get();
assertNotNull(tx);
assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRED).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(tx, ITransaction.CURRENT.get());
assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
}
});
RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {
@Override
public void run() throws Exception {
assertNotSame(tx, ITransaction.CURRENT.get());
assertNull(ITransaction.CURRENT.get().getMember("txMember"));
}
});
RunContexts.copyCurrent().withTransactionScope(TransactionScope.MANDATORY).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(tx, ITransaction.CURRENT.get());
assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
}
});
}
});
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class RunContextTest method testTransactionMember_TxRequired_TxNotPresent.
@Test
public void testTransactionMember_TxRequired_TxNotPresent() {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("abc");
when(txMember.needsCommit()).thenReturn(true);
when(txMember.commitPhase1()).thenReturn(true);
RunContexts.empty().withTransactionScope(TransactionScope.REQUIRED).withTransactionMember(txMember).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
}
});
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