INT-1377 - first round of Router hierarchy refactoring to make them more dynamic, moved every router under ACNRMR (later ACNRMR will be merged with AMR), removed type preloading in PTR parser, fixed tests, removed MapBasedChannelResolver and related tests. fixed test for other components that were dependent on MapBasedChannelResolver
This commit is contained in:
@@ -20,17 +20,17 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -39,14 +39,16 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
*/
|
||||
public class MessagePublishingInterceptorTests {
|
||||
|
||||
private final MapBasedChannelResolver channelResolver = new MapBasedChannelResolver();
|
||||
private ChannelResolver channelResolver;
|
||||
|
||||
private final QueueChannel testChannel = new QueueChannel();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
channelResolver.setChannelMap(Collections.singletonMap("c", testChannel));
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
channelResolver = new BeanFactoryChannelResolver(beanFactory);
|
||||
beanFactory.registerSingleton("c", testChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,19 +37,19 @@
|
||||
</property>
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="setName" value="channel" />
|
||||
<entry key="setName" value="messagePublishingInterceptorUsageTestChannel" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="channelResolver">
|
||||
<bean
|
||||
class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="channel" value-ref="messagePublishingInterceptorUsageTestChannel" />
|
||||
</map>
|
||||
</property>
|
||||
class="org.springframework.integration.support.channel.BeanFactoryChannelResolver">
|
||||
<!-- <property name="channelMap">-->
|
||||
<!-- <map>-->
|
||||
<!-- <entry key="channel" value-ref="messagePublishingInterceptorUsageTestChannel" />-->
|
||||
<!-- </map>-->
|
||||
<!-- </property>-->
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -1,73 +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.channel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.MessageChannel;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MapBasedChannelResolverTests {
|
||||
|
||||
@Test
|
||||
public void mapContainsChannel() {
|
||||
MessageChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("testChannel");
|
||||
assertNotNull(result);
|
||||
assertEquals(testChannel, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapDoesNotContainChannel() {
|
||||
MessageChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("noSuchChannel");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyMap() {
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("testChannel");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nullMapRejected() {
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
<bean id="payloadTypeRouter" class="org.springframework.integration.router.PayloadTypeRouter">
|
||||
<property name="resolutionRequired" value="true"/>
|
||||
<property name="payloadTypeChannelMap">
|
||||
<property name="channelIdentifierMap">
|
||||
<map>
|
||||
<entry key="java.lang.String" value-ref="strings"/>
|
||||
<entry key="java.lang.String" value="strings"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -31,12 +31,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
@@ -45,6 +45,7 @@ import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
@@ -306,9 +307,12 @@ public class MessagingTemplateTests {
|
||||
@Test
|
||||
public void sendByChannelNameWithCustomChannelResolver() {
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
// Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
// channelMap.put("testChannel", testChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("testChannel", testChannel);
|
||||
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(beanFactory);
|
||||
// MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
MessagingTemplate template = new MessagingTemplate();
|
||||
template.setChannelResolver(channelResolver);
|
||||
template.afterPropertiesSet();
|
||||
@@ -352,11 +356,11 @@ public class MessagingTemplateTests {
|
||||
@Test
|
||||
public void receiveByChannelNameWithCustomChannelResolver() {
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("testChannel", testChannel);
|
||||
|
||||
MessagingTemplate template = new MessagingTemplate();
|
||||
template.setChannelResolver(channelResolver);
|
||||
template.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
template.afterPropertiesSet();
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
testChannel.send(message);
|
||||
|
||||
@@ -22,20 +22,24 @@ import static org.junit.Assert.assertNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ErrorMessageExceptionTypeRouterTests {
|
||||
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
private QueueChannel illegalArgumentChannel = new QueueChannel();
|
||||
|
||||
@@ -46,6 +50,15 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
private QueueChannel messageDeliveryExceptionChannel = new QueueChannel();
|
||||
|
||||
private QueueChannel defaultChannel = new QueueChannel();
|
||||
|
||||
@Before
|
||||
public void prepare(){
|
||||
beanFactory.registerSingleton("illegalArgumentChannel", illegalArgumentChannel);
|
||||
beanFactory.registerSingleton("runtimeExceptionChannel", runtimeExceptionChannel);
|
||||
beanFactory.registerSingleton("messageHandlingExceptionChannel", messageHandlingExceptionChannel);
|
||||
beanFactory.registerSingleton("messageDeliveryExceptionChannel", messageDeliveryExceptionChannel);
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@@ -56,12 +69,14 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
@@ -78,11 +93,12 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "runtimeExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(runtimeExceptionChannel.receive(1000));
|
||||
@@ -99,10 +115,10 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(messageHandlingExceptionChannel.receive(1000));
|
||||
@@ -135,10 +151,10 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(MessageDeliveryException.class, messageDeliveryExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(MessageDeliveryException.class.getName(), "messageDeliveryExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setResolutionRequired(true);
|
||||
router.handleMessage(message);
|
||||
}
|
||||
@@ -151,12 +167,12 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
Message<?> message = new GenericMessage<Exception>(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
@@ -173,11 +189,11 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
|
||||
@@ -20,19 +20,19 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class HeaderValueRouterTests {
|
||||
|
||||
@@ -76,12 +76,13 @@ public class HeaderValueRouterTests {
|
||||
public void resolveChannelNameFromMap() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
ManagedMap channelMap = new ManagedMap();
|
||||
channelMap.put("testKey", new RuntimeBeanReference("testChannel"));
|
||||
RootBeanDefinition channelResolverBeanDefinition = new RootBeanDefinition(MapBasedChannelResolver.class);
|
||||
channelResolverBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue(channelMap);
|
||||
channelMap.put("testKey", "testChannel");
|
||||
RootBeanDefinition channelResolverBeanDefinition = new RootBeanDefinition(BeanFactoryChannelResolver.class);
|
||||
channelResolverBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue(context);
|
||||
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
|
||||
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("channelIdentifierMap", channelMap);
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("channelResolver", new RuntimeBeanReference("resolver"));
|
||||
context.registerBeanDefinition("resolver", channelResolverBeanDefinition);
|
||||
context.registerBeanDefinition("router", routerBeanDefinition);
|
||||
|
||||
@@ -18,16 +18,19 @@ package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -81,6 +84,7 @@ public class MultiChannelRouterTests {
|
||||
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"});
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@@ -25,15 +25,17 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class PayloadTypeRouterTests {
|
||||
|
||||
@@ -41,15 +43,24 @@ public class PayloadTypeRouterTests {
|
||||
public void resolveExactMatch() {
|
||||
QueueChannel stringChannel = new QueueChannel();
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
MessageChannel result1 = router.determineTargetChannel(message1);
|
||||
MessageChannel result2 = router.determineTargetChannel(message2);
|
||||
MessageChannel result1 = router.determineTargetChannels(message1).iterator().next();
|
||||
MessageChannel result2 = router.determineTargetChannels(message2).iterator().next();
|
||||
//MessageChannel result1 = router.determineTargetChannel(message1);
|
||||
//MessageChannel result2 = router.determineTargetChannel(message2);
|
||||
assertEquals(stringChannel, result1);
|
||||
assertEquals(integerChannel, result2);
|
||||
}
|
||||
@@ -60,10 +71,15 @@ public class PayloadTypeRouterTests {
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
QueueChannel numberChannel = new QueueChannel();
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -81,11 +97,20 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
integerChannel.setBeanName("integerChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -102,10 +127,18 @@ public class PayloadTypeRouterTests {
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -123,11 +156,20 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -146,11 +188,20 @@ public class PayloadTypeRouterTests {
|
||||
serializableChannel.setBeanName("serializableChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Serializable.class, serializableChannel);
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("serializableChannel", serializableChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
try {
|
||||
@@ -169,11 +220,22 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel serializableChannel = new QueueChannel();
|
||||
serializableChannel.setBeanName("serializableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Serializable.class, serializableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("serializableChannel", serializableChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -190,11 +252,19 @@ public class PayloadTypeRouterTests {
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
stringChannel.setBeanName("stringChannel");
|
||||
integerChannel.setBeanName("integerChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
router.handleMessage(message1);
|
||||
@@ -211,10 +281,19 @@ public class PayloadTypeRouterTests {
|
||||
stringChannel.setBeanName("stringChannel");
|
||||
QueueChannel defaultChannel = new QueueChannel();
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
@@ -32,6 +34,7 @@ import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -148,6 +151,7 @@ public class RouterTests {
|
||||
return "notImportant";
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
router.handleMessage(new GenericMessage<String>("this should fail"));
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ public class RouterTests {
|
||||
return CollectionUtils.arrayToList(new String[] { "notImportant" });
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
router.handleMessage(new GenericMessage<String>("this should fail"));
|
||||
}
|
||||
|
||||
|
||||
@@ -61,15 +61,6 @@ public class PayloadTypeRouterParserTests {
|
||||
assertTrue(chanel2.receive(0).getPayload() instanceof Integer);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testFakeTypes(){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(routerConfigFakeType.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testNoMappingElement(){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(routerConfigNoMaping.getBytes());
|
||||
|
||||
Reference in New Issue
Block a user