use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyPayloadNoDestination.
@Test
public void replyPayloadNoDestination() 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("Response")).willReturn(responseMessage);
given(session.createProducer(replyDestination)).willReturn(messageProducer);
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadNoDestination", Message.class);
listener.setDefaultResponseDestination(replyDestination);
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.Session in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method exceptionInListener.
@Test
public void exceptionInListener() {
jakarta.jms.Message message = new StubTextMessage("foo");
Session session = mock(Session.class);
MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class);
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(message, session)).havingCause().isExactlyInstanceOf(IllegalArgumentException.class).withMessage("Expected test exception");
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method exceptionInInvocation.
@Test
public void exceptionInInvocation() {
jakarta.jms.Message message = new StubTextMessage("foo");
Session session = mock(Session.class);
MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class);
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(message, session)).withCauseExactlyInstanceOf(MessageConversionException.class);
}
use of jakarta.jms.Session 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.Session 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;
}
Aggregations