use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyUsesMessageConverterForPayload.
@Test
public void replyUsesMessageConverterForPayload() throws JMSException {
Session session = mock(Session.class);
MessageConverter messageConverter = mock(MessageConverter.class);
given(messageConverter.toMessage("Response", session)).willReturn(new StubTextMessage("Response"));
Message<String> result = MessageBuilder.withPayload("Response").build();
MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
listener.setMessageConverter(messageConverter);
jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
verify(messageConverter, times(1)).toMessage("Response", session);
assertThat(replyMessage).as("reply should never be null").isNotNull();
assertThat(((TextMessage) replyMessage).getText()).isEqualTo("Response");
}
use of jakarta.jms.TextMessage 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;
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyWithCustomTimeToLive.
@Test
public void replyWithCustomTimeToLive() 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();
settings.setTimeToLive(6000);
listener.setResponseQosSettings(settings);
listener.onMessage(mock(jakarta.jms.Message.class), session);
verify(session).createQueue("queueOut");
verify(session).createTextMessage("Response");
verify(messageProducer).send(responseMessage, jakarta.jms.Message.DEFAULT_DELIVERY_MODE, jakarta.jms.Message.DEFAULT_PRIORITY, 6000);
verify(messageProducer).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toTextMessageWithObject.
@Test
void toTextMessageWithObject() throws Exception {
converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class);
Date toBeMarshalled = new Date();
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(textMessageMock).setStringProperty("__typeid__", Date.class.getName());
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method fromTextMessageAsObject.
@Test
void fromTextMessageAsObject() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
String text = "{\"foo\":\"bar\"}";
given(textMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(textMessageMock.getText()).willReturn(text);
Object result = converter.fromMessage(textMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
Aggregations