Search in sources :

Example 41 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class OutboundChannelAdapterParserTests method testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression.

@Test
public void testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
    Object consumer = context.getBean("sftpOutboundAdapterWithExpression");
    assertTrue(consumer instanceof EventDrivenConsumer);
    assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
    assertEquals("sftpOutboundAdapterWithExpression", ((EventDrivenConsumer) consumer).getComponentName());
    FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class);
    SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor.expression");
    assertNotNull(remoteDirectoryExpression);
    assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString());
    FileNameGenerator generator = (FileNameGenerator) TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator");
    Expression fileNameGeneratorExpression = TestUtils.getPropertyValue(generator, "expression", Expression.class);
    assertNotNull(fileNameGeneratorExpression);
    assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression.getExpressionString());
    assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
    assertNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) FileNameGenerator(org.springframework.integration.file.FileNameGenerator) Test(org.junit.Test)

Example 42 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class XPathRouterParserTests method testSetResolutionRequiredFalse.

@Test
public void testSetResolutionRequiredFalse() throws Exception {
    StringBuffer contextBuffer = new StringBuffer("<si-xml:xpath-router id='router' resolution-required='false' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
    EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
    DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
    Object handler = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(handler);
    Object resolutionRequired = accessor.getPropertyValue("resolutionRequired");
    assertEquals("Resolution required not set to false ", false, resolutionRequired);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 43 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class XPathRouterParserTests method testSetResolutionRequiredTrue.

@Test
public void testSetResolutionRequiredTrue() throws Exception {
    StringBuffer contextBuffer = new StringBuffer("<si-xml:xpath-router id='router' resolution-required='true' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
    EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
    DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
    Object handler = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(handler);
    Object resolutionRequired = accessor.getPropertyValue("resolutionRequired");
    assertEquals("Resolution required not set to true ", true, resolutionRequired);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 44 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer 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 45 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class XPathRouterParserTests method testSetDefaultOutputChannel.

@Test
public void testSetDefaultOutputChannel() throws Exception {
    StringBuffer contextBuffer = new StringBuffer("<si-xml:xpath-router id='router' default-output-channel='defaultOutput' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
    EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
    DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
    Object handler = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(handler);
    Object defaultOutputChannelValue = accessor.getPropertyValue("defaultOutputChannel");
    assertEquals("Default output channel not correctly set ", defaultOutput, defaultOutputChannelValue);
    inputChannel.send(MessageBuilder.withPayload("<unrelated/>").build());
    assertEquals("Wrong count of messages on default output channel", 1, defaultOutput.getQueueSize());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5