Search in sources :

Example 6 with EJBException

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

the class EjbTransactionDescriptorTestCase method testLocalMethodHasNever.

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

Example 7 with EJBException

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

the class EarModulesPPTestCase method checkPropertyEjb.

/**
     * Checks access to a system property on the server using EJB.
     *
     * @param moduleName
     * @param propertyName
     * @param exceptionExpected
     * @param expectedValue
     * @throws Exception
     */
private void checkPropertyEjb(final String moduleName, final String propertyName, final boolean exceptionExpected, final String expectedValue) throws Exception {
    LOGGER.debug("Checking if '" + propertyName + "' property is available");
    ReadSystemPropertyRemote bean = lookupEjb(moduleName, EJBAPP_BASE_NAME + moduleName, ReadSystemPropertyBean.class.getSimpleName(), ReadSystemPropertyRemote.class);
    assertNotNull(bean);
    Exception ex = null;
    String propertyValue = null;
    try {
        propertyValue = bean.readSystemProperty(propertyName);
    } catch (Exception e) {
        ex = e;
    }
    if (ex instanceof EJBException && ex.getCause() instanceof AccessControlException) {
        assertTrue("AccessControlException came, but it was not expected", exceptionExpected);
    } else if (ex != null) {
        throw ex;
    } else if (exceptionExpected) {
        fail("AccessControlException was expected");
    }
    if (ex == null && expectedValue != null) {
        assertEquals("System property value doesn't match the expected one.", expectedValue, propertyValue);
    }
}
Also used : ReadSystemPropertyRemote(org.jboss.as.testsuite.integration.secman.ejbs.ReadSystemPropertyRemote) ReadSystemPropertyBean(org.jboss.as.testsuite.integration.secman.ejbs.ReadSystemPropertyBean) AccessControlException(java.security.AccessControlException) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException) EJBException(javax.ejb.EJBException) AccessControlException(java.security.AccessControlException)

Example 8 with EJBException

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

the class RemoteLocalCallProfileTestCase method testStatefulLocalFromRemote.

@Test
@OperateOnDeployment("client")
public void testStatefulLocalFromRemote(@ArquillianResource InitialContext ctx) throws Exception {
    InitialContext jndiContext = new InitialContext();
    StatelessRemote bean = (StatelessRemote) jndiContext.lookup("java:module/" + StatelessBean.class.getSimpleName() + "!" + StatelessRemote.class.getName());
    Assert.assertNotNull(bean);
    try {
        bean.localCall();
        Assert.fail("should not be allowed to call local interface remotely");
    } catch (EJBException e) {
    // it's OK
    } catch (Exception ee) {
        if (!(ee.getCause() instanceof EJBException)) {
            Assert.fail("should be " + EJBException.class.getName());
        }
    }
}
Also used : EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext) EJBException(javax.ejb.EJBException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 9 with EJBException

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

the class RemoteLocalCallTestCase method testStatefulLocalFromRemote.

@Test
@OperateOnDeployment("client")
public void testStatefulLocalFromRemote(@ArquillianResource InitialContext ctx) throws Exception {
    InitialContext jndiContext = new InitialContext();
    StatelessRemote bean = (StatelessRemote) jndiContext.lookup("java:module/" + StatelessBean.class.getSimpleName() + "!" + StatelessRemote.class.getName());
    Assert.assertNotNull(bean);
    try {
        bean.localCall();
        Assert.fail("should not be allowed to call local interface remotely");
    } catch (EJBException e) {
    // it's OK
    } catch (Exception ee) {
        if (!(ee.getCause() instanceof EJBException)) {
            Assert.fail("should be " + EJBException.class.getName());
        }
    }
}
Also used : EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext) EJBException(javax.ejb.EJBException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 10 with EJBException

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

the class RemoteLocalCallTestCase method testStatefulLocalHomeFromRemoteHome.

@Test
@OperateOnDeployment("client")
public void testStatefulLocalHomeFromRemoteHome(@ArquillianResource InitialContext ctx) throws Exception {
    InitialContext jndiContext = new InitialContext();
    StatelessRemoteHome home = (StatelessRemoteHome) jndiContext.lookup("java:module/" + StatelessBean.class.getSimpleName() + "!" + StatelessRemoteHome.class.getName());
    StatelessRemote bean = home.create();
    Assert.assertNotNull(bean);
    try {
        bean.localHomeCall();
        Assert.fail("should not be allowed to call local interface remotely");
    } catch (EJBException e) {
    // it's OK
    } catch (Exception ee) {
        if (!(ee.getCause() instanceof EJBException)) {
            Assert.fail("should be " + EJBException.class.getName());
        }
    }
}
Also used : EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext) EJBException(javax.ejb.EJBException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Aggregations

EJBException (javax.ejb.EJBException)86 InitialContext (javax.naming.InitialContext)40 OpenEJBException (org.apache.openejb.OpenEJBException)24 Test (org.junit.Test)16 RemoteException (java.rmi.RemoteException)13 CreateException (javax.ejb.CreateException)12 NamingException (javax.naming.NamingException)11 Connection (java.sql.Connection)10 PreparedStatement (java.sql.PreparedStatement)10 DataSource (javax.sql.DataSource)10 Properties (java.util.Properties)9 ThreadContext (org.apache.openejb.core.ThreadContext)9 FinderException (javax.ejb.FinderException)7 HashMap (java.util.HashMap)6 RemoveException (javax.ejb.RemoveException)6 BeanContext (org.apache.openejb.BeanContext)6 File (java.io.File)5 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)5 JMSException (javax.jms.JMSException)5 Assembler (org.apache.openejb.assembler.classic.Assembler)5