use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class RunContextTest method testCopyCurrent_Transaction.
@Test
public void testCopyCurrent_Transaction() {
final ITransaction tx = mock(ITransaction.class);
RunContexts.empty().withTransaction(tx).run(new IRunnable() {
@Override
public void run() throws Exception {
assertEquals(tx, RunContexts.copyCurrent().getTransaction());
}
});
RunContexts.empty().withTransaction(null).run(new IRunnable() {
@Override
public void run() throws Exception {
assertNotNull(ITransaction.CURRENT.get());
assertNotNull(RunContexts.copyCurrent().getTransaction());
assertNull(RunContext.CURRENT.get().getTransaction());
RunContexts.copyCurrent().run(new IRunnable() {
@Override
public void run() throws Exception {
assertNotNull(ITransaction.CURRENT.get());
}
});
}
});
RunContexts.empty().withTransaction(tx).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(tx, ITransaction.CURRENT.get());
assertSame(tx, RunContexts.copyCurrent().getTransaction());
assertSame(tx, RunContext.CURRENT.get().getTransaction());
RunContexts.copyCurrent().run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(tx, ITransaction.CURRENT.get());
assertSame(tx, RunContexts.copyCurrent().getTransaction());
assertSame(tx, RunContext.CURRENT.get().getTransaction());
}
});
}
});
}
use of org.eclipse.scout.rt.platform.transaction.ITransaction 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"));
}
});
}
});
}
Aggregations