INT-982, INT-1158, INT-1159, INT-1160, INT-1161, INT-1162, INT-1163 inbound mail adapter updates

This commit is contained in:
Mark Fisher
2010-06-10 00:36:34 +00:00
parent 589bad1eba
commit ad8a45fec3
11 changed files with 760 additions and 164 deletions

View File

@@ -0,0 +1,106 @@
<?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-982 -->
<mail:inbound-channel-adapter id="pop3ShouldDeleteTrue" store-uri="pop3:test" channel="testChannel" should-delete-messages="true" auto-startup="false"/>
<mail:inbound-channel-adapter id="pop3ShouldDeleteFalse" store-uri="pop3:test" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapShouldDeleteTrue" store-uri="imap:test" channel="testChannel" should-delete-messages="true" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapShouldDeleteFalse" store-uri="imap:test" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<!-- INT-1158 -->
<context:property-placeholder properties-ref="configProperties"/>
<util:properties id="configProperties">
<prop key="mail.delete.true">true</prop>
<prop key="mail.delete.false">false</prop>
</util:properties>
<mail:inbound-channel-adapter id="pop3ShouldDeleteTrueProperty" store-uri="pop3:test" channel="testChannel" should-delete-messages="${mail.delete.true}" auto-startup="false"/>
<mail:inbound-channel-adapter id="pop3ShouldDeleteFalseProperty" store-uri="pop3:test" channel="testChannel" should-delete-messages="${mail.delete.false}" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapShouldDeleteTrueProperty" store-uri="imap:test" channel="testChannel" should-delete-messages="${mail.delete.true}" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapShouldDeleteFalseProperty" store-uri="imap:test" channel="testChannel" should-delete-messages="${mail.delete.false}" auto-startup="false"/>
<!-- INT-1159 -->
<mail:inbound-channel-adapter id="pop3WithAuthenticator" store-uri="pop3:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapWithAuthenticator" store-uri="imap:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:imap-idle-channel-adapter id="imapIdleWithAuthenticator" store-uri="imap:test" authenticator="testAuthenticator" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<bean id="testAuthenticator" class="org.springframework.integration.mail.config.InboundChannelAdapterParserTests$TestAuthenticator"/>
<!-- INT-1160 -->
<mail:inbound-channel-adapter id="pop3WithMaxFetchSize" store-uri="pop3:test" max-fetch-size="11" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:inbound-channel-adapter id="pop3WithMaxFetchSizeFallsBackToPollerMax" store-uri="pop3:test" channel="testChannel" should-delete-messages="false" auto-startup="false">
<si:poller max-messages-per-poll="99">
<si:interval-trigger interval="30" time-unit="SECONDS"/>
</si:poller>
</mail:inbound-channel-adapter>
<mail:inbound-channel-adapter id="imapWithMaxFetchSize" store-uri="imap:test" max-fetch-size="22" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:imap-idle-channel-adapter id="imapIdleWithMaxFetchSize" store-uri="imap:test" max-fetch-size="33" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<!-- INT-1161 -->
<mail:inbound-channel-adapter id="pop3WithSession" store-uri="pop3:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:inbound-channel-adapter id="imapWithSession" store-uri="imap:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<mail:imap-idle-channel-adapter id="imapIdleWithSession" store-uri="imap:test" session="testSession" channel="testChannel" should-delete-messages="false" auto-startup="false"/>
<bean id="testSession" class="javax.mail.Session" factory-method="getInstance">
<constructor-arg>
<props>
<prop key="foo">bar</prop>
</props>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.integration.mail.config.InboundChannelAdapterParserTests$TestAuthenticator"/>
</constructor-arg>
</bean>
<!-- INT-1162 -->
<mail:inbound-channel-adapter id="pop3WithoutStoreUri" channel="testChannel" protocol="pop3" should-delete-messages="false" auto-startup="false"/>
<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"/>
<!-- COMMON CONFIGURATION -->
<si:channel id="testChannel"/>
<si:poller default="true" max-messages-per-poll="1">
<si:interval-trigger interval="60" time-unit="SECONDS"/>
</si:poller>
</beans>

View File

@@ -0,0 +1,20 @@
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- INT-1163 -->
<mail:inbound-channel-adapter id="invalid" channel="testChannel" protocol="pop3" auto-startup="false"/>
<si:channel id="testChannel"/>
<si:poller default="true" max-messages-per-poll="1">
<si:interval-trigger interval="60" time-unit="SECONDS"/>
</si:poller>
</beans>

View File

@@ -0,0 +1,277 @@
/*
* Copyright 2002-2010 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.mail.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import javax.mail.Authenticator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xml.sax.SAXParseException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @since 1.0.5
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class InboundChannelAdapterParserTests {
@Autowired
private ApplicationContext context;
//==================== INT-982 =====================
@Test
public void pop3ShouldDeleteTrue() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrue");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertTrue(value);
}
@Test
public void pop3ShouldDeleteFalse() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteFalse");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertFalse(value);
}
@Test
public void imapShouldDeleteTrue() {
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteTrue");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertTrue(value);
}
@Test
public void imapShouldDeleteFalse() {
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteFalse");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertFalse(value);
}
//==================== INT-1158 ====================
@Test
public void pop3ShouldDeleteTrueProperty() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrueProperty");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertTrue(value);
}
@Test
public void pop3ShouldDeleteFalseProperty() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteFalseProperty");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertFalse(value);
}
@Test
public void imapShouldDeleteTrueProperty() {
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteTrueProperty");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertTrue(value);
}
@Test
public void imapShouldDeleteFalseProperty() {
AbstractMailReceiver receiver = this.getReceiver("imapShouldDeleteFalseProperty");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Boolean value = (Boolean) new DirectFieldAccessor(receiver).getPropertyValue("shouldDeleteMessages");
assertFalse(value);
}
//==================== INT-1159 ====================
@Test
public void pop3WithAuthenticator() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithAuthenticator");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
assertNotNull(authenticator);
assertEquals(context.getBean("testAuthenticator"), authenticator);
}
@Test
public void imapWithAuthenticator() {
AbstractMailReceiver receiver = this.getReceiver("imapWithAuthenticator");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
assertNotNull(authenticator);
assertEquals(context.getBean("testAuthenticator"), authenticator);
}
@Test
public void imapIdleWithAuthenticator() {
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithAuthenticator");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object authenticator = new DirectFieldAccessor(receiver).getPropertyValue("javaMailAuthenticator");
assertNotNull(authenticator);
assertEquals(context.getBean("testAuthenticator"), authenticator);
}
@SuppressWarnings("unused")
private static class TestAuthenticator extends Authenticator {
}
//==================== INT-1160 ====================
@Test
public void pop3WithMaxFetchSize() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithMaxFetchSize");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
assertEquals(11, value);
}
@Test
public void pop3WithMaxFetchSizeFallsBackToPollerMax() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithMaxFetchSizeFallsBackToPollerMax");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
assertEquals(99, value);
}
@Test
public void imapWithMaxFetchSize() {
AbstractMailReceiver receiver = this.getReceiver("imapWithMaxFetchSize");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
assertEquals(22, value);
}
@Test
public void imapIdleWithMaxFetchSize() {
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithMaxFetchSize");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object value = new DirectFieldAccessor(receiver).getPropertyValue("maxFetchSize");
assertEquals(33, value);
}
//==================== INT-1161 ====================
@Test
public void pop3WithSession() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithSession");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
assertNotNull(session);
assertEquals(context.getBean("testSession"), session);
}
@Test
public void imapWithSession() {
AbstractMailReceiver receiver = this.getReceiver("imapWithSession");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
assertNotNull(session);
assertEquals(context.getBean("testSession"), session);
}
@Test
public void imapIdleWithSession() {
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithSession");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object session = new DirectFieldAccessor(receiver).getPropertyValue("session");
assertNotNull(session);
assertEquals(context.getBean("testSession"), session);
}
//==================== INT-1162 ====================
@Test
public void pop3WithoutStoreUri() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithoutStoreUri");
assertEquals(Pop3MailReceiver.class, receiver.getClass());
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
assertNull(url);
}
@Test
public void imapWithoutStoreUri() {
AbstractMailReceiver receiver = this.getReceiver("imapWithoutStoreUri");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
assertNull(url);
}
@Test
public void imapIdleWithoutStoreUri() {
AbstractMailReceiver receiver = this.getReceiver("imapIdleWithoutStoreUri");
assertEquals(ImapMailReceiver.class, receiver.getClass());
Object url = new DirectFieldAccessor(receiver).getPropertyValue("url");
assertNull(url);
}
//==================== INT-1163 ====================
@Test
public void inboundChannelAdapterRequiresShouldDeleteMessages() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-invalidContext.xml");
fail("expected a parser error");
}
catch(BeanDefinitionStoreException e) {
assertEquals(SAXParseException.class, e.getCause().getClass());
}
}
//===================== COMMON =====================
private AbstractMailReceiver getReceiver(String name) {
Object adapter = context.getBean(name);
Object target = (adapter instanceof ImapIdleChannelAdapter) ? adapter
: new DirectFieldAccessor(adapter).getPropertyValue("source");
return (AbstractMailReceiver) new DirectFieldAccessor(target).getPropertyValue("mailReceiver");
}
}

View File

@@ -16,10 +16,10 @@
<integration:channel id="channel"/>
<mail:inbound-channel-adapter id="imapAdapter"
store-uri="imap:foo" java-mail-properties="props" channel="channel" auto-startup="false"/>
store-uri="imap:foo" java-mail-properties="props" channel="channel" should-delete-messages="false" auto-startup="false"/>
<mail:inbound-channel-adapter id="pop3Adapter"
store-uri="pop3:bar" java-mail-properties="props" channel="channel" auto-startup="false"/>
store-uri="pop3:bar" java-mail-properties="props" channel="channel" should-delete-messages="true" auto-startup="false"/>
<util:properties id="props">
<prop key="foo">bar</prop>