use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class MessageSourcePollingTemplateTests method testAckNack.
@Test
public void testAckNack() {
AcknowledgmentCallback callback = mock(AcknowledgmentCallback.class);
given(callback.isAutoAck()).willReturn(true);
MessageSource<?> source = () -> new GenericMessage<>("foo", Collections.singletonMap(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, callback));
MessageSourcePollingTemplate template = new MessageSourcePollingTemplate(source);
template.poll(h -> {
});
verify(callback).acknowledge(Status.ACCEPT);
try {
template.poll(h -> {
throw new RuntimeException("expected");
});
fail("expected exception");
} catch (MessageHandlingException e) {
assertThat(e.getCause().getMessage(), equalTo("expected"));
}
verify(callback).acknowledge(Status.REJECT);
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class CorrelatingMessageHandlerTests method bufferCompletesWithException.
@Test
public void bufferCompletesWithException() throws Exception {
doAnswer(new ThrowsException(new RuntimeException("Planned test exception"))).when(processor).processMessageGroup(isA(SimpleMessageGroup.class));
String correlationKey = "key";
Message<?> message1 = testMessage(correlationKey, 1, 2);
Message<?> message2 = testMessage(correlationKey, 2, 2);
when(correlationStrategy.getCorrelationKey(isA(Message.class))).thenReturn(correlationKey);
handler.setExpireGroupsUponCompletion(true);
handler.handleMessage(message1);
try {
handler.handleMessage(message2);
fail("Expected MessageHandlingException");
} catch (MessageHandlingException e) {
assertEquals(0, store.getMessageGroup(correlationKey).size());
}
verify(correlationStrategy).getCorrelationKey(message1);
verify(correlationStrategy).getCorrelationKey(message2);
verify(processor).processMessageGroup(isA(SimpleMessageGroup.class));
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method fallbackToErrorMessageType.
@Test
public void fallbackToErrorMessageType() {
Message<?> failedMessage = new GenericMessage<String>("foo");
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
RuntimeException middleCause = new RuntimeException(rootCause);
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
ErrorMessage message = new ErrorMessage(error);
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
router.setBeanFactory(beanFactory);
router.setApplicationContext(TestUtils.createTestApplicationContext());
router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(messageHandlingExceptionChannel.receive(1000));
assertNull(runtimeExceptionChannel.receive(0));
assertNull(illegalArgumentChannel.receive(0));
assertNull(defaultChannel.receive(0));
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method exceptionPayloadButNotErrorMessage.
@Test
public void exceptionPayloadButNotErrorMessage() {
Message<?> failedMessage = new GenericMessage<String>("foo");
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
RuntimeException middleCause = new RuntimeException(rootCause);
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
Message<?> message = new GenericMessage<Exception>(error);
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
router.setBeanFactory(beanFactory);
router.setApplicationContext(TestUtils.createTestApplicationContext());
router.setChannelMapping(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
router.setChannelMapping(RuntimeException.class.getName(), "runtimeExceptionChannel");
router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(illegalArgumentChannel.receive(1000));
assertNull(defaultChannel.receive(0));
assertNull(runtimeExceptionChannel.receive(0));
assertNull(messageHandlingExceptionChannel.receive(0));
}
use of org.springframework.messaging.MessageHandlingException in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method mostSpecificCause.
@Test
public void mostSpecificCause() {
Message<?> failedMessage = new GenericMessage<String>("foo");
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
RuntimeException middleCause = new RuntimeException(rootCause);
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
ErrorMessage message = new ErrorMessage(error);
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
router.setBeanFactory(beanFactory);
router.setApplicationContext(TestUtils.createTestApplicationContext());
router.setChannelMapping(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
router.setChannelMapping(RuntimeException.class.getName(), "runtimeExceptionChannel");
router.setChannelMapping(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(illegalArgumentChannel.receive(1000));
assertNull(defaultChannel.receive(0));
assertNull(runtimeExceptionChannel.receive(0));
assertNull(messageHandlingExceptionChannel.receive(0));
}
Aggregations