use of org.apache.cayenne.tx.TransactionListener in project cayenne by apache.
the class ServerRuntimeIT method testPerformInTransaction_Local_Callback.
@Test
public void testPerformInTransaction_Local_Callback() {
TransactionListener callback = mock(TransactionListener.class);
Artist a = runtime.performInTransaction(new TransactionalOperation<Artist>() {
@Override
public Artist perform() {
Artist localArtist = runtime.newContext().newObject(Artist.class);
localArtist.setArtistName("A1");
localArtist.getObjectContext().commitChanges();
return localArtist;
}
}, callback);
assertEquals("A1", a.getArtistName());
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
verify(callback).willCommit(any(Transaction.class));
verify(callback).willAddConnection(any(Transaction.class), any(String.class), any(Connection.class));
verify(callback, times(0)).willRollback(any(Transaction.class));
}
use of org.apache.cayenne.tx.TransactionListener in project cayenne by apache.
the class ServerRuntimeIT method testPerformInTransaction_Local_Callback_Rollback.
@Test
public void testPerformInTransaction_Local_Callback_Rollback() {
TransactionListener callback = mock(TransactionListener.class);
try {
runtime.performInTransaction(new TransactionalOperation<Artist>() {
@Override
public Artist perform() {
Artist localArtist = runtime.newContext().newObject(Artist.class);
localArtist.getObjectContext().commitChanges();
return localArtist;
}
}, callback);
fail("Exception expected");
} catch (ValidationException v) {
verify(callback).willRollback(any(Transaction.class));
verify(callback, times(0)).willAddConnection(any(Transaction.class), any(String.class), any(Connection.class));
verify(callback, times(0)).willCommit(any(Transaction.class));
}
}
Aggregations