Example usage for org.springframework.integration.test.util TestUtils locateComponentInHistory

List of usage examples for org.springframework.integration.test.util TestUtils locateComponentInHistory

Introduction

In this page you can find the example usage for org.springframework.integration.test.util TestUtils locateComponentInHistory.

Prototype

public static Properties locateComponentInHistory(List<Properties> history, String componentName,
        int startingIndex) 

Source Link

Usage

From source file:org.springframework.integration.mail.ImapMailReceiverTests.java

@SuppressWarnings("resource")
@Test/*from ww w  .j a  va  2 s  .c o m*/
@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();
}