Search in sources :

Example 31 with EventDrivenConsumer

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

the class XPathMessageSplitterParserTests method testSimpleStringExpressionWithCreateDocuments.

@Test
public void testSimpleStringExpressionWithCreateDocuments() 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' input-channel='test-input' output-channel='test-output' create-documents='true'><si-xml:xpath-expression expression='//name'/></si-xml:xpath-splitter>");
    EventDrivenConsumer consumer = (EventDrivenConsumer) ctx.getBean("splitter");
    consumer.start();
    ctx.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    inputChannel.send(docMessage);
    assertEquals("Wrong number of split messages ", 2, outputChannel.getQueueSize());
    assertTrue("Splitter failed to create documents ", ((Message<?>) outputChannel.receive(1000)).getPayload() instanceof Document);
    assertTrue("Splitter failed to create documents ", ((Message<?>) outputChannel.receive(1000)).getPayload() instanceof Document);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 32 with EventDrivenConsumer

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

the class XPathFilterParserTests method testParse.

@Test
public void testParse() throws Exception {
    EventDrivenConsumer consumer = (EventDrivenConsumer) context.getBean("parseOnly");
    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));
    SmartLifecycleRoleController roleController = context.getBean(SmartLifecycleRoleController.class);
    @SuppressWarnings("unchecked") List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles", MultiValueMap.class).get("foo");
    assertThat(list, contains((SmartLifecycle) consumer));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) SmartLifecycleRoleController(org.springframework.integration.support.SmartLifecycleRoleController) List(java.util.List) SmartLifecycle(org.springframework.context.SmartLifecycle) Test(org.junit.Test)

Example 33 with EventDrivenConsumer

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

the class EventOutboundChannelAdapterParserTests method validateEventParser.

@Test
public void validateEventParser() {
    EventDrivenConsumer adapter = this.context.getBean("eventAdapter", EventDrivenConsumer.class);
    Assert.assertNotNull(adapter);
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    MessageHandler handler = (MessageHandler) adapterAccessor.getPropertyValue("handler");
    Assert.assertTrue(handler instanceof ApplicationEventPublishingMessageHandler);
    Assert.assertEquals(this.context.getBean("input"), adapterAccessor.getPropertyValue("inputChannel"));
    Assert.assertTrue(TestUtils.getPropertyValue(handler, "publishPayload", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageHandler(org.springframework.messaging.MessageHandler) ApplicationEventPublishingMessageHandler(org.springframework.integration.event.outbound.ApplicationEventPublishingMessageHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ApplicationEventPublishingMessageHandler(org.springframework.integration.event.outbound.ApplicationEventPublishingMessageHandler) Test(org.junit.Test)

Example 34 with EventDrivenConsumer

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

the class MongoDbOutboundGatewayXmlTests method testSingleQueryExpression.

@Test
@MongoDbAvailable
public void testSingleQueryExpression() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewaySingleQueryExpression", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("query", "{'name' : 'Gary'}").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    Person person = getPerson(result);
    assertEquals("Gary", person.getName());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 35 with EventDrivenConsumer

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

the class MongoDbOutboundGatewayXmlTests method testQueryExpression.

@Test
@MongoDbAvailable
public void testQueryExpression() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayQueryExpression", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("query", "{}").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    List<Person> persons = getPersons(result);
    assertEquals(4, persons.size());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

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