use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsTemplateTests method testConverter.
@Test
void testConverter() throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
given(this.session.createTextMessage("Hello world")).willReturn(textMessage);
template.convertAndSend(this.queue, s);
verify(messageProducer).send(textMessage);
verify(messageProducer).close();
if (useTransactedTemplate()) {
verify(this.session).commit();
}
verify(this.session).close();
verify(this.connection).close();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException.
@Test
void testWithResponsiveMessageDelegateDoesNotSendReturnTextMessageWhenSessionSupplied_AndListenerMethodThrowsException() throws Exception {
final TextMessage message = mock(TextMessage.class);
final QueueSession session = mock(QueueSession.class);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
willThrow(new IllegalArgumentException("Doe!")).given(delegate).handleMessage(message);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> adapter.onMessage(message, session));
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MessageListenerAdapterTests method testRainyDayWithNoApplicableHandlingMethods.
@Test
void testRainyDayWithNoApplicableHandlingMethods() throws Exception {
TextMessage textMessage = mock(TextMessage.class);
// TextMessage contents must be unwrapped...
given(textMessage.getText()).willReturn(TEXT);
StubMessageListenerAdapter adapter = new StubMessageListenerAdapter();
adapter.setDefaultListenerMethod("walnutsRock");
adapter.onMessage(textMessage);
assertThat(adapter.wasCalled()).isFalse();
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method fromTextMessage.
@Test
public void fromTextMessage() throws Exception {
TextMessage textMessageMock = mock(TextMessage.class);
Object unmarshalled = new Object();
String text = "foo";
given(textMessageMock.getText()).willReturn(text);
given(unmarshallerMock.unmarshal(isA(Source.class))).willReturn(unmarshalled);
Object result = converter.fromMessage(textMessageMock);
assertThat(unmarshalled).as("Invalid result").isEqualTo(result);
}
use of jakarta.jms.TextMessage in project spring-framework by spring-projects.
the class JmsTemplateTests method doTestJmsException.
protected void doTestJmsException(JMSException original, Class<? extends JmsException> thrownExceptionClass) throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
reset(this.session);
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
given(this.session.createTextMessage("Hello world")).willReturn(textMessage);
willThrow(original).given(messageProducer).send(textMessage);
assertThatExceptionOfType(thrownExceptionClass).isThrownBy(() -> template.convertAndSend(this.queue, s)).withCause(original);
verify(messageProducer).close();
verify(this.session).close();
verify(this.connection).close();
}
Aggregations