use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class ErrorMessageExceptionTypeRouterTests method noMatchAndNoDefaultChannel.
@Test
public void noMatchAndNoDefaultChannel() {
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(MessageDeliveryException.class.getName(), "messageDeliveryExceptionChannel");
router.setResolutionRequired(true);
router.setBeanName("fooRouter");
try {
router.handleMessage(message);
fail("MessageDeliveryException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), containsString("'fooRouter'"));
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestChannelNameResolutionByMessage.
private void doTestChannelNameResolutionByMessage(MethodInvokingRouter router) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
TestChannelResolver channelResolver = new TestChannelResolver();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1 = fooChannel.receive(0);
assertNotNull(result1);
assertEquals("foo", result1.getPayload());
router.handleMessage(barMessage);
Message<?> result2 = barChannel.receive(0);
assertNotNull(result2);
assertEquals("bar", result2.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestMultiChannelArrayResolutionByMessage.
private void doTestMultiChannelArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1a = fooChannel.receive(0);
Message<?> result1b = barChannel.receive(0);
assertNotNull(result1a);
assertEquals("foo", result1a.getPayload());
assertNotNull(result1b);
assertEquals("foo", result1b.getPayload());
router.handleMessage(barMessage);
Message<?> result2a = fooChannel.receive(0);
Message<?> result2b = barChannel.receive(0);
assertNotNull(result2a);
assertEquals("bar", result2a.getPayload());
assertNotNull(result2b);
assertEquals("bar", result2b.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestMultiChannelNameArrayResolutionByMessage.
private void doTestMultiChannelNameArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1a = fooChannel.receive(0);
assertNotNull(result1a);
assertEquals("foo", result1a.getPayload());
Message<?> result1b = barChannel.receive(0);
assertNotNull(result1b);
assertEquals("foo", result1b.getPayload());
router.handleMessage(barMessage);
Message<?> result2a = fooChannel.receive(0);
assertNotNull(result2a);
assertEquals("bar", result2a.getPayload());
Message<?> result2b = barChannel.receive(0);
assertNotNull(result2b);
assertEquals("bar", result2b.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
use of org.springframework.messaging.MessageDeliveryException in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method doTestMultiChannelNameResolutionByMessage.
private void doTestMultiChannelNameResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelResolver.addChannel("foo-channel", fooChannel);
channelResolver.addChannel("bar-channel", barChannel);
router.setChannelResolver(channelResolver);
Message<String> fooMessage = new GenericMessage<String>("foo");
Message<String> barMessage = new GenericMessage<String>("bar");
Message<String> badMessage = new GenericMessage<String>("bad");
router.handleMessage(fooMessage);
Message<?> result1a = fooChannel.receive(0);
assertNotNull(result1a);
assertEquals("foo", result1a.getPayload());
Message<?> result1b = barChannel.receive(0);
assertNotNull(result1b);
assertEquals("foo", result1b.getPayload());
router.handleMessage(barMessage);
Message<?> result2a = fooChannel.receive(0);
assertNotNull(result2a);
assertEquals("bar", result2a.getPayload());
Message<?> result2b = barChannel.receive(0);
assertNotNull(result2b);
assertEquals("bar", result2b.getPayload());
try {
router.handleMessage(badMessage);
fail();
} catch (MessageDeliveryException e) {
/* Success */
}
}
Aggregations