use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method assertTextMessage.
private void assertTextMessage(MessageCreator messageCreator) {
try {
TextMessage jmsMessage = createTextMessage(messageCreator);
assertThat(jmsMessage.getText()).as("Wrong body message").isEqualTo("Hello");
assertThat(jmsMessage.getStringProperty("foo")).as("Invalid foo property").isEqualTo("bar");
} catch (JMSException e) {
throw new IllegalStateException("Wrong text message", e);
}
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertAndSendPayload.
@Test
public void convertAndSendPayload() throws JMSException {
Destination destination = new Destination() {
};
this.messagingTemplate.convertAndSend(destination, "my Payload");
verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
assertThat(textMessage.getText()).isEqualTo("my Payload");
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsNamespaceHandlerTests method testListeners.
@Test
public void testListeners() throws Exception {
TestBean testBean1 = context.getBean("testBean1", TestBean.class);
TestBean testBean2 = context.getBean("testBean2", TestBean.class);
TestMessageListener testBean3 = context.getBean("testBean3", TestMessageListener.class);
assertThat(testBean1.getName()).isNull();
assertThat(testBean2.getName()).isNull();
assertThat(testBean3.message).isNull();
TextMessage message1 = mock(TextMessage.class);
given(message1.getText()).willReturn("Test1");
MessageListener listener1 = getListener("listener1");
listener1.onMessage(message1);
assertThat(testBean1.getName()).isEqualTo("Test1");
TextMessage message2 = mock(TextMessage.class);
given(message2.getText()).willReturn("Test2");
MessageListener listener2 = getListener("listener2");
listener2.onMessage(message2);
assertThat(testBean2.getName()).isEqualTo("Test2");
TextMessage message3 = mock(TextMessage.class);
MessageListener listener3 = getListener(DefaultMessageListenerContainer.class.getName() + "#0");
listener3.onMessage(message3);
assertThat(testBean3.message).isSameAs(message3);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied.
@Test
void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
// Reply-To is queried when response is being created...
given(sentTextMessage.getJMSReplyTo()).willReturn(null);
TextMessage responseTextMessage = mock(TextMessage.class);
final QueueSession session = mock(QueueSession.class);
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
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;
}
};
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> adapter.onMessage(sentTextMessage, session)).withCauseExactlyInstanceOf(InvalidDestinationException.class);
verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
verify(delegate).handleMessage(sentTextMessage);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException.
@Test
void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
Queue destination = mock(Queue.class);
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
// Reply-To is queried when response is being created...
given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
TextMessage responseTextMessage = mock(TextMessage.class);
MessageProducer messageProducer = mock(MessageProducer.class);
willThrow(new JMSException("Doe!")).given(messageProducer).send(responseTextMessage);
final QueueSession session = mock(QueueSession.class);
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
given(session.createProducer(destination)).willReturn(messageProducer);
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;
}
};
assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> adapter.onMessage(sentTextMessage, session)).withCauseExactlyInstanceOf(JMSException.class);
verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
verify(messageProducer).close();
verify(delegate).handleMessage(sentTextMessage);
}
Aggregations