Search in sources :

Example 26 with EventDrivenConsumer

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

the class JmsOutboundChannelAdapterParserTests method adapterWithConnectionFactoryAndDestination.

@Test
public void adapterWithConnectionFactoryAndDestination() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundWithConnectionFactoryAndDestination.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
    DirectFieldAccessor accessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
    assertNotNull(accessor.getPropertyValue("jmsTemplate"));
    assertTrue(TestUtils.getPropertyValue(endpoint, "handler.jmsTemplate.sessionTransacted", Boolean.class));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 27 with EventDrivenConsumer

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

the class JmsOutboundChannelAdapterParserTests method adapterWithConnectionFactoryAndDestinationName.

@Test
public void adapterWithConnectionFactoryAndDestinationName() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundWithConnectionFactoryAndDestinationName.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter");
    DirectFieldAccessor accessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
    assertNotNull(accessor.getPropertyValue("jmsTemplate"));
    assertFalse(TestUtils.getPropertyValue(endpoint, "handler.jmsTemplate.sessionTransacted", Boolean.class));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 28 with EventDrivenConsumer

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

the class TestSendingMessageHandlerParserTests method testSendingMessageHandlerSuccessfulBootstrap.

@Test
public void testSendingMessageHandlerSuccessfulBootstrap() {
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("TestSendingMessageHandlerParser-context.xml", this.getClass());
    EventDrivenConsumer dmAdapter = ac.getBean("dmAdapter", EventDrivenConsumer.class);
    MessageHandler handler = TestUtils.getPropertyValue(dmAdapter, "handler", MessageHandler.class);
    assertEquals(DirectMessageSendingMessageHandler.class, handler.getClass());
    assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
    dmAdapter = ac.getBean("dmAdvised", EventDrivenConsumer.class);
    handler = TestUtils.getPropertyValue(dmAdapter, "handler", MessageHandler.class);
    handler.handleMessage(new GenericMessage<String>("foo"));
    assertEquals(1, adviceCalled);
    MessageHandler handler2 = TestUtils.getPropertyValue(ac.getBean("advised"), "handler", MessageHandler.class);
    assertNotSame(handler, handler2);
    handler2.handleMessage(new GenericMessage<String>("foo"));
    assertEquals(2, adviceCalled);
    ac.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectMessageSendingMessageHandler(org.springframework.integration.twitter.outbound.DirectMessageSendingMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 29 with EventDrivenConsumer

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

the class XPathMessageSplitterParserTests method testProvideDocumentBuilder.

@Test
public void testProvideDocumentBuilder() throws Exception {
    TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<bean id='docBuilderFactory' class='org.springframework.integration.xml.config.StubDocumentBuilderFactory' />" + channelDefinitions + "<si-xml:xpath-splitter id='splitter' input-channel='test-input' output-channel='test-output' doc-builder-factory='docBuilderFactory'><si-xml:xpath-expression expression='//name'/></si-xml:xpath-splitter>");
    EventDrivenConsumer consumer = (EventDrivenConsumer) ctx.getBean("splitter");
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(consumer);
    Object handler = fieldAccessor.getPropertyValue("handler");
    fieldAccessor = new DirectFieldAccessor(handler);
    Object documnetBuilderFactory = fieldAccessor.getPropertyValue("documentBuilderFactory");
    assertTrue("DocumnetBuilderFactory was not expected stub ", documnetBuilderFactory instanceof DocumentBuilderFactory);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 30 with EventDrivenConsumer

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

the class XPathMessageSplitterParserTests method testSimpleStringExpression.

@Test
public void testSimpleStringExpression() throws Exception {
    Document doc = XmlTestUtil.getDocumentForString("<names><name>Bob</name><name>John</name></names>");
    GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
    TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext(channelDefinitions + "<si-xml:xpath-splitter id='splitter' " + "order='2' send-timeout='123' auto-startup='false' phase='-1' " + "input-channel='test-input' output-channel='test-output'><si-xml:xpath-expression expression='//name'/></si-xml:xpath-splitter>");
    EventDrivenConsumer consumer = (EventDrivenConsumer) ctx.getBean("splitter");
    assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
    assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
    assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
    assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
    consumer.start();
    ctx.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    inputChannel.send(docMessage);
    assertEquals("Wrong number of split messages ", 2, outputChannel.getQueueSize());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Document(org.w3c.dom.Document) 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