INT-2800 Add search-term-strategy to IMAP Adapter
Previously, the ability to customize the search term strategy was added to the IMAP Idle adapter; it should also be available to the polled IMAP adapter. Add the attribute. Remove some obsolete code from the parser.
This commit is contained in:
committed by
Mark Fisher
parent
73faefa22c
commit
d8d77a9bbc
@@ -104,6 +104,15 @@
|
||||
|
||||
<si:bridge input-channel="autoChannel" output-channel="nullChannel"/>
|
||||
|
||||
<!-- INT-2800 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithSearch" channel="testChannel" protocol="imap" should-delete-messages="false" auto-startup="false"
|
||||
search-term-strategy="searchTermStrategy"/>
|
||||
|
||||
<bean id="searchTermStrategy" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.mail.SearchTermStrategy"/>
|
||||
</bean>
|
||||
|
||||
<!-- COMMON CONFIGURATION -->
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mail="http://www.springframework.org/schema/integration/mail"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- INT-2800 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3WithSearch" channel="testChannel" protocol="pop3" should-delete-messages="false" auto-startup="false"
|
||||
search-term-strategy="searchTermStrategy"/>
|
||||
|
||||
<bean id="searchTermStrategy" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.mail.SearchTermStrategy"/>
|
||||
</bean>
|
||||
|
||||
<!-- COMMON CONFIGURATION -->
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:poller default="true" max-messages-per-poll="1" fixed-rate="60000"/>
|
||||
|
||||
</beans>
|
||||
@@ -29,6 +29,7 @@ import javax.mail.Authenticator;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -40,6 +41,7 @@ import org.springframework.integration.mail.AbstractMailReceiver;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.Pop3MailReceiver;
|
||||
import org.springframework.integration.mail.SearchTermStrategy;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -72,7 +74,7 @@ public class InboundChannelAdapterParserTests {
|
||||
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
|
||||
assertTrue(value);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void imapShouldMarkMessagesAsRead() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapShouldMarkAsReadTrue");
|
||||
@@ -283,6 +285,30 @@ public class InboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
|
||||
//==================== INT-2800 ====================
|
||||
|
||||
@Test
|
||||
public void imapWithSearchTermStrategy() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithSearch");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object sts = new DirectFieldAccessor(receiver).getPropertyValue("searchTermStrategy");
|
||||
assertNotNull(sts);
|
||||
assertSame(context.getBean(SearchTermStrategy.class), sts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3WithSearchTermStrategy() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml");
|
||||
fail("expected a parser error");
|
||||
}
|
||||
catch(BeanCreationException e) {
|
||||
assertTrue(e.getMessage().contains("searchTermStrategy is only allowed with imap"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//===================== COMMON =====================
|
||||
|
||||
private AbstractMailReceiver getReceiver(String name) {
|
||||
|
||||
Reference in New Issue
Block a user