use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class PayloadTypeRouterTests method ambiguityFailure.
@Test(expected = MessageHandlingException.class)
public void ambiguityFailure() throws Exception {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel serializableChannel = new QueueChannel();
serializableChannel.setBeanName("serializableChannel");
QueueChannel comparableChannel = new QueueChannel();
comparableChannel.setBeanName("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.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class PayloadTypeRouterTests method resolveByPayloadTypeWithRouterEndpoint.
@Test
public void resolveByPayloadTypeWithRouterEndpoint() {
QueueChannel stringChannel = new QueueChannel();
QueueChannel integerChannel = new QueueChannel();
stringChannel.setBeanName("stringChannel");
integerChannel.setBeanName("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.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
Message<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
router.handleMessage(message1);
router.handleMessage(message2);
Message<?> reply1 = stringChannel.receive(0);
Message<?> reply2 = integerChannel.receive(0);
assertEquals("test", reply1.getPayload());
assertEquals(123, reply2.getPayload());
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class PayloadTypeRouterTests method exactMatchFavoredOverSuperclass.
@Test
public void exactMatchFavoredOverSuperclass() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel numberChannel = new QueueChannel();
numberChannel.setBeanName("numberChannel");
QueueChannel integerChannel = new QueueChannel();
integerChannel.setBeanName("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.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
Message<?> result = integerChannel.receive(0);
assertNotNull(result);
assertEquals(99, result.getPayload());
assertNull(numberChannel.receive(0));
assertNull(defaultChannel.receive(0));
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class PayloadTypeRouterTests method directInterfaceFavoredOverSuperclass.
@Test
public void directInterfaceFavoredOverSuperclass() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel numberChannel = new QueueChannel();
numberChannel.setBeanName("numberChannel");
QueueChannel comparableChannel = new QueueChannel();
comparableChannel.setBeanName("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.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
Message<?> result = comparableChannel.receive(0);
assertNotNull(result);
assertEquals(99, result.getPayload());
assertNull(numberChannel.receive(0));
assertNull(defaultChannel.receive(0));
// validate dynamics
QueueChannel newChannel = new QueueChannel();
beanFactory.registerSingleton("newChannel", newChannel);
router.setChannelMapping(Integer.class.getName(), "newChannel");
assertEquals(1, router.getChannelKeys(message).size());
router.handleMessage(message);
result = newChannel.receive(10);
assertNotNull(result);
}
use of org.springframework.integration.channel.QueueChannel in project spring-integration by spring-projects.
the class PayloadTypeRouterTests method classWinsOverMoreDistantAmbiguousInterfaces.
@Test
public void classWinsOverMoreDistantAmbiguousInterfaces() throws Exception {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel i5aChannel = new QueueChannel();
i5aChannel.setBeanName("i5aChannel");
QueueChannel i5bChannel = new QueueChannel();
i5bChannel.setBeanName("i5bChannel");
QueueChannel c2Channel = new QueueChannel();
c2Channel.setBeanName("c2Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("i5aChannel", i5aChannel);
beanFactory.registerSingleton("i5bChannel", i5bChannel);
beanFactory.registerSingleton("c2Channel", c2Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(I5A.class.getName(), "i5aChannel");
payloadTypeChannelMap.put(I5B.class.getName(), "i5bChannel");
payloadTypeChannelMap.put(C2.class.getName(), "c2Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
assertNotNull(c2Channel.receive(100));
}
Aggregations