Search in sources :

Example 1 with LocalSynchronizationException

use of org.hibernate.resource.transaction.LocalSynchronizationException in project hibernate-orm by hibernate.

the class SynchronizationRegistryStandardImplTests method testUserSynchronizationExceptions.

@Test
public void testUserSynchronizationExceptions() {
    // exception in beforeCompletion
    SynchronizationRegistryStandardImpl registry = new SynchronizationRegistryStandardImpl();
    Synchronization synchronization = SynchronizationErrorImpl.forBefore();
    registry.registerSynchronization(synchronization);
    try {
        registry.notifySynchronizationsBeforeTransactionCompletion();
        fail("Expecting LocalSynchronizationException, but call succeeded");
    } catch (LocalSynchronizationException expected) {
    // expected
    } catch (Exception e) {
        fail("Was expecting LocalSynchronizationException, but got " + e.getClass().getName());
    }
    // exception in beforeCompletion
    registry.clearSynchronizations();
    registry = new SynchronizationRegistryStandardImpl();
    synchronization = SynchronizationErrorImpl.forAfter();
    registry.registerSynchronization(synchronization);
    try {
        registry.notifySynchronizationsAfterTransactionCompletion(Status.STATUS_COMMITTED);
        fail("Expecting LocalSynchronizationException, but call succeeded");
    } catch (LocalSynchronizationException expected) {
    // expected
    } catch (Exception e) {
        fail("Was expecting LocalSynchronizationException, but got " + e.getClass().getName());
    }
}
Also used : LocalSynchronizationException(org.hibernate.resource.transaction.LocalSynchronizationException) SynchronizationRegistryStandardImpl(org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl) Synchronization(javax.transaction.Synchronization) LocalSynchronizationException(org.hibernate.resource.transaction.LocalSynchronizationException) NullSynchronizationException(org.hibernate.resource.transaction.NullSynchronizationException) Test(org.junit.Test)

Aggregations

Synchronization (javax.transaction.Synchronization)1 LocalSynchronizationException (org.hibernate.resource.transaction.LocalSynchronizationException)1 NullSynchronizationException (org.hibernate.resource.transaction.NullSynchronizationException)1 SynchronizationRegistryStandardImpl (org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl)1 Test (org.junit.Test)1