Search in sources :

Example 1 with AbstractMappingMessageRouter

use of org.springframework.integration.router.AbstractMappingMessageRouter in project spring-integration by spring-projects.

the class XPathRouterParserTests method testWithDynamicChanges.

@Test
public void testWithDynamicChanges() throws Exception {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
    MessageChannel inputChannel = ac.getBean("xpathRouterEmptyChannel", MessageChannel.class);
    PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
    PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
    Document doc = XmlTestUtil.getDocumentForString("<name>channelA</name>");
    GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
    inputChannel.send(docMessage);
    assertNotNull(channelA.receive(10));
    assertNull(channelB.receive(10));
    EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterEmpty", EventDrivenConsumer.class);
    AbstractMappingMessageRouter xpathRouter = (AbstractMappingMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
    xpathRouter.setChannelMapping("channelA", "channelB");
    inputChannel.send(docMessage);
    assertNotNull(channelB.receive(10));
    assertNull(channelA.receive(10));
    ac.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) AbstractMappingMessageRouter(org.springframework.integration.router.AbstractMappingMessageRouter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 2 with AbstractMappingMessageRouter

use of org.springframework.integration.router.AbstractMappingMessageRouter in project spring-integration by spring-projects.

the class XPathRouterParserTests method testWithDynamicChangesWithExistingMappingsAndMultiChannel.

@Test
public void testWithDynamicChangesWithExistingMappingsAndMultiChannel() throws Exception {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
    MessageChannel inputChannel = ac.getBean("multiChannelRouterChannel", MessageChannel.class);
    PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
    PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
    Document doc = XmlTestUtil.getDocumentForString("<root><name>channelA</name><name>channelB</name></root>");
    GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
    inputChannel.send(docMessage);
    assertNotNull(channelA.receive(10));
    assertNotNull(channelA.receive(10));
    assertNull(channelB.receive(10));
    EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterWithMappingMultiChannel", EventDrivenConsumer.class);
    AbstractMappingMessageRouter xpathRouter = (AbstractMappingMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
    xpathRouter.removeChannelMapping("channelA");
    xpathRouter.removeChannelMapping("channelB");
    inputChannel.send(docMessage);
    assertNotNull(channelA.receive(10));
    assertNotNull(channelB.receive(10));
    ac.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) AbstractMappingMessageRouter(org.springframework.integration.router.AbstractMappingMessageRouter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with AbstractMappingMessageRouter

use of org.springframework.integration.router.AbstractMappingMessageRouter in project spring-integration by spring-projects.

the class XPathRouterParserTests method testWithDynamicChangesWithExistingMappings.

@Test
public void testWithDynamicChangesWithExistingMappings() throws Exception {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
    MessageChannel inputChannel = ac.getBean("xpathRouterWithMappingChannel", MessageChannel.class);
    PollableChannel channelA = ac.getBean("channelA", PollableChannel.class);
    PollableChannel channelB = ac.getBean("channelB", PollableChannel.class);
    Document doc = XmlTestUtil.getDocumentForString("<name>channelA</name>");
    GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
    inputChannel.send(docMessage);
    assertNull(channelA.receive(10));
    assertNotNull(channelB.receive(10));
    EventDrivenConsumer routerEndpoint = ac.getBean("xpathRouterWithMapping", EventDrivenConsumer.class);
    AbstractMappingMessageRouter xpathRouter = (AbstractMappingMessageRouter) TestUtils.getPropertyValue(routerEndpoint, "handler");
    xpathRouter.removeChannelMapping("channelA");
    inputChannel.send(docMessage);
    assertNotNull(channelA.receive(10));
    assertNull(channelB.receive(10));
    ac.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) AbstractMappingMessageRouter(org.springframework.integration.router.AbstractMappingMessageRouter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 AbstractMappingMessageRouter (org.springframework.integration.router.AbstractMappingMessageRouter)3 MessageChannel (org.springframework.messaging.MessageChannel)3 PollableChannel (org.springframework.messaging.PollableChannel)3 GenericMessage (org.springframework.messaging.support.GenericMessage)3 Document (org.w3c.dom.Document)3