Search in sources :

Example 16 with MessageHistory

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();
}
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 17 with MessageHistory

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"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with MessageHistory

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"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) Test(org.junit.Test)

Example 19 with MessageHistory

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();
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) JmsMessageDrivenEndpoint(org.springframework.integration.jms.JmsMessageDrivenEndpoint) Test(org.junit.Test)

Example 20 with MessageHistory

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"));
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) MessageChannel(org.springframework.messaging.MessageChannel) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

MessageHistory (org.springframework.integration.history.MessageHistory)37 Test (org.junit.Test)34 Properties (java.util.Properties)26 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectChannel (org.springframework.integration.channel.DirectChannel)8 PollableChannel (org.springframework.messaging.PollableChannel)8 Message (org.springframework.messaging.Message)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 EnableMessageHistory (org.springframework.integration.config.EnableMessageHistory)3 MongoClient (com.mongodb.MongoClient)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 TcpConnection (org.springframework.integration.ip.tcp.connection.TcpConnection)2 JmsMessageDrivenEndpoint (org.springframework.integration.jms.JmsMessageDrivenEndpoint)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 MessageChannel (org.springframework.messaging.MessageChannel)2