Search in sources :

Example 36 with TextMessage

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

the class MessageListenerAdapterTests method testWhenTheAdapterItselfIsTheDelegate.

@Test
void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    // TextMessage contents must be unwrapped...
    given(textMessage.getText()).willReturn(TEXT);
    StubMessageListenerAdapter adapter = new StubMessageListenerAdapter();
    adapter.onMessage(textMessage);
    assertThat(adapter.wasCalled()).isTrue();
}
Also used : TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 37 with TextMessage

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

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied.

@Test
void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
    final TextMessage sentTextMessage = mock(TextMessage.class);
    final Session session = mock(Session.class);
    ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
    given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
    final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected Object extractMessage(Message message) {
            return message;
        }
    };
    adapter.setMessageConverter(null);
    assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> adapter.onMessage(sentTextMessage, session)).withCauseExactlyInstanceOf(MessageConversionException.class);
}
Also used : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) ObjectMessage(jakarta.jms.ObjectMessage) TextMessage(jakarta.jms.TextMessage) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 38 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyPayloadToQueue.

@Test
public void replyPayloadToQueue() throws JMSException {
    Session session = mock(Session.class);
    Queue replyDestination = mock(Queue.class);
    given(session.createQueue("queueOut")).willReturn(replyDestination);
    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", "replyPayloadToQueue", Message.class);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session).createQueue("queueOut");
    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 39 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyWithFullQoS.

@Test
public void replyWithFullQoS() throws JMSException {
    Session session = mock(Session.class);
    Queue replyDestination = mock(Queue.class);
    given(session.createQueue("queueOut")).willReturn(replyDestination);
    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", "replyPayloadToQueue", Message.class);
    QosSettings settings = new QosSettings(DeliveryMode.NON_PERSISTENT, 6, 6000);
    listener.setResponseQosSettings(settings);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session).createQueue("queueOut");
    verify(session).createTextMessage("Response");
    verify(messageProducer).send(responseMessage, DeliveryMode.NON_PERSISTENT, 6, 6000);
    verify(messageProducer).close();
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(jakarta.jms.TextMessage) QosSettings(org.springframework.jms.support.QosSettings) 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 40 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyJacksonPojoAndJsonView.

@Test
public void replyJacksonPojoAndJsonView() throws JMSException {
    TextMessage reply = testReplyWithJackson("replyJacksonPojoAndJsonView", "{\"name\":\"Response\"}");
    verify(reply, never()).setObjectProperty("foo", "bar");
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TextMessage (jakarta.jms.TextMessage)54 Test (org.junit.jupiter.api.Test)47 StubTextMessage (org.springframework.jms.StubTextMessage)22 Session (jakarta.jms.Session)20 MessageProducer (jakarta.jms.MessageProducer)13 Message (jakarta.jms.Message)12 Queue (jakarta.jms.Queue)10 ObjectMessage (jakarta.jms.ObjectMessage)9 Message (org.springframework.messaging.Message)9 BytesMessage (jakarta.jms.BytesMessage)8 Destination (jakarta.jms.Destination)7 QueueSession (jakarta.jms.QueueSession)7 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)5 JMSException (jakarta.jms.JMSException)4 QueueSender (jakarta.jms.QueueSender)4 MessageConsumer (jakarta.jms.MessageConsumer)3 HashMap (java.util.HashMap)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 QosSettings (org.springframework.jms.support.QosSettings)3 ConnectionFactory (jakarta.jms.ConnectionFactory)2