Search in sources :

Example 1 with Queue

use of jakarta.jms.Queue in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied.

@Test
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 : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) ObjectMessage(jakarta.jms.ObjectMessage) QueueSender(jakarta.jms.QueueSender) Queue(jakarta.jms.Queue) TextMessage(jakarta.jms.TextMessage) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 2 with Queue

use of jakarta.jms.Queue in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied.

@Test
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 : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) ObjectMessage(jakarta.jms.ObjectMessage) MessageProducer(jakarta.jms.MessageProducer) Queue(jakarta.jms.Queue) TextMessage(jakarta.jms.TextMessage) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 3 with Queue

use of jakarta.jms.Queue in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWithDefaultDestination_SendsReturnTextMessageWhenSessionSupplied.

@Test
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 : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) ObjectMessage(jakarta.jms.ObjectMessage) QueueSender(jakarta.jms.QueueSender) Queue(jakarta.jms.Queue) TextMessage(jakarta.jms.TextMessage) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 4 with Queue

use of jakarta.jms.Queue in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method replyPayloadNoDestination.

@Test
public void replyPayloadNoDestination() throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage("Response")).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadNoDestination", Message.class);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage("Response");
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(jakarta.jms.TextMessage) MessageProducer(jakarta.jms.MessageProducer) Queue(jakarta.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 5 with Queue

use of jakarta.jms.Queue in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method testReplyWithJackson.

public TextMessage testReplyWithJackson(String methodName, String replyContent) throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage(replyContent)).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", methodName, Message.class);
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTargetType(MessageType.TEXT);
    listener.setMessageConverter(messageConverter);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage(replyContent);
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
    return responseMessage;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(jakarta.jms.TextMessage) MessageProducer(jakarta.jms.MessageProducer) Queue(jakarta.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session)

Aggregations

Queue (jakarta.jms.Queue)12 Session (jakarta.jms.Session)10 Test (org.junit.jupiter.api.Test)10 TextMessage (jakarta.jms.TextMessage)9 MessageProducer (jakarta.jms.MessageProducer)7 QueueSession (jakarta.jms.QueueSession)6 StubTextMessage (org.springframework.jms.StubTextMessage)5 Message (org.springframework.messaging.Message)5 BytesMessage (jakarta.jms.BytesMessage)4 Message (jakarta.jms.Message)4 ObjectMessage (jakarta.jms.ObjectMessage)4 QueueSender (jakarta.jms.QueueSender)2 TopicSession (jakarta.jms.TopicSession)2 StubQueue (org.springframework.jms.StubQueue)2 QosSettings (org.springframework.jms.support.QosSettings)2 JMSException (jakarta.jms.JMSException)1 QueueBrowser (jakarta.jms.QueueBrowser)1 TemporaryQueue (jakarta.jms.TemporaryQueue)1 MappingJackson2MessageConverter (org.springframework.jms.support.converter.MappingJackson2MessageConverter)1 Nullable (org.springframework.lang.Nullable)1