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();
}
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");
}
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);
}
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();
}
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");
}
Aggregations