Java 类javax.jms.IllegalStateRuntimeException 实例源码

项目:pooled-jms    文件:JmsPoolJMSContext.java   
@Override
public JMSProducer createProducer() {
    if (connectionRefCount.get() == 0) {
        throw new IllegalStateRuntimeException("The Connection is closed");
    }

    try {
        if (sharedProducer == null) {
            synchronized (this) {
                if (sharedProducer == null) {
                    sharedProducer = (JmsPoolMessageProducer) getSession().createProducer(null);
                }
            }
        }

        return new JmsPoolJMSProducer(getSession(), sharedProducer);
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
项目:pooled-jms    文件:JmsPoolJMSProducerTest.java   
@Test
public void testRuntimeExceptionFromSendMessage() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), context.createMessage());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:JmsPoolJMSProducerTest.java   
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), new byte[0]);
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:JmsPoolJMSProducerTest.java   
@Test
public void testRuntimeExceptionFromSendMapBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), Collections.<String, Object>emptyMap());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:JmsPoolJMSProducerTest.java   
@Test
public void testRuntimeExceptionFromSendSerializableBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), UUID.randomUUID());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:JmsPoolJMSProducerTest.java   
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
    JMSProducer producer = context.createProducer();

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    connection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onMessageSend(MockJMSSession session, Message message) throws JMSException {
            throw new IllegalStateException("Send Failed");
        }
    });

    try {
        producer.send(context.createTemporaryQueue(), "test");
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:MockJMSContext.java   
@Override
public JMSProducer createProducer() {
    if (connectionRefCount.get() == 0) {
        throw new IllegalStateRuntimeException("The Connection is closed");
    }

    try {
        if (sharedProducer == null) {
            synchronized (this) {
                if (sharedProducer == null) {
                    sharedProducer = (MockJMSMessageProducer) getSession().createProducer(null);
                }
            }
        }

        return new MockJMSProducer(getSession(), sharedProducer);
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
项目:pooled-jms    文件:JmsPoolSessionTest.java   
@Test(timeout = 60000)
public void testRun() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    try {
        session.run();
        fail("Session should be unable to run outside EE.");
    } catch (JMSRuntimeException jmsre) {}

    session.close();

    try {
        session.run();
        fail("Session should be closed.");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:pooled-jms    文件:JmsPoolJMSContextTest.java   
@Test(timeout = 60000)
public void testSetClientIDTwiceWithSameID() throws Exception {
    JMSContext context = cf.createContext();

    // test: call setClientID("newID") twice
    // this should be tolerated and not result in an exception
    context.setClientID("newID");

    try {
        context.setClientID("newID");
        context.start();
        context.close();
    } catch (IllegalStateRuntimeException ise) {
        LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
        fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
    } finally {
        cf.stop();
    }

    LOG.debug("Test finished.");
}
项目:pooled-jms    文件:JmsPoolJMSContextTest.java   
@Test(timeout = 60000)
public void testSetClientIDTwiceWithDifferentID() throws Exception {
    JMSContext context = cf.createContext();

    // test: call setClientID() twice with different IDs
    // this should result in an IllegalStateException
    context.setClientID("newID1");
    try {
        context.setClientID("newID2");
        fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException");
    } catch (IllegalStateRuntimeException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        context.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
项目:pooled-jms    文件:JmsPoolJMSContextTest.java   
@Test(timeout = 60000)
public void testSetClientIDAfterConnectionStart() throws Exception {
    JMSContext context = cf.createContext();

    // test: try to call setClientID() after start()
    // should result in an exception
    try {
        context.start();
        context.setClientID("newID3");
        fail("Calling setClientID() after start() mut raise a JMSException.");
    } catch (IllegalStateRuntimeException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        context.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
项目:org.ops4j.pax.transx    文件:JMSContextImpl.java   
protected Session getSession() {
    if (session == null) {
        synchronized (this) {
            if (closed)
                throw new IllegalStateRuntimeException("Context is closed");
            if (session == null) {
                try {
                    session = connection.createSession(sessionMode);
                } catch (JMSException e) {
                    throw Utils.convertToRuntimeException(e);
                }
            }
        }
    }
    return session;
}
项目:activemq-artemis    文件:ActiveMQJMSContext.java   
/**
 *
 */
private void checkSession() {
   if (session == null) {
      synchronized (this) {
         if (closed)
            throw new IllegalStateRuntimeException("Context is closed");
         if (session == null) {
            try {
               if (xa) {
                  session = ((XAConnection) connection).createXASession();
               } else {
                  session = connection.createSession(sessionMode);
               }
            } catch (JMSException e) {
               throw JmsExceptionUtils.convertToRuntimeException(e);
            }
         }
      }
   }
}
项目:qpid-jms    文件:JmsProducerTest.java   
@Test
public void testRuntimeExceptionFromSendMessage() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);
    Message message = Mockito.mock(Message.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(message);

    Mockito.doThrow(IllegalStateException.class).when(message).setJMSCorrelationID(anyString());

    JmsProducer producer = new JmsProducer(session, messageProducer);

    producer.setJMSCorrelationID("id");

    try {
        producer.send(session.createTemporaryQueue(), session.createMessage());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:qpid-jms    文件:JmsProducerTest.java   
@Test
public void testRuntimeExceptionFromSendByteBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

    Mockito.doThrow(IllegalStateException.class).when(session).createBytesMessage();

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), new byte[0]);
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:qpid-jms    文件:JmsProducerTest.java   
@Test
public void testRuntimeExceptionFromSendMapBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

    Mockito.doThrow(IllegalStateException.class).when(session).createMapMessage();

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), Collections.<String, Object>emptyMap());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:qpid-jms    文件:JmsProducerTest.java   
@Test
public void testRuntimeExceptionFromSendSerializableBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

    Mockito.doThrow(IllegalStateException.class).when(session).createObjectMessage();

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), UUID.randomUUID());
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:qpid-jms    文件:JmsProducerTest.java   
@Test
public void testRuntimeExceptionFromSendStringBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageProducer messageProducer = Mockito.mock(JmsMessageProducer.class);

    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));

    Mockito.doThrow(IllegalStateException.class).when(session).createTextMessage(anyString());

    JmsProducer producer = new JmsProducer(session, messageProducer);

    try {
        producer.send(session.createTemporaryQueue(), "test");
        fail("Should have thrown an exception");
    } catch (IllegalStateRuntimeException isre) {}
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnGetMessageListener() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).getMessageListener();

    try {
        consumer.getMessageListener();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnSetMessageListener() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).setMessageListener(null);

    try {
        consumer.setMessageListener(null);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnGetMessageSelector() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).getMessageSelector();

    try {
        consumer.getMessageSelector();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnReceive() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive();

    try {
        consumer.receive();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnReceiveNoWait() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveNoWait();

    try {
        consumer.receiveNoWait();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnTimedReceive() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receive(anyLong());

    try {
        consumer.receive(100);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnReceiveBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, -1);

    try {
        consumer.receiveBody(Map.class);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnTimedReceiveBody() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 100);

    try {
        consumer.receiveBody(Map.class, 100);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsConsumerTest.java   
@Test
public void testRuntimeExceptionOnReceiveBodyNoWait() throws JMSException {
    JmsSession session = Mockito.mock(JmsSession.class);
    JmsMessageConsumer messageConsumer = Mockito.mock(JmsMessageConsumer.class);
    JmsConsumer consumer = new JmsConsumer(session, messageConsumer);

    Mockito.doThrow(IllegalStateException.class).when(messageConsumer).receiveBody(Map.class, 0);

    try {
        consumer.receiveBodyNoWait(Map.class);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        consumer.close();
    }
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testContextClosePreservesSessionCloseException() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).close();
    Mockito.doThrow(JMSSecurityException.class).when(connection).close();

    context.createTemporaryTopic();
    Mockito.verify(connection, Mockito.times(1)).createSession(JMSContext.AUTO_ACKNOWLEDGE);

    try {
        context.close();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    }
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateProducer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createProducer(null);

    try {
        context.createProducer();
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createConsumer(any(Destination.class));

    try {
        context.createConsumer(context.createTemporaryQueue());
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class));
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateConsumerWithSelector() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createConsumer(any(Destination.class), anyString());

    try {
        context.createConsumer(context.createTemporaryQueue(), "a = b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateConsumerWithSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createConsumer(any(Destination.class), anyString(), anyBoolean());

    try {
        context.createConsumer(context.createTemporaryQueue(), "a = b", true);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createConsumer(any(Destination.class), anyString(), anyBoolean());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateDurableConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createDurableConsumer(any(Topic.class), anyString());

    try {
        context.createDurableConsumer(context.createTemporaryTopic(), "name");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createDurableConsumer(any(Topic.class), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateDurableConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).
        createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean());

    try {
        context.createDurableConsumer(context.createTemporaryTopic(), "name", "a = b", true);
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createDurableConsumer(any(Topic.class), anyString(), anyString(), anyBoolean());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateSharedConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createSharedConsumer(any(Topic.class), anyString());

    try {
        context.createSharedConsumer(context.createTemporaryTopic(), "name");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedConsumer(any(Topic.class), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateSharedConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).
        createSharedConsumer(any(Topic.class), anyString(), anyString());

    try {
        context.createSharedConsumer(context.createTemporaryTopic(), "name", "a = b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedConsumer(any(Topic.class), anyString(), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateSharedDurableConsumer() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createSharedDurableConsumer(any(Topic.class), anyString());

    try {
        context.createSharedDurableConsumer(context.createTemporaryTopic(), "name");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateSharedDurableConsumerSelectorNoLocal() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryTopic()).thenReturn(new JmsTemporaryTopic());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).
    createSharedDurableConsumer(any(Topic.class), anyString(), anyString());

    try {
        context.createSharedDurableConsumer(context.createTemporaryTopic(), "name", "a = b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createSharedDurableConsumer(any(Topic.class), anyString(), anyString());
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateQueueBrowser() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createBrowser(any(Queue.class));

    try {
        context.createBrowser(context.createTemporaryQueue());
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createBrowser(any(Queue.class));
}
项目:qpid-jms    文件:JmsContextTest.java   
@Test
public void testRuntimeExceptionOnCreateQueueBrowserWithSelector() throws JMSException {
    JmsConnection connection = Mockito.mock(JmsConnection.class);
    JmsSession session = Mockito.mock(JmsSession.class);
    Mockito.when(connection.createSession(Mockito.anyInt())).thenReturn(session);
    Mockito.when(session.createTemporaryQueue()).thenReturn(new JmsTemporaryQueue());
    JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);

    Mockito.doThrow(IllegalStateException.class).when(session).createBrowser(any(Queue.class), anyString());

    try {
        context.createBrowser(context.createTemporaryQueue(), "a == b");
        fail("Should throw ISRE");
    } catch (IllegalStateRuntimeException isre) {
    } finally {
        context.close();
    }

    Mockito.verify(session, Mockito.times(1)).createBrowser(any(Queue.class), anyString());
}