Search in sources :

Example 41 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyPayloadToDestination.

@Test
public void replyPayloadToDestination() throws JMSException {
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage("Response")).willReturn(responseMessage);
    given(session.createProducer(sharedReplyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToDestination", Message.class);
    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) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 42 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyJackson.

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

Example 43 with TextMessage

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

the class MessagingMessageListenerAdapterTests method buildMessageWithStandardMessage.

@Test
public void buildMessageWithStandardMessage() throws JMSException {
    Destination replyTo = new Destination() {
    };
    Message<String> result = MessageBuilder.withPayload("Response").setHeader("foo", "bar").setHeader(JmsHeaders.TYPE, "msg_type").setHeader(JmsHeaders.REPLY_TO, replyTo).build();
    Session session = mock(Session.class);
    given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
    MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
    jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
    verify(session).createTextMessage("Response");
    assertThat(replyMessage).as("reply should never be null").isNotNull();
    assertThat(((TextMessage) replyMessage).getText()).isEqualTo("Response");
    assertThat(replyMessage.getStringProperty("foo")).as("custom header not copied").isEqualTo("bar");
    assertThat(replyMessage.getJMSType()).as("type header not copied").isEqualTo("msg_type");
    assertThat(replyMessage.getJMSReplyTo()).as("replyTo header not copied").isEqualTo(replyTo);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 44 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyPayloadToTopic.

@Test
public void replyPayloadToTopic() throws JMSException {
    Session session = mock(Session.class);
    Topic replyDestination = mock(Topic.class);
    given(session.createTopic("topicOut")).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", "replyPayloadToTopic", Message.class);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session).createTopic("topicOut");
    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) Topic(jakarta.jms.Topic) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 45 with TextMessage

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

the class MessagingMessageListenerAdapterTests method replyJacksonMessageAndJsonView.

@Test
public void replyJacksonMessageAndJsonView() throws JMSException {
    TextMessage reply = testReplyWithJackson("replyJacksonMessageAndJsonView", "{\"name\":\"Response\"}");
    verify(reply).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