From 92f563f5e10ccd36bb846e5824202b35849d158a Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 18 Jul 2011 13:58:26 -0400 Subject: [PATCH] INT-1969 added more tests to validate several ambiguity scenarios for the PayloadTypeRouter --- .../router/PayloadTypeRouterTests.java | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java index 37b96f6207..5b5df3c13a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/PayloadTypeRouterTests.java @@ -453,6 +453,73 @@ public class PayloadTypeRouterTests { assertEquals(123, result2.getPayload()); } + @Test + public void classWinningOverAmbiguateInterfacesFewLevelsDown() throws Exception { + QueueChannel defaultChannel = new QueueChannel(); + defaultChannel.setBeanName("defaultChannel"); + + QueueChannel i4aChannel = new QueueChannel(); + i4aChannel.setBeanName("i4aChannel"); + QueueChannel i4bChannel = new QueueChannel(); + i4bChannel.setBeanName("i4bChannel"); + + QueueChannel c2Channel = new QueueChannel(); + c2Channel.setBeanName("c2Channel"); + + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + beanFactory.registerSingleton("defaultChannel", defaultChannel); + beanFactory.registerSingleton("i4aChannel", i4aChannel); + beanFactory.registerSingleton("i4bChannel", i4aChannel); + beanFactory.registerSingleton("c2Channel", c2Channel); + + Map payloadTypeChannelMap = new ConcurrentHashMap(); + payloadTypeChannelMap.put(I4A.class.getName(), "i4aChannel"); + payloadTypeChannelMap.put(I4B.class.getName(), "i4bChannel"); + payloadTypeChannelMap.put(C2.class.getName(), "c2Channel"); + PayloadTypeRouter router = new PayloadTypeRouter(); + + router.setBeanFactory(beanFactory); + router.setChannelIdentifierMap(payloadTypeChannelMap); + + router.setDefaultOutputChannel(defaultChannel); + Message message = new GenericMessage(new C1()); + router.handleMessage(message); + assertNotNull(c2Channel.receive(100)); + } + + @Test(expected=MessageHandlingException.class) + public void classLosingOverAmbiguateInterfacesSameLevel() throws Exception { + QueueChannel defaultChannel = new QueueChannel(); + defaultChannel.setBeanName("defaultChannel"); + + QueueChannel i1aChannel = new QueueChannel(); + i1aChannel.setBeanName("i1aChannel"); + QueueChannel i1bChannel = new QueueChannel(); + i1bChannel.setBeanName("i1bChannel"); + + QueueChannel c2Channel = new QueueChannel(); + c2Channel.setBeanName("c2Channel"); + + DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + beanFactory.registerSingleton("defaultChannel", defaultChannel); + beanFactory.registerSingleton("i1aChannel", i1aChannel); + beanFactory.registerSingleton("i1bChannel", i1bChannel); + beanFactory.registerSingleton("c2Channel", c2Channel); + + Map payloadTypeChannelMap = new ConcurrentHashMap(); + payloadTypeChannelMap.put(I1A.class.getName(), "i1aChannel"); + payloadTypeChannelMap.put(I1B.class.getName(), "i2bChannel"); + payloadTypeChannelMap.put(C2.class.getName(), "c2Channel"); + PayloadTypeRouter router = new PayloadTypeRouter(); + + router.setBeanFactory(beanFactory); + router.setChannelIdentifierMap(payloadTypeChannelMap); + + router.setDefaultOutputChannel(defaultChannel); + Message message = new GenericMessage(new C1()); + router.handleMessage(message); + } + @SuppressWarnings("serial") public static class C1 extends C2 implements I1A, I1B {} @@ -464,7 +531,9 @@ public class PayloadTypeRouterTests { public interface I3 extends I4 {} - public interface I4 {} + public interface I4 extends I4A, I4B{} + public interface I4A {} + public interface I4B {} public static class C2 extends C3{}