Search in sources :

Example 16 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveCustomHeaderNameAndPayloadWithHeaderNameSet.

@Test
void resolveCustomHeaderNameAndPayloadWithHeaderNameSet() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setIntProperty("myCounter", 24);
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 17 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method processAndReply.

@Test
void processAndReply() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
    String body = "echo text";
    String correlationId = "link-1234";
    Destination replyDestination = new Destination() {
    };
    TextMessage reply = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(session.createTextMessage(body)).willReturn(reply);
    given(session.createProducer(replyDestination)).willReturn(queueSender);
    listener.setDefaultResponseDestination(replyDestination);
    StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
    inputMessage.setJMSCorrelationID(correlationId);
    listener.onMessage(inputMessage, session);
    assertDefaultListenerMethodInvocation();
    verify(reply).setJMSCorrelationID(correlationId);
    verify(queueSender).send(reply);
    verify(queueSender).close();
}
Also used : Destination(jakarta.jms.Destination) MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 18 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.

private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain, QosSettings replyQosSettings) throws JMSException {
    String body = "echo text";
    String correlationId = "link-1234";
    Destination replyDestination = new Destination() {
    };
    DestinationResolver destinationResolver = mock(DestinationResolver.class);
    TextMessage reply = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
    given(session.createTextMessage(body)).willReturn(reply);
    given(session.createProducer(replyDestination)).willReturn(queueSender);
    listener.setDestinationResolver(destinationResolver);
    StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
    inputMessage.setJMSCorrelationID(correlationId);
    listener.onMessage(inputMessage, session);
    verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
    verify(reply).setJMSCorrelationID(correlationId);
    if (replyQosSettings != null) {
        verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(), replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
    } else {
        verify(queueSender).send(reply);
    }
    verify(queueSender).close();
}
Also used : Destination(jakarta.jms.Destination) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session)

Example 19 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveJmsMessageHeaderAccessor.

@Test
void resolveJmsMessageHeaderAccessor() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(JmsMessageHeaderAccessor.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setBooleanProperty("customBoolean", true);
    message.setJMSPriority(9);
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 20 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveHeaders.

@Test
void resolveHeaders() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, Map.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setIntProperty("customInt", 1234);
    message.setJMSMessageID("abcd-1234");
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

StubTextMessage (org.springframework.jms.StubTextMessage)26 Test (org.junit.jupiter.api.Test)21 Session (jakarta.jms.Session)14 Destination (jakarta.jms.Destination)10 TextMessage (jakarta.jms.TextMessage)9 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)8 JMSException (jakarta.jms.JMSException)3 Message (jakarta.jms.Message)3 QueueSender (jakarta.jms.QueueSender)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 Message (org.springframework.messaging.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)1 MessageNotWriteableException (jakarta.jms.MessageNotWriteableException)1 ObjectMessage (jakarta.jms.ObjectMessage)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1