Search in sources :

Example 1 with EJBTransactionRequiredException

use of javax.ejb.EJBTransactionRequiredException in project wildfly by wildfly.

the class EjbTransactionDescriptorTestCase method testRemoteMethodHasMandatory.

@Test
public void testRemoteMethodHasMandatory() throws SystemException, NotSupportedException, NamingException {
    final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction");
    final TransactionRemote bean = (TransactionRemote) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionRemote.class.getName());
    userTransaction.begin();
    try {
        Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus());
    } finally {
        userTransaction.rollback();
    }
    try {
        bean.transactionStatus();
        throw new RuntimeException("Expected an exception");
    } catch (EJBTransactionRequiredException e) {
    //ignore
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) InitialContext(javax.naming.InitialContext) EJBTransactionRequiredException(javax.ejb.EJBTransactionRequiredException) Test(org.junit.Test)

Example 2 with EJBTransactionRequiredException

use of javax.ejb.EJBTransactionRequiredException in project Payara by payara.

the class SafeProperties method mapLocal3xException.

private Throwable mapLocal3xException(Throwable t) {
    Throwable mappedException = null;
    if (t instanceof TransactionRolledbackLocalException) {
        mappedException = new EJBTransactionRolledbackException();
        mappedException.initCause(t);
    } else if (t instanceof TransactionRequiredLocalException) {
        mappedException = new EJBTransactionRequiredException();
        mappedException.initCause(t);
    } else if (t instanceof NoSuchObjectLocalException) {
        mappedException = new NoSuchEJBException();
        mappedException.initCause(t);
    } else if (t instanceof AccessLocalException) {
        mappedException = new EJBAccessException();
        mappedException.initCause(t);
    }
    return (mappedException != null) ? mappedException : t;
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) NoSuchEJBException(javax.ejb.NoSuchEJBException) TransactionRolledbackLocalException(javax.ejb.TransactionRolledbackLocalException) AccessLocalException(javax.ejb.AccessLocalException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) TransactionRequiredLocalException(javax.ejb.TransactionRequiredLocalException) EJBTransactionRequiredException(javax.ejb.EJBTransactionRequiredException) EJBAccessException(javax.ejb.EJBAccessException)

Example 3 with EJBTransactionRequiredException

use of javax.ejb.EJBTransactionRequiredException in project wildfly by wildfly.

the class EjbTransactionDescriptorTestCase method testRemoteMethodHasMandatoryNoMethodIntf.

@Test
public void testRemoteMethodHasMandatoryNoMethodIntf() throws SystemException, NotSupportedException, NamingException {
    final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:jboss/UserTransaction");
    final TransactionRemote bean = (TransactionRemote) initialContext.lookup("java:module/" + DescriptorBean.class.getSimpleName() + "!" + TransactionRemote.class.getName());
    userTransaction.begin();
    try {
        Assert.assertEquals(Status.STATUS_ACTIVE, bean.transactionStatus2());
    } finally {
        userTransaction.rollback();
    }
    try {
        bean.transactionStatus2();
        throw new RuntimeException("Expected an exception");
    } catch (EJBTransactionRequiredException e) {
    //ignore
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) InitialContext(javax.naming.InitialContext) EJBTransactionRequiredException(javax.ejb.EJBTransactionRequiredException) Test(org.junit.Test)

Aggregations

EJBTransactionRequiredException (javax.ejb.EJBTransactionRequiredException)3 InitialContext (javax.naming.InitialContext)2 UserTransaction (javax.transaction.UserTransaction)2 Test (org.junit.Test)2 AccessLocalException (javax.ejb.AccessLocalException)1 EJBAccessException (javax.ejb.EJBAccessException)1 EJBTransactionRolledbackException (javax.ejb.EJBTransactionRolledbackException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)1 TransactionRequiredLocalException (javax.ejb.TransactionRequiredLocalException)1 TransactionRolledbackLocalException (javax.ejb.TransactionRolledbackLocalException)1