Search in sources :

Example 6 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class EncSingletonBean method lookupJMSConnectionFactory.

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);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatefulObject(org.apache.openejb.test.stateful.BasicStatefulObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) JMSException(javax.jms.JMSException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 7 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class EncCmpBean method lookupJMSConnectionFactory.

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);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatelessObject(org.apache.openejb.test.stateless.BasicStatelessObject) BasicStatefulObject(org.apache.openejb.test.stateful.BasicStatefulObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) RemoveException(javax.ejb.RemoveException) JMSException(javax.jms.JMSException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 8 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class ContextLookupMdbBean method lookupJMSConnectionFactory.

@Override
public void lookupJMSConnectionFactory() throws TestFailureException {
    try {
        try {
            Object obj = mdbContext.lookup("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 = mdbContext.lookup("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 = mdbContext.lookup("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);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatelessObject(org.apache.openejb.test.stateless.BasicStatelessObject) BasicStatefulObject(org.apache.openejb.test.stateful.BasicStatefulObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) JMSException(javax.jms.JMSException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 9 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class ContextLookupMdbPojoBean method lookupJMSConnectionFactory.

public void lookupJMSConnectionFactory() throws TestFailureException {
    try {
        try {
            Object obj = getMessageDrivenContext().lookup("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 = getMessageDrivenContext().lookup("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 = getMessageDrivenContext().lookup("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);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatelessObject(org.apache.openejb.test.stateless.BasicStatelessObject) BasicStatefulObject(org.apache.openejb.test.stateful.BasicStatefulObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 10 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithQueueConnectionFactoryAndJms11Usage.

@Test
public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    given(cf.createConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createConnection();
    Connection con2 = scf.createConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) Test(org.junit.Test)

Aggregations

QueueConnectionFactory (javax.jms.QueueConnectionFactory)27 ConnectionFactory (javax.jms.ConnectionFactory)18 TopicConnectionFactory (javax.jms.TopicConnectionFactory)18 JMSException (javax.jms.JMSException)16 AssertionFailedError (junit.framework.AssertionFailedError)15 TestFailureException (org.apache.openejb.test.TestFailureException)15 EJBException (javax.ejb.EJBException)13 InitialContext (javax.naming.InitialContext)11 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)11 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)11 RemoteException (java.rmi.RemoteException)10 QueueConnection (javax.jms.QueueConnection)10 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)10 Test (org.junit.Test)7 Queue (javax.jms.Queue)6 QueueSession (javax.jms.QueueSession)6 Message (javax.jms.Message)5 MessageProducer (javax.jms.MessageProducer)5 TextMessage (javax.jms.TextMessage)5 RemoveException (javax.ejb.RemoveException)4