Search in sources :

Example 91 with Session

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

the class MessagingMessageListenerAdapterTests method exceptionInListener.

@Test
public void exceptionInListener() {
    javax.jms.Message message = new StubTextMessage("foo");
    Session session = mock(Session.class);
    MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class);
    try {
        listener.onMessage(message, session);
        fail("Should have thrown an exception");
    } catch (JMSException ex) {
        fail("Should not have thrown a JMS exception");
    } catch (ListenerExecutionFailedException ex) {
        assertEquals(IllegalArgumentException.class, ex.getCause().getClass());
        assertEquals("Expected test exception", ex.getCause().getMessage());
    }
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 92 with Session

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

the class MessagingMessageListenerAdapterTests method exceptionInInvocation.

@Test
public void exceptionInInvocation() {
    javax.jms.Message message = new StubTextMessage("foo");
    Session session = mock(Session.class);
    MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class);
    try {
        listener.onMessage(message, session);
        fail("Should have thrown an exception");
    } catch (JMSException ex) {
        fail("Should not have thrown a JMS exception");
    } catch (ListenerExecutionFailedException ex) {
        assertEquals(MessageConversionException.class, ex.getCause().getClass());
    }
}
Also used : MessageConversionException(org.springframework.messaging.converter.MessageConversionException) StubTextMessage(org.springframework.jms.StubTextMessage) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 93 with Session

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

the class JmsInvokerTests method receiveTimeoutExpired.

@Test
public void receiveTimeoutExpired() {
    JmsInvokerProxyFactoryBean pfb = new JmsInvokerProxyFactoryBean() {

        @Override
        protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
            // faking no message received
            return null;
        }
    };
    pfb.setServiceInterface(ITestBean.class);
    pfb.setConnectionFactory(this.mockConnectionFactory);
    pfb.setQueue(this.mockQueue);
    pfb.setReceiveTimeout(1500);
    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    thrown.expect(RemoteTimeoutException.class);
    thrown.expectMessage("1500 ms");
    thrown.expectMessage("getAge");
    proxy.getAge();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) Queue(javax.jms.Queue) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 94 with Session

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

the class JmsInvokerTests method doTestJmsInvokerProxyFactoryBeanAndServiceExporter.

private void doTestJmsInvokerProxyFactoryBeanAndServiceExporter(boolean dynamicQueue) throws Throwable {
    TestBean target = new TestBean("myname", 99);
    final JmsInvokerServiceExporter exporter = new JmsInvokerServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);
    exporter.setMessageConverter(new MockSimpleMessageConverter());
    exporter.afterPropertiesSet();
    JmsInvokerProxyFactoryBean pfb = new JmsInvokerProxyFactoryBean() {

        @Override
        protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
            Session mockExporterSession = mock(Session.class);
            ResponseStoringProducer mockProducer = new ResponseStoringProducer();
            given(mockExporterSession.createProducer(requestMessage.getJMSReplyTo())).willReturn(mockProducer);
            exporter.onMessage(requestMessage, mockExporterSession);
            assertTrue(mockProducer.closed);
            return mockProducer.response;
        }
    };
    pfb.setServiceInterface(ITestBean.class);
    pfb.setConnectionFactory(this.mockConnectionFactory);
    if (dynamicQueue) {
        pfb.setQueueName("myQueue");
    } else {
        pfb.setQueue(this.mockQueue);
    }
    pfb.setMessageConverter(new MockSimpleMessageConverter());
    pfb.afterPropertiesSet();
    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
    proxy.setAge(50);
    assertEquals(50, proxy.getAge());
    proxy.setStringArray(new String[] { "str1", "str2" });
    assertTrue(Arrays.equals(new String[] { "str1", "str2" }, proxy.getStringArray()));
    try {
        proxy.exceptional(new IllegalStateException());
        fail("Should have thrown IllegalStateException");
    } catch (IllegalStateException ex) {
    // expected
    }
    try {
        proxy.exceptional(new IllegalAccessException());
        fail("Should have thrown IllegalAccessException");
    } catch (IllegalAccessException ex) {
    // expected
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) Queue(javax.jms.Queue) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession)

Example 95 with Session

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

the class SimpleMessageConverterTests method testStringConversion.

@Test
public void testStringConversion() throws JMSException {
    Session session = mock(Session.class);
    TextMessage message = mock(TextMessage.class);
    String content = "test";
    given(session.createTextMessage(content)).willReturn(message);
    given(message.getText()).willReturn(content);
    SimpleMessageConverter converter = new SimpleMessageConverter();
    Message msg = converter.toMessage(content, session);
    assertEquals(content, converter.fromMessage(msg));
}
Also used : TextMessage(javax.jms.TextMessage) MapMessage(javax.jms.MapMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Session (javax.jms.Session)281 MessageProducer (javax.jms.MessageProducer)131 Connection (javax.jms.Connection)120 Test (org.junit.Test)110 Message (javax.jms.Message)86 TextMessage (javax.jms.TextMessage)84 JMSException (javax.jms.JMSException)80 MessageConsumer (javax.jms.MessageConsumer)64 Destination (javax.jms.Destination)46 Topic (javax.jms.Topic)40 ConnectionFactory (javax.jms.ConnectionFactory)37 ObjectMessage (javax.jms.ObjectMessage)28 Queue (javax.jms.Queue)26 StubTextMessage (org.springframework.jms.StubTextMessage)20 QueueSession (javax.jms.QueueSession)16 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)16 MessageCreator (org.springframework.jms.core.MessageCreator)15 BytesMessage (javax.jms.BytesMessage)14 MapMessage (javax.jms.MapMessage)12 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)12