diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java
index 73fb69003a..19b90aa012 100644
--- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java
+++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java
@@ -22,8 +22,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
-import org.springframework.integration.mail.ImapIdleChannelAdapter;
-import org.springframework.integration.mail.ImapMailReceiver;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -35,8 +33,11 @@ import org.springframework.util.StringUtils;
*/
public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
- protected Class> getBeanClass(Element element) {
- return ImapIdleChannelAdapter.class;
+ private static final String BASE_PACKAGE = "org.springframework.integration.mail";
+
+
+ protected String getBeanClassName(Element element) {
+ return BASE_PACKAGE + ".ImapIdleChannelAdapter";
}
protected boolean shouldGenerateId() {
@@ -56,12 +57,17 @@ public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionPa
if (StringUtils.hasText(taskExecutorRef)) {
builder.addPropertyReference("taskExecutor", taskExecutorRef);
}
+ String autoStartup = element.getAttribute("auto-startup");
+ if (StringUtils.hasText(autoStartup)) {
+ builder.addPropertyValue("autoStartup", autoStartup);
+ }
}
private String parseImapMailReceiver(Element element, ParserContext parserContext) {
String uri = element.getAttribute("store-uri");
Assert.hasText(uri, "the 'store-uri' attribute is required");
- BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(ImapMailReceiver.class);
+ BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
+ BASE_PACKAGE + ".ImapMailReceiver");
receiverBuilder.addConstructorArgValue(uri);
String propertiesRef = element.getAttribute("java-mail-properties");
if (StringUtils.hasText(propertiesRef)) {
diff --git a/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd b/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd
index d82ec499a8..50a09e1947 100644
--- a/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd
+++ b/org.springframework.integration.mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-1.0.xsd
@@ -130,7 +130,14 @@
-
+
+
+
+
+
+
diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml
new file mode 100644
index 0000000000..3dbba9958f
--- /dev/null
+++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+ bar
+
+
+
+
+
\ No newline at end of file
diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java
new file mode 100644
index 0000000000..a2c58673c5
--- /dev/null
+++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2002-2009 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.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.util.Properties;
+
+import javax.mail.URLName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.DirectFieldAccessor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.integration.mail.ImapIdleChannelAdapter;
+import org.springframework.integration.mail.ImapMailReceiver;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Mark Fisher
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class ImapIdleChannelAdapterParserTests {
+
+ @Autowired
+ private ApplicationContext context;
+
+
+ @Test
+ public void simpleAdapter() {
+ Object adapter = context.getBean("simpleAdapter");
+ assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
+ DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
+ Object channel = context.getBean("channel");
+ assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
+ assertNull(adapterAccessor.getPropertyValue("taskExecutor"));
+ assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
+ Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
+ assertEquals(ImapMailReceiver.class, receiver.getClass());
+ DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
+ Object url = receiverAccessor.getPropertyValue("url");
+ assertEquals(new URLName("imap:foo"), url);
+ Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
+ assertEquals(0, properties.size());
+ assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
+ }
+
+ @Test
+ public void customAdapter() {
+ Object adapter = context.getBean("customAdapter");
+ assertEquals(ImapIdleChannelAdapter.class, adapter.getClass());
+ DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
+ Object channel = context.getBean("channel");
+ Object executor = context.getBean("executor");
+ assertSame(channel, adapterAccessor.getPropertyValue("outputChannel"));
+ assertSame(executor, adapterAccessor.getPropertyValue("taskExecutor"));
+ assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
+ Object receiver = adapterAccessor.getPropertyValue("mailReceiver");
+ assertEquals(ImapMailReceiver.class, receiver.getClass());
+ DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
+ Object url = receiverAccessor.getPropertyValue("url");
+ assertEquals(new URLName("imap:foo"), url);
+ Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
+ assertEquals("bar", properties.getProperty("foo"));
+ assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
+ }
+
+}
diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests-context.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests-context.xml
new file mode 100644
index 0000000000..47041656c0
--- /dev/null
+++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests-context.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+ bar
+
+
+
+
+
+
+
diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests.java b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests.java
index b2780a1e77..7707976ca9 100644
--- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests.java
+++ b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/PollingMailSourceParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2009 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.
@@ -16,20 +16,73 @@
package org.springframework.integration.mail.config;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import java.util.Properties;
+
+import javax.mail.URLName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.DirectFieldAccessor;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
+import org.springframework.integration.mail.ImapMailReceiver;
+import org.springframework.integration.mail.MailReceivingMessageSource;
+import org.springframework.integration.mail.Pop3MailReceiver;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Jonas Partner
+ * @author Mark Fisher
*/
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
public class PollingMailSourceParserTests {
+ @Autowired
+ private ApplicationContext context;
+
+
@Test
- public void testPop3(){
- ApplicationContext context = new ClassPathXmlApplicationContext("pollingMailSourceParserTests.xml", PollingMailSourceParserTests.class);
- context.getBean("pollingPop3");
+ public void imapAdapter() {
+ Object adapter = context.getBean("imapAdapter");
+ assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
+ DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
+ assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
+ Object channel = context.getBean("channel");
+ assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
+ Object source = adapterAccessor.getPropertyValue("source");
+ assertEquals(MailReceivingMessageSource.class, source.getClass());
+ Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
+ assertEquals(ImapMailReceiver.class, receiver.getClass());
+ DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
+ Object url = receiverAccessor.getPropertyValue("url");
+ assertEquals(new URLName("imap:foo"), url);
+ Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
+ assertEquals("bar", properties.getProperty("foo"));
+ }
+
+ @Test
+ public void pop3Adapter() {
+ Object adapter = context.getBean("pop3Adapter");
+ assertEquals(SourcePollingChannelAdapter.class, adapter.getClass());
+ DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
+ assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup"));
+ Object channel = context.getBean("channel");
+ assertEquals(channel, adapterAccessor.getPropertyValue("outputChannel"));
+ Object source = adapterAccessor.getPropertyValue("source");
+ assertEquals(MailReceivingMessageSource.class, source.getClass());
+ Object receiver = new DirectFieldAccessor(source).getPropertyValue("mailReceiver");
+ assertEquals(Pop3MailReceiver.class, receiver.getClass());
+ DirectFieldAccessor receiverAccessor = new DirectFieldAccessor(receiver);
+ Object url = receiverAccessor.getPropertyValue("url");
+ assertEquals(new URLName("pop3:bar"), url);
+ Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
+ assertEquals("bar", properties.getProperty("foo"));
}
}
diff --git a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/pollingMailSourceParserTests.xml b/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/pollingMailSourceParserTests.xml
deleted file mode 100644
index 66d3afe2c7..0000000000
--- a/org.springframework.integration.mail/src/test/java/org/springframework/integration/mail/config/pollingMailSourceParserTests.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-