use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWhenTheAdapterItselfIsTheDelegate.
@Test
void testWhenTheAdapterItselfIsTheDelegate() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
StubMessageListenerAdapter adapter = new StubMessageListenerAdapter();
adapter.onMessage(textMessage);
assertThat(adapter.wasCalled()).isTrue();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied.
@Test
void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
final Session session = mock(Session.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
adapter.setMessageConverter(null);
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> adapter.onMessage(sentTextMessage, session)).withCauseExactlyInstanceOf(MessageConversionException.class);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyPayloadToQueue.
@Test
public void replyPayloadToQueue() 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);
listener.onMessage(mock(jakarta.jms.Message.class), session);
verify(session).createQueue("queueOut");
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 replyWithFullQoS.
@Test
public void replyWithFullQoS() 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(DeliveryMode.NON_PERSISTENT, 6, 6000);
listener.setResponseQosSettings(settings);
listener.onMessage(mock(jakarta.jms.Message.class), session);
verify(session).createQueue("queueOut");
verify(session).createTextMessage("Response");
verify(messageProducer).send(responseMessage, DeliveryMode.NON_PERSISTENT, 6, 6000);
verify(messageProducer).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyJacksonPojoAndJsonView.
@Test
public void replyJacksonPojoAndJsonView() throws JMSException {
TextMessage reply = testReplyWithJackson("replyJacksonPojoAndJsonView", "{\"name\":\"Response\"}");
verify(reply, never()).setObjectProperty("foo", "bar");
}
Aggregations