Search in sources :

Example 66 with TextMessage

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

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied.

@Test
public void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
    Queue destination = mock(Queue.class);
    final TextMessage sentTextMessage = mock(TextMessage.class);
    // correlation ID is queried when response is being created...
    given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
    // Reply-To is queried when response is being created...
    given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
    TextMessage responseMessage = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(session.createProducer(destination)).willReturn(queueSender);
    ResponsiveJmsTextMessageReturningMessageDelegate delegate = mock(ResponsiveJmsTextMessageReturningMessageDelegate.class);
    given(delegate.handleMessage(sentTextMessage)).willReturn(responseMessage);
    final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected Object extractMessage(Message message) {
            return message;
        }
    };
    adapter.setMessageConverter(null);
    adapter.onMessage(sentTextMessage, session);
    verify(responseMessage).setJMSCorrelationID(CORRELATION_ID);
    verify(queueSender).send(responseMessage);
    verify(queueSender).close();
}
Also used : TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 67 with TextMessage

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

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied.

@Test
public void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
    given(delegate.handleMessage(textMessage)).willReturn(TEXT);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    // we DON'T want the default SimpleMessageConversion happening...
    adapter.setMessageConverter(null);
    adapter.onMessage(textMessage);
}
Also used : TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 68 with TextMessage

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

the class MessageListenerAdapterTests method testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault.

@Test
public void testThatAnExceptionThrownFromTheHandlingMethodIsSimplySwallowedByDefault() throws Exception {
    final IllegalArgumentException exception = new IllegalArgumentException();
    TextMessage textMessage = mock(TextMessage.class);
    MessageDelegate delegate = mock(MessageDelegate.class);
    willThrow(exception).given(delegate).handleMessage(textMessage);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected void handleListenerException(Throwable ex) {
            assertNotNull("The Throwable passed to the handleListenerException(..) method must never be null.", ex);
            assertTrue("The Throwable passed to the handleListenerException(..) method must be of type [ListenerExecutionFailedException].", ex instanceof ListenerExecutionFailedException);
            ListenerExecutionFailedException lefx = (ListenerExecutionFailedException) ex;
            Throwable cause = lefx.getCause();
            assertNotNull("The cause of a ListenerExecutionFailedException must be preserved.", cause);
            assertSame(exception, cause);
        }
    };
    // we DON'T want the default SimpleMessageConversion happening...
    adapter.setMessageConverter(null);
    adapter.onMessage(textMessage);
}
Also used : TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 69 with TextMessage

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

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied.

@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
    Queue destination = mock(Queue.class);
    TextMessage sentTextMessage = mock(TextMessage.class);
    // correlation ID is queried when response is being created...
    given(sentTextMessage.getJMSCorrelationID()).willReturn(null);
    given(sentTextMessage.getJMSMessageID()).willReturn(CORRELATION_ID);
    // Reply-To is queried when response is being created...
    given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
    TextMessage responseTextMessage = mock(TextMessage.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    Session session = mock(Session.class);
    given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
    given(session.createProducer(destination)).willReturn(messageProducer);
    ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
    given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected Object extractMessage(Message message) {
            return message;
        }
    };
    adapter.onMessage(sentTextMessage, session);
    verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
    verify(messageProducer).send(responseTextMessage);
    verify(messageProducer).close();
    verify(delegate).handleMessage(sentTextMessage);
}
Also used : TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 70 with TextMessage

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

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied.

@Test
public void testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
    Queue destination = mock(Queue.class);
    TextMessage sentTextMessage = mock(TextMessage.class);
    // correlation ID is queried when response is being created...
    given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
    // Reply-To is queried when response is being created...
    // we want to fall back to the default...
    given(sentTextMessage.getJMSReplyTo()).willReturn(null);
    TextMessage responseTextMessage = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
    given(session.createProducer(destination)).willReturn(queueSender);
    ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
    given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected Object extractMessage(Message message) {
            return message;
        }
    };
    adapter.setDefaultResponseDestination(destination);
    adapter.onMessage(sentTextMessage, session);
    verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
    verify(queueSender).send(responseTextMessage);
    verify(queueSender).close();
    verify(delegate).handleMessage(sentTextMessage);
}
Also used : TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) QueueSender(javax.jms.QueueSender) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9