use of org.springframework.integration.history.MessageHistory 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.integration.history.MessageHistory in project spring-integration by spring-projects.
the class MySqlJdbcMessageStoreTests method testWithMessageHistory.
@Test
@Transactional
public void testWithMessageHistory() throws Exception {
Message<?> message = new GenericMessage<String>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
barChannel.setBeanName("barChannel");
message = MessageHistory.write(message, fooChannel);
message = MessageHistory.write(message, barChannel);
messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
}
use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.
the class JdbcMessageStoreTests method testWithMessageHistory.
@Test
public void testWithMessageHistory() throws Exception {
Message<?> message = new GenericMessage<String>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
barChannel.setBeanName("barChannel");
message = MessageHistory.write(message, fooChannel);
message = MessageHistory.write(message, barChannel);
messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
}
use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.
the class JmsInboundGatewayParserTests method testGatewayWithConnectionFactoryAndDestination.
@Test
public void testGatewayWithConnectionFactoryAndDestination() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsGatewayWithConnectionFactoryAndDestination.xml", this.getClass());
PollableChannel channel = (PollableChannel) context.getBean("requestChannel");
JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("jmsGateway");
assertEquals(JmsMessageDrivenEndpoint.class, gateway.getClass());
context.start();
Message<?> message = channel.receive(10000);
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "jmsGateway", 0);
assertNotNull(componentHistoryRecord);
assertEquals("jms:inbound-gateway", componentHistoryRecord.get("type"));
assertNotNull("message should not be null", message);
assertEquals("message-driven-test", message.getPayload());
context.close();
}
use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.
the class XsltTransformerTests method testParamHeadersWithStartWildCharacter.
@Test
public void testParamHeadersWithStartWildCharacter() {
MessageChannel input = applicationContext.getBean("paramHeadersWithStartWildCharacterChannel", MessageChannel.class);
Message<?> message = MessageBuilder.withPayload(this.docAsString).setHeader("testParam", "testParamValue").setHeader("testParam2", "FOO").build();
input.send(message);
Message<?> resultMessage = output.receive();
MessageHistory history = MessageHistory.read(resultMessage);
assertNotNull(history);
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "paramHeadersWithStartWildCharacter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("xml:xslt-transformer", componentHistoryRecord.get("type"));
assertEquals("Wrong payload type", String.class, resultMessage.getPayload().getClass());
assertTrue(((String) resultMessage.getPayload()).contains("testParamValue"));
assertFalse(((String) resultMessage.getPayload()).contains("FOO"));
}
Aggregations