public void lookupJMSConnectionFactory() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); Object obj = ctx.lookup("java:comp/env/jms"); Assert.assertNotNull("The JMS ConnectionFactory is null", obj); Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory); final ConnectionFactory connectionFactory = (ConnectionFactory) obj; testJmsConnection(connectionFactory.createConnection()); obj = ctx.lookup("java:comp/env/TopicCF"); Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj); Assert.assertTrue( "Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory); final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj; testJmsConnection(topicConnectionFactory.createConnection()); obj = ctx.lookup("java:comp/env/QueueCF"); Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj); Assert.assertTrue( "Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory); final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj; testJmsConnection(queueConnectionFactory.createConnection()); } catch (final Exception e) { e.printStackTrace(); Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupResource() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final Object obj = ctx.lookup("java:comp/env/datasource"); Assert.assertNotNull("The DataSource is null", obj); Assert.assertTrue("Not an instance of DataSource", obj instanceof DataSource); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupPersistenceUnit() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final EntityManagerFactory emf = (EntityManagerFactory) ctx.lookup("java:comp/env/persistence/TestUnit"); Assert.assertNotNull("The EntityManagerFactory is null", emf); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupStatefulBusinessLocalBean() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final BasicStatefulPojoBean object = (BasicStatefulPojoBean) ctx.lookup("java:comp/env/stateless/beanReferences/stateful-business-localbean"); Assert.assertNotNull("The EJB BusinessLocalBean is null", object); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupPersistenceContext() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext"); Assert.assertNotNull("The EntityManager is null", em); // call a do nothing method to assure entity manager actually exists em.getFlushMode(); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupByteEntry() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final Byte expected = new Byte((byte) 1); final Byte actual = (Byte) ctx.lookup("java:comp/env/stateless/references/Byte"); Assert.assertNotNull("The Byte looked up is null", actual); Assert.assertEquals(expected, actual); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupStatefulBusinessRemote() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final BasicStatefulBusinessRemote object = (BasicStatefulBusinessRemote) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateful-business-remote"), BasicStatefulBusinessRemote.class); Assert.assertNotNull("The EJB BusinessRemote is null", object); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupStatefulBean() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); final BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateful"), BasicStatefulHome.class); Assert.assertNotNull("The EJBHome looked up is null", home); final BasicStatefulObject object = home.createObject("Enc Bean"); Assert.assertNotNull("The EJBObject is null", object); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }
public void lookupSessionContext() throws TestFailureException { try { try { final InitialContext ctx = new InitialContext(); Assert.assertNotNull("The InitialContext is null", ctx); // lookup in enc final SessionContext sctx = (SessionContext) ctx.lookup("java:comp/env/sessioncontext"); Assert.assertNotNull( "The SessionContext got from java:comp/env/sessioncontext is null", sctx); // lookup using global name final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext"); Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx); // verify context was set via legacy set method Assert.assertNotNull("The SessionContext is null from setter method", ejbContext); } catch (final Exception e) { Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage()); } } catch (final AssertionFailedError afe) { throw new TestFailureException(afe); } }