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) 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);
verify(queueSender).send(reply);
verify(queueSender).close();
}
use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method createJmsTextMessage.
private jakarta.jms.Message createJmsTextMessage(String payload) {
try {
StubTextMessage jmsMessage = new StubTextMessage(payload);
jmsMessage.setStringProperty("foo", "bar");
return jmsMessage;
} catch (JMSException e) {
throw new IllegalStateException("Should not happen", e);
}
}
use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method createTextMessage.
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
Session mock = mock(Session.class);
given(mock.createTextMessage(any())).willAnswer((Answer<TextMessage>) invocation -> new StubTextMessage((String) invocation.getArguments()[0]));
jakarta.jms.Message message = creator.createMessage(mock);
verify(mock).createTextMessage(any());
return (TextMessage) message;
}
use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method resolveMessageHeaders.
@Test
void resolveMessageHeaders() throws JMSException {
MessagingMessageListenerAdapter listener = createDefaultInstance(MessageHeaders.class);
Session session = mock(Session.class);
StubTextMessage message = createSimpleJmsTextMessage("my payload");
message.setLongProperty("customLong", 4567L);
message.setJMSType("myMessageType");
listener.onMessage(message, session);
assertDefaultListenerMethodInvocation();
}
use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method resolveCustomHeaderNameAndPayload.
@Test
void resolveCustomHeaderNameAndPayload() 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();
}
Aggregations