diff --git a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/config/spring-integration-xml-1.0.xsd b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/config/spring-integration-xml-1.0.xsd index f928037b34..c30bb9ede2 100644 --- a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/config/spring-integration-xml-1.0.xsd +++ b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/config/spring-integration-xml-1.0.xsd @@ -1,9 +1,10 @@ + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:tool="http://www.springframework.org/schema/tool" + targetNamespace="http://www.springframework.org/schema/integration/xml" + elementFormDefault="qualified" attributeFormDefault="unqualified"> @@ -13,6 +14,7 @@ Defines the configuration elements for Spring Integration's XML support. + @@ -37,6 +39,7 @@ + @@ -51,6 +54,7 @@ + @@ -122,7 +126,7 @@ - Defines an XPath expression. + Defines an XPath expression. diff --git a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/router/AbstractXPathRouter.java b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/router/AbstractXPathRouter.java index 5db1dfade4..1a3b72121b 100644 --- a/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/router/AbstractXPathRouter.java +++ b/org.springframework.integration.xml/src/main/java/org/springframework/integration/xml/router/AbstractXPathRouter.java @@ -19,7 +19,7 @@ package org.springframework.integration.xml.router; import java.util.HashMap; import java.util.Map; -import org.springframework.integration.router.AbstractChannelMappingMessageRouter; +import org.springframework.integration.router.AbstractChannelNameResolvingMessageRouter; import org.springframework.integration.xml.DefaultXmlPayloadConverter; import org.springframework.integration.xml.XmlPayloadConverter; import org.springframework.xml.xpath.XPathExpression; @@ -31,7 +31,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory; * * @author Jonas Partner */ -public abstract class AbstractXPathRouter extends AbstractChannelMappingMessageRouter { +public abstract class AbstractXPathRouter extends AbstractChannelNameResolvingMessageRouter { private final XPathExpression xPathExpression; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelResolutionException.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelResolutionException.java new file mode 100644 index 0000000000..c1a0269949 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelResolutionException.java @@ -0,0 +1,46 @@ +/* + * 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.channel; + +import org.springframework.integration.message.MessagingException; + +/** + * Thrown by a ChannelResolver when it cannot resolve a channel name. + * + * @author Mark Fisher + * @see ChannelResolver + */ +public class ChannelResolutionException extends MessagingException { + + /** + * Create a new ChannelResolutionException. + * @param description the description + */ + public ChannelResolutionException(String description) { + super(description); + } + + /** + * Create a new ChannelResolutionException. + * @param description the description + * @param cause the root cause (if any) + */ + public ChannelResolutionException(String description, Throwable cause) { + super(description, cause); + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/RouterAnnotationPostProcessor.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/RouterAnnotationPostProcessor.java index d92f913970..5413ea21cd 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/RouterAnnotationPostProcessor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/annotation/RouterAnnotationPostProcessor.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.integration.annotation.Router; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.MessageConsumer; -import org.springframework.integration.router.BeanNameChannelMapping; +import org.springframework.integration.router.BeanFactoryChannelResolver; import org.springframework.integration.router.MethodInvokingRouter; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -42,7 +42,7 @@ public class RouterAnnotationPostProcessor extends AbstractMethodAnnotationPostP @Override protected MessageConsumer createConsumer(Object bean, Method method, Router annotation) { MethodInvokingRouter router = new MethodInvokingRouter(bean, method); - router.setChannelMapping(new BeanNameChannelMapping(this.beanFactoryAccessor.getBeanFactory())); + router.setChannelResolver(new BeanFactoryChannelResolver(this.beanFactoryAccessor.getBeanFactory())); String defaultOutputChannelName = annotation.defaultOutputChannel(); if (StringUtils.hasText(defaultOutputChannelName)) { MessageChannel defaultOutputChannel = this.channelRegistry.lookupChannel(defaultOutputChannelName); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RouterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RouterParser.java index 435f052832..e066d5c298 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RouterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RouterParser.java @@ -21,7 +21,7 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.router.BeanNameChannelMapping; +import org.springframework.integration.router.BeanFactoryChannelResolver; import org.springframework.integration.router.MethodInvokingRouter; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -43,11 +43,10 @@ public class RouterParser extends AbstractConsumerEndpointParser { String method = element.getAttribute(METHOD_ATTRIBUTE); builder.addConstructorArgValue(method); } - BeanDefinitionBuilder channelMappingBuilder = - BeanDefinitionBuilder.genericBeanDefinition(BeanNameChannelMapping.class); - String channelMappingBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName( - channelMappingBuilder.getBeanDefinition(), parserContext.getRegistry()); - builder.addPropertyReference("channelMapping", channelMappingBeanName); + BeanDefinitionBuilder resolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(BeanFactoryChannelResolver.class); + String resolverBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName( + resolverBuilder.getBeanDefinition(), parserContext.getRegistry()); + builder.addPropertyReference("channelResolver", resolverBeanName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel"); return builder; } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelMappingMessageRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java similarity index 76% rename from org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelMappingMessageRouter.java rename to org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java index 75a97e8927..69bad7b41a 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelMappingMessageRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java @@ -33,9 +33,9 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public abstract class AbstractChannelMappingMessageRouter extends AbstractMessageRouter implements BeanFactoryAware, InitializingBean { +public abstract class AbstractChannelNameResolvingMessageRouter extends AbstractMessageRouter implements BeanFactoryAware, InitializingBean { - private volatile ChannelMapping channelMapping; + private volatile ChannelResolver channelResolver; private volatile String prefix; @@ -44,8 +44,8 @@ public abstract class AbstractChannelMappingMessageRouter extends AbstractMessag private volatile BeanFactory beanFactory; - public void setChannelMapping(ChannelMapping channelMapping) { - this.channelMapping = channelMapping; + public void setChannelResolver(ChannelResolver channelResolver) { + this.channelResolver = channelResolver; } public void setPrefix(String prefix) { @@ -61,9 +61,9 @@ public abstract class AbstractChannelMappingMessageRouter extends AbstractMessag } public void afterPropertiesSet() { - if (this.channelMapping == null) { - Assert.notNull(beanFactory, "either a ChannelMapping or BeanFactory is required"); - this.channelMapping = new BeanNameChannelMapping(this.beanFactory); + if (this.channelResolver == null) { + Assert.notNull(beanFactory, "either a ChannelResolver or BeanFactory is required"); + this.channelResolver = new BeanFactoryChannelResolver(this.beanFactory); } } @@ -77,18 +77,18 @@ public abstract class AbstractChannelMappingMessageRouter extends AbstractMessag } for (String channelName : channelNames) { if (channelName != null) { - Assert.state(this.channelMapping != null, - "unable to resolve channels, no ChannelMapping available"); + Assert.state(this.channelResolver != null, + "unable to resolve channel names, no ChannelResolver available"); if (this.prefix != null) { channelName = this.prefix + channelName; } if (this.suffix != null) { channelName = channelName + suffix; } - MessageChannel channel = this.channelMapping.getChannel(channelName); + MessageChannel channel = this.channelResolver.resolveChannelName(channelName); if (channel == null) { throw new MessagingException(message, - "unable to resolve channel '" + channelName + "'"); + "failed to resolve channel name '" + channelName + "'"); } channels.add(channel); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractSingleChannelNameRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractSingleChannelNameRouter.java index 7ffe83f53d..9d0a4dde22 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractSingleChannelNameRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractSingleChannelNameRouter.java @@ -21,7 +21,7 @@ import org.springframework.integration.message.Message; /** * @author Mark Fisher */ -public abstract class AbstractSingleChannelNameRouter extends AbstractChannelMappingMessageRouter { +public abstract class AbstractSingleChannelNameRouter extends AbstractChannelNameResolvingMessageRouter { @Override protected final String[] resolveChannelNames(Message message) { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanFactoryChannelResolver.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanFactoryChannelResolver.java new file mode 100644 index 0000000000..73e1f62b4f --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanFactoryChannelResolver.java @@ -0,0 +1,81 @@ +/* + * 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; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.integration.channel.ChannelResolutionException; +import org.springframework.integration.channel.MessageChannel; +import org.springframework.util.Assert; + +/** + * {@link ChannelResolver} implementation based on a Spring {@link BeanFactory}. + * + *

Will lookup Spring managed beans identified by bean name, + * expecting them to be of type {@link MessageChannel}. + * + * @author Mark Fisher + * @see org.springframework.beans.factory.BeanFactory + */ +public class BeanFactoryChannelResolver implements ChannelResolver, BeanFactoryAware { + + private volatile BeanFactory beanFactory; + + + /** + * Create a new instance of the {@link BeanFactoryChannelResolver} class. + *

The BeanFactory to access must be set via setBeanFactory. + * This will happen automatically if this resolver is defined within an + * ApplicationContext thereby receiving the callback. + * @see #setBeanFactory + */ + public BeanFactoryChannelResolver() { + } + + /** + * Create a new instance of the {@link BeanFactoryChannelResolver} class. + *

Use of this constructor is redundant if this object is being created + * by a Spring IoC container as the supplied {@link BeanFactory} will be + * replaced by the {@link BeanFactory} that creates it (c.f. the + * {@link BeanFactoryAware} contract). So only use this constructor if you + * are instantiating this object explicitly rather than defining a bean. + * + * @param beanFactory the bean factory to be used to lookup {@link MessageChannel}s. + */ + public BeanFactoryChannelResolver(BeanFactory beanFactory) { + Assert.notNull(beanFactory, "BeanFactory must not be null"); + this.beanFactory = beanFactory; + } + + + public void setBeanFactory(BeanFactory beanFactory) { + this.beanFactory = beanFactory; + } + + public MessageChannel resolveChannelName(String name) { + Assert.state(this.beanFactory != null, "BeanFactory is required"); + try { + return (MessageChannel) this.beanFactory.getBean(name, MessageChannel.class); + } + catch (BeansException e) { + throw new ChannelResolutionException( + "failed to look up MessageChannel bean with name '" + name + "'", e); + } + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanNameChannelMapping.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanNameChannelMapping.java deleted file mode 100644 index 3b1daa57eb..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/BeanNameChannelMapping.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.util.Assert; - -/** - * An implementation of the ChannelMapping strategy that retrieves a - * MessageChannel instance from the {@link BeanFactory} using the provided - * name. - * - * @author Mark Fisher - */ -public class BeanNameChannelMapping implements ChannelMapping, BeanFactoryAware { - - private volatile BeanFactory beanFactory; - - - /** - * Constructor for use within a context where the BeanFactory will be - * injected via the {@link #setBeanFactory(BeanFactory)} callback method. - */ - public BeanNameChannelMapping() { - } - - /** - * Constructor for programmatic creation from within other components that - * already have access to the {@link BeanFactory}. - */ - public BeanNameChannelMapping(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - - public void setBeanFactory(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - public MessageChannel getChannel(String name) { - Assert.state(this.beanFactory != null, "beanFactory must not be null"); - return (MessageChannel) this.beanFactory.getBean(name, MessageChannel.class); - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelMapping.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelResolver.java similarity index 78% rename from org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelMapping.java rename to org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelResolver.java index 245cabce41..f3a34ca772 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelMapping.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/ChannelResolver.java @@ -19,12 +19,15 @@ package org.springframework.integration.router; import org.springframework.integration.channel.MessageChannel; /** - * Strategy for mapping from a name to a {@link MessageChannel}. + * Strategy for resolving a name to a {@link MessageChannel}. * * @author Mark Fisher */ -public interface ChannelMapping { +public interface ChannelResolver { - MessageChannel getChannel(String name); + /** + * Return the MessageChannel for the given name. + */ + MessageChannel resolveChannelName(String name); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/MethodInvokingRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/MethodInvokingRouter.java index dbdd768ac0..7a43060f85 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/MethodInvokingRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/MethodInvokingRouter.java @@ -34,7 +34,7 @@ import org.springframework.util.Assert; * method's return value may be a single MessageChannel instance, a single * String to be interpreted as a channel name, or a Collection (or Array) of * either type. If the method returns channel names, then a - * {@link ChannelMapping} is required. + * {@link ChannelResolver} is required. * * @author Mark Fisher */ @@ -42,7 +42,7 @@ public class MethodInvokingRouter extends AbstractMessageRouter implements Initi private final MessageMappingMethodInvoker invoker; - private volatile ChannelMapping channelMapping; + private volatile ChannelResolver channelResolver; public MethodInvokingRouter(Object object, Method method) { @@ -55,11 +55,11 @@ public class MethodInvokingRouter extends AbstractMessageRouter implements Initi /** - * Provide the ChannelMapping strategy to use for methods that return a - * channel name rather than a {@link MessageChannel} instance. + * Provide the {@link ChannelResolver} strategy to use for methods that + * return a channel name rather than a {@link MessageChannel} instance. */ - public void setChannelMapping(ChannelMapping channelMapping) { - this.channelMapping = channelMapping; + public void setChannelResolver(ChannelResolver channelResolver) { + this.channelResolver = channelResolver; } public void afterPropertiesSet() throws Exception { @@ -108,11 +108,11 @@ public class MethodInvokingRouter extends AbstractMessageRouter implements Initi } else if (channelOrName instanceof String) { String channelName = (String) channelOrName; - Assert.state(this.channelMapping != null, - "ChannelMapping is required for resolving channel names"); - MessageChannel channel = this.channelMapping.getChannel(channelName); + Assert.state(this.channelResolver != null, + "unable to resolve channel names, no ChannelResolver available"); + MessageChannel channel = this.channelResolver.resolveChannelName(channelName); if (channel == null) { - throw new MessagingException("unable to resolve channel '" + channelName + "'"); + throw new MessagingException("failed to resolve channel name '" + channelName + "'"); } channels.add(channel); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java index 22a0064a0d..6f4f2c6b80 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java @@ -28,7 +28,7 @@ import org.springframework.util.Assert; * A Message Router that sends Messages to a statically configured list of * recipients. The recipients are provided as a list of {@link MessageChannel} * instances. For dynamic recipient lists, consider instead using the @Router - * annotation or extending {@link AbstractChannelMappingMessageRouter}. + * annotation or extending {@link AbstractChannelNameResolvingMessageRouter}. * * @author Mark Fisher */ diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelMapping.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelResolver.java similarity index 86% rename from org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelMapping.java rename to org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelResolver.java index a769be3293..1981740fad 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelMapping.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/TestChannelResolver.java @@ -19,18 +19,18 @@ package org.springframework.integration.channel; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.integration.router.ChannelMapping; +import org.springframework.integration.router.ChannelResolver; import org.springframework.util.Assert; /** * @author Mark Fisher */ -public class TestChannelMapping implements ChannelMapping { +public class TestChannelResolver implements ChannelResolver { private final Map channels = new ConcurrentHashMap(); - public MessageChannel getChannel(String channelName) { + public MessageChannel resolveChannelName(String channelName) { return this.channels.get(channelName); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/MethodInvokingRouterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/router/MethodInvokingRouterTests.java index 5290d06a13..a6fe7e7775 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/router/MethodInvokingRouterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/MethodInvokingRouterTests.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.springframework.integration.annotation.Header; import org.springframework.integration.channel.ChannelRegistry; import org.springframework.integration.channel.ChannelRegistryAware; -import org.springframework.integration.channel.TestChannelMapping; +import org.springframework.integration.channel.TestChannelResolver; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.message.GenericMessage; @@ -47,12 +47,12 @@ public class MethodInvokingRouterTests { public void channelNameResolutionByPayloadConfiguredByMethodReference() throws Exception { QueueChannel barChannel = new QueueChannel(); barChannel.setBeanName("bar-channel"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(barChannel); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(barChannel); SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - router.setChannelMapping(channelMapping); + router.setChannelResolver(channelResolver); Message message = new GenericMessage("bar"); router.onMessage(message); Message replyMessage = barChannel.receive(); @@ -64,11 +64,11 @@ public class MethodInvokingRouterTests { public void channelNameResolutionByPayloadConfiguredByMethodName() { QueueChannel barChannel = new QueueChannel(); barChannel.setBeanName("bar-channel"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(barChannel); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(barChannel); SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routePayload"); - router.setChannelMapping(channelMapping); + router.setChannelResolver(channelResolver); Message message = new GenericMessage("bar"); router.onMessage(message); Message replyMessage = barChannel.receive(); @@ -82,13 +82,13 @@ public class MethodInvokingRouterTests { QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routeByHeader", String.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - router.setChannelMapping(channelMapping); + router.setChannelResolver(channelResolver); Message message = MessageBuilder.withPayload("bar") .setHeader("targetChannel", "foo").build(); router.onMessage(message); @@ -127,10 +127,10 @@ public class MethodInvokingRouterTests { QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -147,22 +147,22 @@ public class MethodInvokingRouterTests { @Test public void channelInstanceResolutionByPayloadConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); - SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelResolver); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestChannelInstanceResolutionByPayload(router, channelMapping); + this.doTestChannelInstanceResolutionByPayload(router, channelResolver); } @Test public void channelInstanceResolutionByPayloadConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); - SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelResolver); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routePayload"); - this.doTestChannelInstanceResolutionByPayload(router, channelMapping); + this.doTestChannelInstanceResolutionByPayload(router, channelResolver); } - private void doTestChannelInstanceResolutionByPayload(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestChannelInstanceResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) { Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -170,9 +170,9 @@ public class MethodInvokingRouterTests { QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); router.onMessage(fooMessage); Message result1 = fooChannel.receive(0); assertNotNull(result1); @@ -186,29 +186,29 @@ public class MethodInvokingRouterTests { @Test public void channelInstanceResolutionByMessageConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); - SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelResolver); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestChannelInstanceResolutionByMessage(router, channelMapping); + this.doTestChannelInstanceResolutionByMessage(router, channelResolver); } @Test public void channelInstanceResolutionByMessageConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); - SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelResolver); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessage"); - this.doTestChannelInstanceResolutionByMessage(router, channelMapping); + this.doTestChannelInstanceResolutionByMessage(router, channelResolver); } - private void doTestChannelInstanceResolutionByMessage(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestChannelInstanceResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -225,29 +225,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelNameResolutionByPayloadConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); + TestChannelResolver channelResolver = new TestChannelResolver(); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestMultiChannelNameResolutionByPayload(router, channelMapping); + this.doTestMultiChannelNameResolutionByPayload(router, channelResolver); } @Test public void multiChannelNameResolutionByPayloadConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); + TestChannelResolver channelResolver = new TestChannelResolver(); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routePayload"); - this.doTestMultiChannelNameResolutionByPayload(router, channelMapping); + this.doTestMultiChannelNameResolutionByPayload(router, channelResolver); } - private void doTestMultiChannelNameResolutionByPayload(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelNameResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -270,29 +270,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelNameResolutionByMessageConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); + TestChannelResolver channelResolver = new TestChannelResolver(); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestMultiChannelNameResolutionByMessage(router, channelMapping); + this.doTestMultiChannelNameResolutionByMessage(router, channelResolver); } @Test public void multiChannelNameResolutionByMessageConfiguredByMethodName() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); + TestChannelResolver channelResolver = new TestChannelResolver(); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessage"); - this.doTestMultiChannelNameResolutionByMessage(router, channelMapping); + this.doTestMultiChannelNameResolutionByMessage(router, channelResolver); } - private void doTestMultiChannelNameResolutionByMessage(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelNameResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -315,29 +315,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelNameArrayResolutionByMessageConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); + 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, channelMapping); + this.doTestMultiChannelNameArrayResolutionByMessage(router, channelResolver); } @Test public void multiChannelNameArrayResolutionByMessageConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); + TestChannelResolver channelResolver = new TestChannelResolver(); MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean(); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessageToArray"); - this.doTestMultiChannelNameArrayResolutionByMessage(router, channelMapping); + this.doTestMultiChannelNameArrayResolutionByMessage(router, channelResolver); } - private void doTestMultiChannelNameArrayResolutionByMessage(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelNameArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -360,29 +360,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelListResolutionByPayloadConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); Method routingMethod = testBean.getClass().getMethod("routePayload", String.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestMultiChannelListResolutionByPayload(router, channelMapping); + this.doTestMultiChannelListResolutionByPayload(router, channelResolver); } @Test public void multiChannelListResolutionByPayloadConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routePayload"); - this.doTestMultiChannelListResolutionByPayload(router, channelMapping); + this.doTestMultiChannelListResolutionByPayload(router, channelResolver); } - private void doTestMultiChannelListResolutionByPayload(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelListResolutionByPayload(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -405,29 +405,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelListResolutionByMessageConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestMultiChannelListResolutionByMessage(router, channelMapping); + this.doTestMultiChannelListResolutionByMessage(router, channelResolver); } @Test public void multiChannelListResolutionByMessageConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessage"); - this.doTestMultiChannelListResolutionByMessage(router, channelMapping); + this.doTestMultiChannelListResolutionByMessage(router, channelResolver); } - private void doTestMultiChannelListResolutionByMessage(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelListResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -450,29 +450,29 @@ public class MethodInvokingRouterTests { @Test public void multiChannelArrayResolutionByMessageConfiguredByMethodReference() throws Exception { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class); MethodInvokingRouter router = new MethodInvokingRouter(testBean, routingMethod); - this.doTestMultiChannelArrayResolutionByMessage(router, channelMapping); + this.doTestMultiChannelArrayResolutionByMessage(router, channelResolver); } @Test public void multiChannelArrayResolutionByMessageConfiguredByMethodName() { - TestChannelMapping channelMapping = new TestChannelMapping(); - MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelResolver); MethodInvokingRouter router = new MethodInvokingRouter(testBean, "routeMessageToArray"); - this.doTestMultiChannelArrayResolutionByMessage(router, channelMapping); + this.doTestMultiChannelArrayResolutionByMessage(router, channelResolver); } - private void doTestMultiChannelArrayResolutionByMessage(MethodInvokingRouter router, TestChannelMapping channelMapping) { + private void doTestMultiChannelArrayResolutionByMessage(MethodInvokingRouter router, TestChannelResolver channelResolver) { QueueChannel fooChannel = new QueueChannel(); QueueChannel barChannel = new QueueChannel(); fooChannel.setBeanName("foo-channel"); barChannel.setBeanName("bar-channel"); - channelMapping.addChannel(fooChannel); - channelMapping.addChannel(barChannel); - router.setChannelMapping(channelMapping); + channelResolver.addChannel(fooChannel); + channelResolver.addChannel(barChannel); + router.setChannelResolver(channelResolver); Message fooMessage = new StringMessage("foo"); Message barMessage = new StringMessage("bar"); Message badMessage = new StringMessage("bad"); @@ -550,22 +550,22 @@ public class MethodInvokingRouterTests { public static class SingleChannelInstanceRoutingTestBean { - private ChannelMapping mapping; + private ChannelResolver channelResolver; - public SingleChannelInstanceRoutingTestBean(ChannelMapping mapping) { - this.mapping = mapping; + public SingleChannelInstanceRoutingTestBean(ChannelResolver channelResolver) { + this.channelResolver = channelResolver; } public MessageChannel routePayload(String name) { - return mapping.getChannel(name + "-channel"); + return channelResolver.resolveChannelName(name + "-channel"); } public MessageChannel routeMessage(Message message) { if (message.getPayload().equals("foo")) { - return mapping.getChannel("foo-channel"); + return channelResolver.resolveChannelName("foo-channel"); } else if (message.getPayload().equals("bar")) { - return mapping.getChannel("bar-channel"); + return channelResolver.resolveChannelName("bar-channel"); } return null; } @@ -574,17 +574,17 @@ public class MethodInvokingRouterTests { public static class MultiChannelInstanceRoutingTestBean { - private ChannelMapping mapping; + private ChannelResolver channelResolver; - public MultiChannelInstanceRoutingTestBean(ChannelMapping mapping) { - this.mapping = mapping; + public MultiChannelInstanceRoutingTestBean(ChannelResolver channelResolver) { + this.channelResolver = channelResolver; } public List routePayload(String name) { List results = new ArrayList(); if (name.equals("foo") || name.equals("bar")) { - results.add(mapping.getChannel("foo-channel")); - results.add(mapping.getChannel("bar-channel")); + results.add(channelResolver.resolveChannelName("foo-channel")); + results.add(channelResolver.resolveChannelName("bar-channel")); } return results; } @@ -592,8 +592,8 @@ public class MethodInvokingRouterTests { public List routeMessage(Message message) { List results = new ArrayList(); if (message.getPayload().equals("foo") || message.getPayload().equals("bar")) { - results.add(mapping.getChannel("foo-channel")); - results.add(mapping.getChannel("bar-channel")); + results.add(channelResolver.resolveChannelName("foo-channel")); + results.add(channelResolver.resolveChannelName("bar-channel")); } return results; } @@ -602,8 +602,8 @@ public class MethodInvokingRouterTests { MessageChannel[] results = null; if (message.getPayload().equals("foo") || message.getPayload().equals("bar")) { results = new MessageChannel[2]; - results[0] = mapping.getChannel("foo-channel"); - results[1] = mapping.getChannel("bar-channel"); + results[0] = channelResolver.resolveChannelName("foo-channel"); + results[1] = channelResolver.resolveChannelName("bar-channel"); } return results; } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java index 20eec48e65..3ba0baa0dd 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/MultiChannelRouterTests.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.channel.TestChannelMapping; +import org.springframework.integration.channel.TestChannelResolver; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessagingException; import org.springframework.integration.message.StringMessage; @@ -34,7 +34,7 @@ public class MultiChannelRouterTests { @Test public void routeWithChannelMapping() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] {"channel1", "channel2"}; } @@ -43,10 +43,10 @@ public class MultiChannelRouterTests { QueueChannel channel2 = new QueueChannel(); channel1.setBeanName("channel1"); channel2.setBeanName("channel2"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(channel1); - channelMapping.addChannel(channel2); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(channel1); + channelResolver.addChannel(channel2); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); Message result1 = channel1.receive(25); @@ -59,20 +59,20 @@ public class MultiChannelRouterTests { @Test(expected = MessagingException.class) public void channelNameLookupFailure() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] {"noSuchChannel"}; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); } @Test(expected = MessagingException.class) public void channelMappingNotAvailable() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] {"noSuchChannel"}; } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/RouterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/router/RouterTests.java index a322df2023..f804653921 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/router/RouterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/RouterTests.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.springframework.context.support.GenericApplicationContext; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.channel.TestChannelMapping; +import org.springframework.integration.channel.TestChannelResolver; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.MessagingException; @@ -85,26 +85,26 @@ public class RouterTests { @Test public void nullChannelNameArrayIgnoredByDefault() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return null; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); } @Test(expected = MessageDeliveryException.class) public void nullChannelNameArrayThrowsExceptionWhenResolutionRequired() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return null; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); router.setResolutionRequired(true); Message message = new StringMessage("test"); router.onMessage(message); @@ -113,26 +113,26 @@ public class RouterTests { @Test public void emptyChannelNameArrayIgnoredByDefault() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] {}; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); } @Test(expected = MessageDeliveryException.class) public void emptyChannelNameArrayThrowsExceptionWhenResolutionRequired() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] {}; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); router.setResolutionRequired(true); Message message = new StringMessage("test"); router.onMessage(message); @@ -150,7 +150,7 @@ public class RouterTests { @Test(expected = MessagingException.class) public void channelMappingIsRequiredWhenResolvingChannelNamesWithMultiChannelRouter() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] { "notImportant" }; } @@ -176,7 +176,7 @@ public class RouterTests { @Test public void beanFactoryWithMultiChannelRouter() { - AbstractChannelMappingMessageRouter router = new AbstractChannelMappingMessageRouter() { + AbstractChannelNameResolvingMessageRouter router = new AbstractChannelNameResolvingMessageRouter() { public String[] resolveChannelNames(Message message) { return new String[] { "testChannel" }; } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/SingleChannelRouterTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/router/SingleChannelRouterTests.java index 6128ec0d4d..11c19a56e8 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/router/SingleChannelRouterTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/SingleChannelRouterTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.channel.TestChannelMapping; +import org.springframework.integration.channel.TestChannelResolver; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessagingException; import org.springframework.integration.message.StringMessage; @@ -57,9 +57,9 @@ public class SingleChannelRouterTests { }; QueueChannel channel = new QueueChannel(); channel.setBeanName("testChannel"); - TestChannelMapping channelMapping = new TestChannelMapping(); - channelMapping.addChannel(channel); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + channelResolver.addChannel(channel); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); Message result = channel.receive(25); @@ -85,8 +85,8 @@ public class SingleChannelRouterTests { return "noSuchChannel"; } }; - TestChannelMapping channelMapping = new TestChannelMapping(); - router.setChannelMapping(channelMapping); + TestChannelResolver channelResolver = new TestChannelResolver(); + router.setChannelResolver(channelResolver); Message message = new StringMessage("test"); router.onMessage(message); }