use of jakarta.jms.JMSException 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);
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsTemplateTests method testExceptionStackTrace.
@Test
void testExceptionStackTrace() {
JMSException jmsEx = new JMSException("could not connect");
Exception innerEx = new Exception("host not found");
jmsEx.setLinkedException(innerEx);
JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx);
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
springJmsEx.printStackTrace(out);
String trace = sw.toString();
assertThat(trace.indexOf("host not found") > 0).as("inner jms exception not found").isTrue();
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertAndSendCustomJmsMessageConverter.
@Test
public void convertAndSendCustomJmsMessageConverter() throws JMSException {
this.messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
@Override
public jakarta.jms.Message toMessage(Object object, Session session) throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
throw new org.springframework.jms.support.converter.MessageConversionException("Test exception");
}
});
this.messagingTemplate.convertAndSend("myQueue", "msg to convert");
verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
assertThatExceptionOfType(org.springframework.messaging.converter.MessageConversionException.class).isThrownBy(() -> this.messageCreator.getValue().createMessage(mock(Session.class))).withMessageContaining("Test exception");
}
Aggregations