Search in sources :

Example 11 with TestChannelResolver

use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.

the class ServiceActivatorEndpointTests method dynamicReplyChannel.

@Test
public void dynamicReplyChannel() throws Exception {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    final QueueChannel replyChannel1 = new QueueChannel();
    final QueueChannel replyChannel2 = new QueueChannel();
    replyChannel2.setBeanName("replyChannel2");
    Object handler = new Object() {

        @SuppressWarnings("unused")
        public Message<?> handle(Message<?> message) {
            return new GenericMessage<String>("foo" + message.getPayload());
        }
    };
    ServiceActivatingHandler endpoint = new ServiceActivatingHandler(handler, "handle");
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("replyChannel2", replyChannel2);
    endpoint.setChannelResolver(channelResolver);
    endpoint.setBeanFactory(testApplicationContext);
    endpoint.afterPropertiesSet();
    Message<String> testMessage1 = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel1).build();
    endpoint.handleMessage(testMessage1);
    Message<?> reply1 = replyChannel1.receive(50);
    assertNotNull(reply1);
    assertEquals("foobar", reply1.getPayload());
    Message<?> reply2 = replyChannel2.receive(0);
    assertNull(reply2);
    Message<String> testMessage2 = MessageBuilder.fromMessage(testMessage1).setReplyChannelName("replyChannel2").build();
    endpoint.handleMessage(testMessage2);
    reply1 = replyChannel1.receive(0);
    assertNull(reply1);
    reply2 = replyChannel2.receive(0);
    assertNotNull(reply2);
    assertEquals("foobar", reply2.getPayload());
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 12 with TestChannelResolver

use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.

the class ServiceActivatorEndpointTests method returnAddressHeaderWithChannelName.

@Test
public void returnAddressHeaderWithChannelName() {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    QueueChannel channel = new QueueChannel(1);
    channel.setBeanName("testChannel");
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("testChannel", channel);
    ServiceActivatingHandler endpoint = this.createEndpoint();
    endpoint.setChannelResolver(channelResolver);
    endpoint.setBeanFactory(testApplicationContext);
    endpoint.afterPropertiesSet();
    Message<?> message = MessageBuilder.withPayload("foo").setReplyChannelName("testChannel").build();
    endpoint.handleMessage(message);
    Message<?> reply = channel.receive(0);
    assertNotNull(reply);
    assertEquals("FOO", reply.getPayload());
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) QueueChannel(org.springframework.integration.channel.QueueChannel) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 13 with TestChannelResolver

use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.

the class MultiChannelRouterTests method channelNameLookupFailure.

@Test(expected = MessagingException.class)
public void channelNameLookupFailure() {
    AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {

        @SuppressWarnings("unchecked")
        public List<Object> getChannelKeys(Message<?> message) {
            return CollectionUtils.arrayToList(new String[] { "noSuchChannel" });
        }
    };
    TestChannelResolver channelResolver = new TestChannelResolver();
    router.setChannelResolver(channelResolver);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) Test(org.junit.Test)

Example 14 with TestChannelResolver

use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.

the class MultiChannelRouterTests method routeWithChannelMapping.

@Test
public void routeWithChannelMapping() {
    AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {

        @SuppressWarnings("unchecked")
        public List<Object> getChannelKeys(Message<?> message) {
            return CollectionUtils.arrayToList(new String[] { "channel1", "channel2" });
        }
    };
    QueueChannel channel1 = new QueueChannel();
    QueueChannel channel2 = new QueueChannel();
    TestChannelResolver channelResolver = new TestChannelResolver();
    channelResolver.addChannel("channel1", channel1);
    channelResolver.addChannel("channel2", channel2);
    router.setChannelResolver(channelResolver);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
    Message<?> result1 = channel1.receive(25);
    assertNotNull(result1);
    assertEquals("test", result1.getPayload());
    Message<?> result2 = channel2.receive(25);
    assertNotNull(result2);
    assertEquals("test", result2.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) Test(org.junit.Test)

Example 15 with TestChannelResolver

use of org.springframework.integration.channel.TestChannelResolver in project spring-integration by spring-projects.

the class RouterTests method emptyChannelNameArrayRaisesMessageDeliveryExceptionByDefault.

@Test(expected = MessageDeliveryException.class)
public void emptyChannelNameArrayRaisesMessageDeliveryExceptionByDefault() {
    AbstractMappingMessageRouter router = new AbstractMappingMessageRouter() {

        protected List<Object> getChannelKeys(Message<?> message) {
            return new ArrayList<Object>();
        }
    };
    TestChannelResolver channelResolver = new TestChannelResolver();
    router.setChannelResolver(channelResolver);
    Message<String> message = new GenericMessage<String>("test");
    router.handleMessage(message);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) TestChannelResolver(org.springframework.integration.channel.TestChannelResolver) Test(org.junit.Test)

Aggregations

TestChannelResolver (org.springframework.integration.channel.TestChannelResolver)28 Test (org.junit.Test)27 Method (java.lang.reflect.Method)10 GenericMessage (org.springframework.messaging.support.GenericMessage)10 QueueChannel (org.springframework.integration.channel.QueueChannel)8 Message (org.springframework.messaging.Message)6 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)2 TestUtils (org.springframework.integration.test.util.TestUtils)2 ArrayList (java.util.ArrayList)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1