use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method testClassAsKeyResolution.
@Test
public void testClassAsKeyResolution() {
QueueChannel stringsChannel = new QueueChannel();
QueueChannel numbersChannel = new QueueChannel();
TestChannelResolver channelResolver = new TestChannelResolver();
channelResolver.addChannel("stringsChannel", stringsChannel);
channelResolver.addChannel("numbersChannel", numbersChannel);
MethodInvokingRouter router = new MethodInvokingRouter(new ClassAsKeyTestBean());
router.setChannelResolver(channelResolver);
router.setChannelMapping(String.class.getName(), "stringsChannel");
router.setChannelMapping(Integer.class.getName(), "numbersChannel");
Message<?> message = new GenericMessage<>("bar");
router.handleMessage(message);
Message<?> replyMessage = stringsChannel.receive(10000);
assertNotNull(replyMessage);
assertEquals(message, replyMessage);
message = new GenericMessage<>(11);
router.handleMessage(message);
replyMessage = numbersChannel.receive(10000);
assertNotNull(replyMessage);
assertEquals(message, replyMessage);
}
use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method channelNameResolutionByPayloadConfiguredByMethodName.
@Test
public void channelNameResolutionByPayloadConfiguredByMethodName() {
QueueChannel barChannel = new QueueChannel();
TestChannelResolver channelResolver = new TestChannelResolver();
channelResolver.addChannel("bar-channel", barChannel);
SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routePayload");
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("bar");
router.handleMessage(message);
Message<?> replyMessage = barChannel.receive();
assertNotNull(replyMessage);
assertEquals(message, replyMessage);
}
use of org.springframework.integration.channel.TestChannelResolver 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.integration.channel.TestChannelResolver in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method multiChannelNameResolutionByMessageConfiguredByMethodName.
@Test
public void multiChannelNameResolutionByMessageConfiguredByMethodName() throws Exception {
TestChannelResolver channelResolver = new TestChannelResolver();
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessage");
this.doTestMultiChannelNameResolutionByMessage(router, channelResolver);
}
use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.
the class MethodInvokingRouterTests method multiChannelNameArrayResolutionByMessageConfiguredByMethodReference.
@Test
public void multiChannelNameArrayResolutionByMessageConfiguredByMethodReference() throws Exception {
TestChannelResolver channelResolver = new TestChannelResolver();
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class);
MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod);
this.doTestMultiChannelNameArrayResolutionByMessage(router, channelResolver);
}
Aggregations