use of jakarta.mail.FolderClosedException in project spring-integration by spring-projects.
the class ImapMailReceiverTests method testIdleReconnects.
@Test
public void testIdleReconnects() throws Exception {
ImapMailReceiver receiver = spy(new ImapMailReceiver("imap:foo"));
receiver.setBeanFactory(mock(BeanFactory.class));
receiver.afterPropertiesSet();
IMAPFolder folder = mock(IMAPFolder.class);
given(folder.getPermanentFlags()).willReturn(new Flags(Flags.Flag.USER));
given(folder.isOpen()).willReturn(false).willReturn(true);
given(folder.exists()).willReturn(true);
given(folder.hasNewMessages()).willReturn(true);
Field storeField = AbstractMailReceiver.class.getDeclaredField("store");
storeField.setAccessible(true);
Store store = mock(Store.class);
given(store.isConnected()).willReturn(false);
given(store.getFolder(Mockito.any(URLName.class))).willReturn(folder);
storeField.set(receiver, store);
ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(receiver);
LogAccessor logger = spy(TestUtils.getPropertyValue(adapter, "logger", LogAccessor.class));
new DirectFieldAccessor(adapter).setPropertyValue("logger", logger);
willDoNothing().given(logger).warn(any(Throwable.class), anyString());
willAnswer(i -> {
i.callRealMethod();
throw new FolderClosedException(folder, "test");
}).given(receiver).waitForNewMessages();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
adapter.setTaskScheduler(taskScheduler);
adapter.setReconnectDelay(1);
adapter.afterPropertiesSet();
final CountDownLatch latch = new CountDownLatch(3);
adapter.setApplicationEventPublisher(e -> {
latch.countDown();
});
adapter.start();
assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
verify(store, atLeast(3)).connect();
adapter.stop();
taskScheduler.shutdown();
}
Aggregations