Search in sources :

Example 11 with TransactionalException

use of javax.transaction.TransactionalException in project crnk-framework by crnk-project.

the class CdiTransactionRunnerTest method testTransactionalExceptionNotToBeUnwrapped.

@Test
public void testTransactionalExceptionNotToBeUnwrapped() throws Exception {
    Callable callable = Mockito.mock(Callable.class);
    Mockito.when(callable.call()).thenThrow(new TransactionalException("a", new IOException("b")));
    try {
        runner.doInTransaction(callable);
        Assert.fail();
    } catch (TransactionalException e) {
        Assert.assertEquals("a", e.getMessage());
    }
    Mockito.verify(callable, Mockito.times(1)).call();
}
Also used : TransactionalException(javax.transaction.TransactionalException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 12 with TransactionalException

use of javax.transaction.TransactionalException in project narayana by jbosstm.

the class TransactionalImplTest method testNeverExistingTX.

@Test
public void testNeverExistingTX() throws Exception {
    TransactionManager tm = Utills.getTransactionManager();
    Utills.assertTransactionActive(false);
    tm.begin();
    Utills.assertTransactionActive(true);
    try {
        testTransactionalBean.invokeWithNever();
        Assert.fail("Expected Exception to be thrown, but it was not");
    } catch (TransactionalException e) {
    // expected
    }
    Utills.assertTransactionActive(true);
    tm.commit();
    Utills.assertTransactionActive(false);
}
Also used : TransactionalException(javax.transaction.TransactionalException) TransactionManager(javax.transaction.TransactionManager) Test(org.junit.Test)

Aggregations

TransactionalException (javax.transaction.TransactionalException)12 AroundInvoke (javax.interceptor.AroundInvoke)5 Transaction (javax.transaction.Transaction)4 TransactionManager (javax.transaction.TransactionManager)4 Test (org.junit.Test)4 SystemException (javax.transaction.SystemException)3 TransactionManagerHelper (com.sun.enterprise.transaction.TransactionManagerHelper)2 Callable (java.util.concurrent.Callable)2 NotSupportedException (javax.transaction.NotSupportedException)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Logger (java.util.logging.Logger)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 AnnotatedType (javax.enterprise.inject.spi.AnnotatedType)1 InvalidTransactionException (javax.transaction.InvalidTransactionException)1 RollbackException (javax.transaction.RollbackException)1 TransactionRequiredException (javax.transaction.TransactionRequiredException)1 TransactionRolledbackException (javax.transaction.TransactionRolledbackException)1 Transactional (javax.transaction.Transactional)1