use of org.springframework.messaging.support.ErrorMessage 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.support.ErrorMessage 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));
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method fallbackToNextMostSpecificCause.
@Test
public void fallbackToNextMostSpecificCause() {
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(RuntimeException.class.getName(), "runtimeExceptionChannel");
router.setChannelMapping(MessageHandlingException.class.getName(), "runtimeExceptionChannel");
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(runtimeExceptionChannel.receive(1000));
assertNull(illegalArgumentChannel.receive(0));
assertNull(defaultChannel.receive(0));
assertNull(messageHandlingExceptionChannel.receive(0));
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method fallbackToDefaultChannel.
@Test
public void fallbackToDefaultChannel() {
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.setApplicationContext(TestUtils.createTestApplicationContext());
router.setDefaultOutputChannel(defaultChannel);
router.handleMessage(message);
assertNotNull(defaultChannel.receive(1000));
assertNull(runtimeExceptionChannel.receive(0));
assertNull(illegalArgumentChannel.receive(0));
assertNull(messageHandlingExceptionChannel.receive(0));
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method testHierarchicalMapping.
@Test
public void testHierarchicalMapping() {
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
MessageHandlingException error = new MessageRejectedException(new GenericMessage<Object>("foo"), "failed", rootCause);
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(defaultChannel.receive(0));
}
Aggregations