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"));
}
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();
}
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());
}
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());
}
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);
}
Aggregations