Search in sources :

Example 96 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class JdbcOutboundGatewayParserTests method testOutboundGatewayInsideChain.

// INT-1029
@Test
public void testOutboundGatewayInsideChain() {
    setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
    String beanName = "org.springframework.integration.handler.MessageHandlerChain#" + "0$child.jdbc-outbound-gateway-within-chain.handler";
    JdbcOutboundGateway jdbcMessageHandler = this.context.getBean(beanName, JdbcOutboundGateway.class);
    MessageChannel channel = this.context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
    assertFalse(TestUtils.getPropertyValue(jdbcMessageHandler, "requiresReply", Boolean.class));
    channel.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build());
    PollableChannel outbound = this.context.getBean("replyChannel", PollableChannel.class);
    Message<?> reply = outbound.receive(10000);
    assertNotNull(reply);
    @SuppressWarnings("unchecked") Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
    assertEquals("bar", payload.get("name"));
}
Also used : JdbcOutboundGateway(org.springframework.integration.jdbc.JdbcOutboundGateway) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) Map(java.util.Map) Test(org.junit.Test)

Example 97 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ImapMailReceiverTests method testMessageHistory.

@Test
@Ignore
public void testMessageHistory() throws Exception {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("ImapIdleChannelAdapterParserTests-context.xml", ImapIdleChannelAdapterParserTests.class);
    ImapIdleChannelAdapter adapter = context.getBean("simpleAdapter", ImapIdleChannelAdapter.class);
    AbstractMailReceiver receiver = new ImapMailReceiver();
    receiver = spy(receiver);
    receiver.setBeanFactory(mock(BeanFactory.class));
    receiver.afterPropertiesSet();
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    adapterAccessor.setPropertyValue("mailReceiver", receiver);
    MimeMessage mailMessage = mock(MimeMessage.class);
    Flags flags = mock(Flags.class);
    given(mailMessage.getFlags()).willReturn(flags);
    final Message[] messages = new Message[] { mailMessage };
    willAnswer(invocation -> {
        DirectFieldAccessor accessor = new DirectFieldAccessor((invocation.getMock()));
        IMAPFolder folder = mock(IMAPFolder.class);
        accessor.setPropertyValue("folder", folder);
        given(folder.hasNewMessages()).willReturn(true);
        return null;
    }).given(receiver).openFolder();
    willAnswer(invocation -> messages).given(receiver).searchForNewMessages();
    willAnswer(invocation -> null).given(receiver).fetchMessages(messages);
    PollableChannel channel = context.getBean("channel", PollableChannel.class);
    adapter.start();
    org.springframework.messaging.Message<?> replMessage = channel.receive(10000);
    MessageHistory history = MessageHistory.read(replMessage);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "simpleAdapter", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("mail:imap-idle-channel-adapter", componentHistoryRecord.get("type"));
    adapter.stop();
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) IMAPFolder(com.sun.mail.imap.IMAPFolder) Flags(javax.mail.Flags) Properties(java.util.Properties) MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MimeMessage(javax.mail.internet.MimeMessage) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BeanFactory(org.springframework.beans.factory.BeanFactory) PollableChannel(org.springframework.messaging.PollableChannel) Ignore(org.junit.Ignore) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 98 with PollableChannel

use of org.springframework.messaging.PollableChannel 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 99 with PollableChannel

use of org.springframework.messaging.PollableChannel 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)

Example 100 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class MongoDbOutboundGatewayXmlTests method testCollectionCallback.

@Test
@MongoDbAvailable
public void testCollectionCallback() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayCollectionCallback", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    long personsCount = (Long) result.getPayload();
    assertEquals(4, personsCount);
}
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

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9