Search in sources :

Example 1 with DestinationResolver

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();
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) QueueChannel(org.springframework.integration.channel.QueueChannel) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) MessageChannel(org.springframework.messaging.MessageChannel) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Matchers.contains(org.hamcrest.Matchers.contains) MessageHandler(org.springframework.messaging.MessageHandler) Matchers.equalTo(org.hamcrest.Matchers.equalTo) DestinationResolver(org.springframework.messaging.core.DestinationResolver) Message(org.springframework.messaging.Message) MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageHandler(org.springframework.messaging.MessageHandler) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Test(org.junit.Test)

Aggregations

Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertThat (org.junit.Assert.assertThat)1 Test (org.junit.Test)1 ManagedMap (org.springframework.beans.factory.support.ManagedMap)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 MessageBuilder (org.springframework.integration.support.MessageBuilder)1 Message (org.springframework.messaging.Message)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageHandler (org.springframework.messaging.MessageHandler)1 DestinationResolver (org.springframework.messaging.core.DestinationResolver)1