From d3c2fdc0a4b2bcc7154b19560268d99e354b1541 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 20 May 2008 17:56:48 +0000 Subject: [PATCH] Added namespace support for the element (INT-168). --- .../config/IntegrationNamespaceHandler.java | 2 + .../config/spring-integration-core-1.0.xsd | 13 ++ .../router/RouterMessageHandlerAdapter.java | 10 +- .../router/config/RouterParser.java | 51 +++++ .../RouterMessageHandlerAdapterTests.java | 204 ++++++++++++++---- .../router/config/RouterParserTests.java | 52 +++++ .../router/config/SplitterParserTests.java | 2 +- .../integration/router/config/TestRouter.java | 34 +++ .../router/config/routerParserTests.xml | 24 +++ 9 files changed, 346 insertions(+), 46 deletions(-) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/router/config/RouterParser.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterParserTests.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/router/config/TestRouter.java create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/router/config/routerParserTests.xml diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java index 8224d6f8f1..fd28191d4c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java @@ -34,6 +34,7 @@ import org.springframework.integration.channel.config.PriorityChannelParser; import org.springframework.integration.channel.config.QueueChannelParser; import org.springframework.integration.channel.config.RendezvousChannelParser; import org.springframework.integration.channel.config.ThreadLocalChannelParser; +import org.springframework.integration.router.config.RouterParser; import org.springframework.integration.router.config.SplitterParser; import org.springframework.util.ClassUtils; @@ -67,6 +68,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("target-endpoint", new TargetEndpointParser()); registerBeanDefinitionParser("handler", new HandlerParser()); registerBeanDefinitionParser("handler-chain", new HandlerParser()); + registerBeanDefinitionParser("router", new RouterParser()); registerBeanDefinitionParser("splitter", new SplitterParser()); registerBeanDefinitionParser("aggregator", new AggregatorParser()); Map> parserMappings = this.loadAdapterParserMappings(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd index bc19a253dd..93e7b7dee5 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/spring-integration-core-1.0.xsd @@ -281,6 +281,19 @@ + + + + + Defines a Router. + + + + + + + + diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/RouterMessageHandlerAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/router/RouterMessageHandlerAdapter.java index d7937c0888..928c7fe69e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/router/RouterMessageHandlerAdapter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/RouterMessageHandlerAdapter.java @@ -49,6 +49,11 @@ public class RouterMessageHandlerAdapter extends AbstractMessageHandlerAdapter i } } + public RouterMessageHandlerAdapter(Object object, String methodName) { + this.setObject(object); + this.setMethodName(methodName); + } + public void setChannelRegistry(ChannelRegistry channelRegistry) { this.channelRegistry = channelRegistry; @@ -60,7 +65,10 @@ public class RouterMessageHandlerAdapter extends AbstractMessageHandlerAdapter i if (target != null && this.channelRegistry != null && (target instanceof ChannelRegistryAware)) { ((ChannelRegistryAware) target).setChannelRegistry(this.channelRegistry); } - this.setMessageMapper(new AnnotationMethodMessageMapper(this.getMethod())); + Method method = this.getMethod(); + if (method != null) { + this.setMessageMapper(new AnnotationMethodMessageMapper(method)); + } } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/router/config/RouterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/router/config/RouterParser.java new file mode 100644 index 0000000000..d23d1b3dc0 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/router/config/RouterParser.java @@ -0,0 +1,51 @@ +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.router.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.integration.ConfigurationException; +import org.springframework.integration.router.RouterMessageHandlerAdapter; +import org.springframework.util.StringUtils; + +/** + * Parser for the <router/> element. + * + * @author Mark Fisher + */ +public class RouterParser extends AbstractSingleBeanDefinitionParser { + + @Override + protected Class getBeanClass(Element element) { + return RouterMessageHandlerAdapter.class; + } + + @Override + protected void doParse(Element element, BeanDefinitionBuilder builder) { + String ref = element.getAttribute("ref"); + String methodName = element.getAttribute("method"); + if (!StringUtils.hasText(ref) || !StringUtils.hasText(methodName)) { + throw new ConfigurationException( + "The 'ref' and 'method' attributes are both required."); + } + builder.addConstructorArgReference(ref); + builder.addConstructorArgValue(methodName); + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/RouterMessageHandlerAdapterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/RouterMessageHandlerAdapterTests.java index 132f6faa29..4af9f84e15 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/RouterMessageHandlerAdapterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/RouterMessageHandlerAdapterTests.java @@ -23,8 +23,6 @@ import static org.junit.Assert.assertNull; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.junit.Test; @@ -46,10 +44,21 @@ import org.springframework.integration.message.StringMessage; public class RouterMessageHandlerAdapterTests { @Test - public void testChannelNameResolutionByPayload() throws Exception { + public void testChannelNameResolutionByPayloadConfiguredByMethodReference() throws Exception { SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestChannelNameResolutionByPayload(adapter); + } + + @Test + public void testChannelNameResolutionByPayloadConfiguredByMethodName() { + SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload"); + this.doTestChannelNameResolutionByPayload(adapter); + } + + private void doTestChannelNameResolutionByPayload(RouterMessageHandlerAdapter adapter) { Message message = new GenericMessage("123", "bar"); QueueChannel barChannel = new QueueChannel(); ChannelRegistry channelRegistry = new DefaultChannelRegistry(); @@ -121,10 +130,21 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testChannelNameResolutionByMessage() throws Exception { + public void testChannelNameResolutionByMessageConfiguredByMethodReference() throws Exception { SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestChannelNameResolutionByMessage(adapter); + } + + @Test + public void testChannelNameResolutionByMessageConfiguredByMethodName() { + SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage"); + this.doTestChannelNameResolutionByMessage(adapter); + } + + private void doTestChannelNameResolutionByMessage(RouterMessageHandlerAdapter adapter) { Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -151,15 +171,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testChannelInstanceResolutionByPayload() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testChannelInstanceResolutionByPayloadConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestChannelInstanceResolutionByPayload(adapter, channelRegistry); + } + + @Test + public void testChannelInstanceResolutionByPayloadConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload"); + this.doTestChannelInstanceResolutionByPayload(adapter, channelRegistry); + } + + private void doTestChannelInstanceResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -181,15 +213,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testChannelInstanceResolutionByMessage() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testChannelInstanceResolutionByMessageConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestChannelInstanceResolutionByMessage(adapter, channelRegistry); + } + + @Test + public void testChannelInstanceResolutionByMessageConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage"); + this.doTestChannelInstanceResolutionByMessage(adapter, channelRegistry); + } + + private void doTestChannelInstanceResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -211,15 +255,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelNameResolutionByPayload() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelNameResolutionByPayloadConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelNameResolutionByPayload(adapter, channelRegistry); + } + + @Test + public void testMultiChannelNameResolutionByPayloadConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload"); + this.doTestMultiChannelNameResolutionByPayload(adapter, channelRegistry); + } + + private void doTestMultiChannelNameResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -247,15 +303,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelNameResolutionByMessage() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelNameResolutionByMessageConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelNameResolutionByMessage(adapter, channelRegistry); + } + + @Test + public void testMultiChannelNameResolutionByMessageConfiguredByMethodName() throws Exception { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage"); + this.doTestMultiChannelNameResolutionByMessage(adapter, channelRegistry); + } + + private void doTestMultiChannelNameResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -283,15 +351,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelNameArrayResolutionByMessage() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelNameArrayResolutionByMessageConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelNameArrayResolutionByMessage(adapter, channelRegistry); + } + + @Test + public void testMultiChannelNameArrayResolutionByMessageConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessageToArray"); + this.doTestMultiChannelNameArrayResolutionByMessage(adapter, channelRegistry); + } + + private void doTestMultiChannelNameArrayResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -319,15 +399,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelListResolutionByPayload() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelListResolutionByPayloadConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelListResolutionByPayload(adapter, channelRegistry); + } + + @Test + public void testMultiChannelListResolutionByPayloadConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload"); + this.doTestMultiChannelListResolutionByPayload(adapter, channelRegistry); + } + + private void doTestMultiChannelListResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -355,15 +447,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelListResolutionByMessage() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelListResolutionByMessageConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelListResolutionByMessage(adapter, channelRegistry); + } + + @Test + public void testMultiChannelListResolutionByMessageConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage"); + this.doTestMultiChannelListResolutionByMessage(adapter, channelRegistry); + } + + private void doTestMultiChannelListResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -391,15 +495,27 @@ public class RouterMessageHandlerAdapterTests { } @Test - public void testMultiChannelArrayResolutionByMessage() throws Exception { - QueueChannel fooChannel = new QueueChannel(); - QueueChannel barChannel = new QueueChannel(); + public void testMultiChannelArrayResolutionByMessageConfiguredByMethodReference() throws Exception { ChannelRegistry channelRegistry = new DefaultChannelRegistry(); - channelRegistry.registerChannel("foo-channel", fooChannel); - channelRegistry.registerChannel("bar-channel", barChannel); MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class); RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod); + this.doTestMultiChannelArrayResolutionByMessage(adapter, channelRegistry); + } + + @Test + public void testMultiChannelArrayResolutionByMessageConfiguredByMethodName() { + ChannelRegistry channelRegistry = new DefaultChannelRegistry(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry); + RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessageToArray"); + this.doTestMultiChannelArrayResolutionByMessage(adapter, channelRegistry); + } + + private void doTestMultiChannelArrayResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) { + QueueChannel fooChannel = new QueueChannel(); + QueueChannel barChannel = new QueueChannel(); + channelRegistry.registerChannel("foo-channel", fooChannel); + channelRegistry.registerChannel("bar-channel", barChannel); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterParserTests.java new file mode 100644 index 0000000000..e41af39ea2 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterParserTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.router.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; + +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.message.Message; +import org.springframework.integration.message.StringMessage; + +/** + * @author Mark Fisher + */ +public class RouterParserTests { + + @Test + public void testRouter() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "routerParserTests.xml", this.getClass()); + context.start(); + MessageChannel input = (MessageChannel) context.getBean("input"); + MessageChannel output1 = (MessageChannel) context.getBean("output1"); + MessageChannel output2 = (MessageChannel) context.getBean("output2"); + input.send(new StringMessage("1")); + Message result1 = output1.receive(1000); + assertEquals("1", result1.getPayload()); + assertNull(output2.receive(0)); + input.send(new StringMessage("2")); + Message result2 = output2.receive(1000); + assertEquals("2", result2.getPayload()); + assertNull(output1.receive(0)); + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java index 264d542e25..c8563543b4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java @@ -32,7 +32,7 @@ import org.springframework.integration.message.StringMessage; public class SplitterParserTests { @Test - public void test() { + public void testSplitter() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "splitterParserTests.xml", this.getClass()); context.start(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestRouter.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestRouter.java new file mode 100644 index 0000000000..21f5ead1c0 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/TestRouter.java @@ -0,0 +1,34 @@ +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.router.config; + +/** + * @author Mark Fisher + */ +public class TestRouter { + + public String route(int input) { + if (input == 1) { + return "output1"; + } + if (input == 2) { + return "output2"; + } + return null; + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/routerParserTests.xml b/spring-integration-core/src/test/java/org/springframework/integration/router/config/routerParserTests.xml new file mode 100644 index 0000000000..511a378aed --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/routerParserTests.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + +