use of org.apache.cayenne.tx.TransactionFactory in project cayenne by apache.
the class ServerRuntimeTest method testPerformInTransaction.
@Test
public void testPerformInTransaction() {
final BaseTransaction tx = mock(BaseTransaction.class);
final TransactionFactory txFactory = mock(TransactionFactory.class);
when(txFactory.createTransaction()).thenReturn(tx);
Module module = binder -> binder.bind(TransactionFactory.class).toInstance(txFactory);
ServerRuntime runtime = ServerRuntime.builder().addConfig("xxxx").addModule(module).build();
try {
final Object expectedResult = new Object();
Object result = runtime.performInTransaction(new TransactionalOperation<Object>() {
public Object perform() {
assertSame(tx, BaseTransaction.getThreadTransaction());
return expectedResult;
}
});
assertSame(expectedResult, result);
} finally {
runtime.shutdown();
}
}
Aggregations