use of org.springframework.messaging.core.DestinationResolver in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromMapAndCustomeResolver.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveChannelNameFromMapAndCustomeResolver() {
final StaticApplicationContext context = new StaticApplicationContext();
ManagedMap channelMappings = new ManagedMap();
channelMappings.put("testKey", "testChannel");
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
routerBeanDefinition.getPropertyValues().addPropertyValue("channelResolver", (DestinationResolver<MessageChannel>) channelName -> context.getBean("anotherChannel", MessageChannel.class));
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("anotherChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("anotherChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
Aggregations