Author: davsclaus
Date: Thu Jan 22 00:44:15 2009
New Revision: 736589

URL: http://svn.apache.org/viewvc?rev=736589&view=rev
Log:
CAMEL-505: mail endpoint can now be configured as spring bean

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/
    
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
   (with props)
    
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/
    
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
   (with props)
Modified:
    
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
    camel/trunk/tests/camel-itest/pom.xml

Modified: 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java?rev=736589&r1=736588&r2=736589&view=diff
==============================================================================
--- 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
 Thu Jan 22 00:44:15 2009
@@ -24,6 +24,7 @@
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
 import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.mail.javamail.JavaMailSenderImpl;
 
@@ -36,6 +37,10 @@
     private MailBinding binding;
     private MailConfiguration configuration;
 
+    public MailEndpoint() {
+        this.binding = new MailBinding();
+    }
+
     public MailEndpoint(String uri, MailComponent component, MailConfiguration 
configuration) {
         super(uri, component);
         this.configuration = configuration;
@@ -116,11 +121,15 @@
         this.binding = binding;
     }
 
-    public boolean isSingleton() {
-        return false;
-    }
-
     public MailConfiguration getConfiguration() {
         return configuration;
     }
+
+    public void setConfiguration(MailConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    public boolean isSingleton() {
+        return false;
+    }
 }

Modified: camel/trunk/tests/camel-itest/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=736589&r1=736588&r2=736589&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Thu Jan 22 00:44:15 2009
@@ -59,6 +59,18 @@
         
         <dependency>
             <groupId>org.apache.camel</groupId>
+            <artifactId>camel-mail</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jvnet.mock-javamail</groupId>
+            <artifactId>mock-javamail</artifactId>
+            <version>1.7</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
             <artifactId>camel-ftp</artifactId>
             <scope>test</scope>
         </dependency>

Added: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java?rev=736589&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
 (added)
+++ 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
 Thu Jan 22 00:44:15 2009
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.itest.mail;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.jvnet.mock_javamail.Mailbox;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import 
org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * Unit testing Mail configured using spring bean
+ */
+...@contextconfiguration
+public class SpringMailEndpointTest extends AbstractJUnit38SpringContextTests {
+
+    @Autowired
+    protected ProducerTemplate template;
+    @EndpointInject(name = "myMailEndpoint")
+    protected Endpoint inputFTP;
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint result;
+
+    public void testMailEndpointAsSpringBean() throws Exception {
+        Mailbox.clearAll();
+
+        String body = "Hello Claus.\nYes it does.\n\nRegards James.";
+
+        result.expectedMessageCount(1);
+        result.expectedHeaderReceived("subject", "Hello Camel");
+        result.expectedBodiesReceived(body);
+
+        template.sendBodyAndHeader("smtp://jam...@localhost", body, "subject", 
"Hello Camel");
+
+        result.assertIsSatisfied();
+    }
+
+}
\ No newline at end of file

Propchange: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/mail/SpringMailEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml?rev=736589&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
 (added)
+++ 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
 Thu Jan 22 00:44:15 2009
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://activemq.apache.org/camel/schema/spring 
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+    <bean id="myMailEndpoint" 
class="org.apache.camel.component.mail.MailEndpoint">
+        <property name="camelContext" ref="camel"/>
+        <property name="configuration" ref="mailConfig"/>
+    </bean>
+
+    <bean id="mailConfig" 
class="org.apache.camel.component.mail.MailConfiguration">
+        <property name="host" value="localhost"/>
+        <property name="port" value="110"/>
+        <property name="username" value="james2"/>
+        <property name="password" value="james2"/>
+        <property name="protocol" value="pop3"/>
+    </bean>
+
+    <!-- START SNIPPET: example -->
+    <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+        <template id="camelTemplate"/>
+
+        <route>
+            <from ref="myMailEndpoint"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
+
+</beans>

Propchange: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/mail/SpringMailEndpointTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to