use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method intermediateCauseHasNoMappingButMostSpecificCauseDoes.
@Test
public void intermediateCauseHasNoMappingButMostSpecificCauseDoes() {
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(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 PollingEndpointErrorHandlingTests method checkExceptionPlacedOnErrorChannel.
@SuppressWarnings("rawtypes")
@Test
public void checkExceptionPlacedOnErrorChannel() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollingEndpointErrorHandlingTests.xml", this.getClass());
PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
Message errorMessage = errorChannel.receive(5000);
assertNotNull("No error message received", errorMessage);
assertEquals("Message received was not an ErrorMessage", ErrorMessage.class, errorMessage.getClass());
context.close();
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class MessageHistoryTests method testCorrectErrorMessageAfterWrite.
@Test
public void testCorrectErrorMessageAfterWrite() {
RuntimeException payload = new RuntimeException();
ErrorMessage original = new ErrorMessage(payload);
assertNull(MessageHistory.read(original));
Message<Throwable> result1 = MessageHistory.write(original, new TestComponent(1));
assertThat(result1, instanceOf(ErrorMessage.class));
assertNotSame(original, result1);
assertSame(original.getPayload(), result1.getPayload());
MessageHistory history1 = MessageHistory.read(result1);
assertNotNull(history1);
assertEquals("testComponent-1", history1.toString());
Message<Throwable> result2 = MessageHistory.write(result1, new TestComponent(2));
assertThat(result2, instanceOf(ErrorMessage.class));
assertNotSame(original, result2);
assertNotSame(result1, result2);
assertSame(original.getPayload(), result2.getPayload());
MessageHistory history2 = MessageHistory.read(result2);
assertNotNull(history2);
assertEquals("testComponent-1,testComponent-2", history2.toString());
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class RouterTests method testExceptionTypeRouteFlow.
@Test
public void testExceptionTypeRouteFlow() {
Message<?> failedMessage = new GenericMessage<>("foo");
IllegalArgumentException rootCause = new IllegalArgumentException("bad argument");
RuntimeException middleCause = new RuntimeException(rootCause);
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
ErrorMessage message = new ErrorMessage(error);
this.exceptionTypeRouteFlowInput.send(message);
assertNotNull(this.illegalArgumentChannel.receive(1000));
assertNull(this.exceptionRouterDefaultChannel.receive(0));
assertNull(this.runtimeExceptionChannel.receive(0));
assertNull(this.messageHandlingExceptionChannel.receive(0));
}
use of org.springframework.messaging.support.ErrorMessage in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterParserTests method validateExceptionTypeRouterConfig.
@Test
public void validateExceptionTypeRouterConfig() {
inputChannel.send(new ErrorMessage(new NullPointerException()));
assertTrue(npeChannel.receive(1000).getPayload() instanceof NullPointerException);
inputChannel.send(new ErrorMessage(new IllegalArgumentException()));
assertTrue(illegalChannel.receive(1000).getPayload() instanceof IllegalArgumentException);
inputChannel.send(new ErrorMessage(new RuntimeException()));
assertTrue(defaultChannel.receive(1000).getPayload() instanceof RuntimeException);
}
Aggregations