INT-3861: Mail Namespace Support for userFlag
JIRA: https://jira.spring.io/browse/INT-3861 Allow the custom `userFlag` to be configured using the namespace. Polishing according PR comments
This commit is contained in:
committed by
Artem Bilan
parent
33a40f6cae
commit
f80c0db0df
@@ -18,7 +18,7 @@
|
||||
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">
|
||||
|
||||
|
||||
<integration:message-history/>
|
||||
|
||||
<context:property-placeholder properties-ref="configProperties"/>
|
||||
@@ -36,21 +36,22 @@
|
||||
channel="channel"
|
||||
auto-startup="false"
|
||||
should-delete-messages="true"/>
|
||||
|
||||
|
||||
<mail:imap-idle-channel-adapter id="simpleAdapterWithErrorChannel"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
error-channel="errorChannel"
|
||||
auto-startup="false"
|
||||
should-delete-messages="true"/>
|
||||
|
||||
|
||||
<mail:imap-idle-channel-adapter id="simpleAdapterMarkAsRead"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
auto-startup="false"
|
||||
should-delete-messages="true"
|
||||
user-flag="flagged"
|
||||
should-mark-messages-as-read="true"/>
|
||||
|
||||
|
||||
<mail:imap-idle-channel-adapter id="simpleAdapterMarkAsReadFalse"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
@@ -63,9 +64,9 @@
|
||||
channel="channel"
|
||||
auto-startup="false"
|
||||
java-mail-properties="javaMailProperties"
|
||||
should-delete-messages="${mail.delete}"
|
||||
should-delete-messages="${mail.delete}"
|
||||
search-term-strategy="searchTermStrategy"/>
|
||||
|
||||
|
||||
<mail:imap-idle-channel-adapter id="transactionalAdapter"
|
||||
store-uri="imap:foo"
|
||||
channel="channel"
|
||||
@@ -97,4 +98,4 @@
|
||||
|
||||
<integration:bridge input-channel="autoChannel" output-channel="nullChannel" />
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,15 +30,16 @@ import javax.mail.search.SearchTerm;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
import org.springframework.integration.mail.ImapMailReceiver;
|
||||
import org.springframework.integration.mail.SearchTermStrategy;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -120,6 +121,7 @@ public class ImapIdleChannelAdapterParserTests {
|
||||
assertEquals(2, properties.size());
|
||||
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
|
||||
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
|
||||
assertEquals("flagged", receiverAccessor.getPropertyValue("userFlag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,6 +193,7 @@ public class ImapIdleChannelAdapterParserTests {
|
||||
}
|
||||
public static class TestSearchTermStrategy implements SearchTermStrategy {
|
||||
|
||||
@Override
|
||||
public SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,9 +91,9 @@
|
||||
<mail:inbound-channel-adapter id="imapWithoutStoreUri" channel="testChannel" protocol="imap" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
<mail:imap-idle-channel-adapter id="imapIdleWithoutStoreUri" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
|
||||
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldMarkAsReadTrue" channel="testChannel" protocol="pop3" should-delete-messages="false" auto-startup="false" should-mark-messages-as-read="true"/>
|
||||
|
||||
|
||||
<mail:inbound-channel-adapter id="pop3ShouldMarkAsReadFalse" channel="testChannel" protocol="pop3" should-delete-messages="false" auto-startup="false" should-mark-messages-as-read="false"/>
|
||||
|
||||
<mail:inbound-channel-adapter id="imapShouldMarkAsReadTrue" channel="testChannel" protocol="imap" should-delete-messages="false" auto-startup="false" should-mark-messages-as-read="true"/>
|
||||
@@ -106,7 +106,8 @@
|
||||
|
||||
<!-- INT-2800 -->
|
||||
|
||||
<mail:inbound-channel-adapter id="imapWithSearch" channel="testChannel" protocol="imap" should-delete-messages="false" auto-startup="false"
|
||||
<mail:inbound-channel-adapter id="imapWithSearch" channel="testChannel" protocol="imap"
|
||||
should-delete-messages="false" auto-startup="false" user-flag="flagged"
|
||||
search-term-strategy="searchTermStrategy"/>
|
||||
|
||||
<bean id="searchTermStrategy" class="org.mockito.Mockito" factory-method="mock">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.mail.AbstractMailReceiver;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter;
|
||||
@@ -45,12 +44,14 @@ 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.messaging.MessageChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @since 1.0.5
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@@ -278,7 +279,8 @@ public class InboundChannelAdapterParserTests {
|
||||
public void inboundChannelAdapterRequiresShouldDeleteMessages() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-invalidContext.xml");
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-invalidContext.xml")
|
||||
.close();
|
||||
fail("expected a parser error");
|
||||
}
|
||||
catch(BeanDefinitionStoreException e) {
|
||||
@@ -293,16 +295,19 @@ public class InboundChannelAdapterParserTests {
|
||||
public void imapWithSearchTermStrategy() {
|
||||
AbstractMailReceiver receiver = this.getReceiver("imapWithSearch");
|
||||
assertEquals(ImapMailReceiver.class, receiver.getClass());
|
||||
Object sts = new DirectFieldAccessor(receiver).getPropertyValue("searchTermStrategy");
|
||||
DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
|
||||
Object sts = receiverAccessor.getPropertyValue("searchTermStrategy");
|
||||
assertNotNull(sts);
|
||||
assertSame(context.getBean(SearchTermStrategy.class), sts);
|
||||
assertEquals("flagged", receiverAccessor.getPropertyValue("userFlag"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pop3WithSearchTermStrategy() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml");
|
||||
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml")
|
||||
.close();
|
||||
fail("expected a parser error");
|
||||
}
|
||||
catch(BeanCreationException e) {
|
||||
|
||||
Reference in New Issue
Block a user