You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/07 11:18:21 UTC

[camel] 01/03: Added test based on user forum issue

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit aa0b89a53c561ca17c75ebb5f283cad446125495
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 7 10:35:29 2018 +0100

    Added test based on user forum issue
---
 components/camel-mail/pom.xml                      |  2 +-
 .../component/mail/MailSplitAttachmentsTest.java   |  1 -
 ...st.java => SpringMailSplitAttachmentsTest.java} | 37 ++++++-------------
 .../mail/SpringMailSplitAttachmentsTest.xml        | 42 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/components/camel-mail/pom.xml b/components/camel-mail/pom.xml
index 4812751..d9697d9 100644
--- a/components/camel-mail/pom.xml
+++ b/components/camel-mail/pom.xml
@@ -69,7 +69,7 @@
         <!-- testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
+            <artifactId>camel-test-spring</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java
index 9609280..6b86d1f 100644
--- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java
@@ -45,7 +45,6 @@ public class MailSplitAttachmentsTest extends CamelTestSupport {
         Mailbox.clearAll();
     }
 
-
     @Before
     public void setup() {
         // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.java
similarity index 79%
copy from components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java
copy to components/camel-mail/src/test/java/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.java
index 9609280..8a055e2 100644
--- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java
+++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.java
@@ -23,29 +23,33 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Producer;
-import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
 import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- *  Tests the {@link SplitAttachmentsExpression}.
+ *  Spring XML version of {@link MailSplitAttachmentsTest}
  */
-public class MailSplitAttachmentsTest extends CamelTestSupport {
+public class SpringMailSplitAttachmentsTest extends CamelSpringTestSupport {
 
     private Endpoint endpoint;
-    private SplitAttachmentsExpression splitAttachmentsExpression;
     private Exchange exchange;
 
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.xml");
+    }
+
     @Before
     public void clearMailBox() {
         Mailbox.clearAll();
     }
 
-
     @Before
     public void setup() {
         // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
@@ -90,6 +94,7 @@ public class MailSplitAttachmentsTest extends CamelTestSupport {
         mock.expectedMessageCount(2);
 
         // set the expression to extract the attachments as byte[]s
+        SplitAttachmentsExpression splitAttachmentsExpression = context.getRegistry().findByType(SplitAttachmentsExpression.class).iterator().next();
         splitAttachmentsExpression.setExtractAttachments(true);
 
         Producer producer = endpoint.createProducer();
@@ -115,24 +120,4 @@ public class MailSplitAttachmentsTest extends CamelTestSupport {
         assertArrayEquals(expected2, second.getBody(byte[].class));
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-
-        splitAttachmentsExpression = new SplitAttachmentsExpression(false);
-
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                // START SNIPPET: e1
-                from("pop3://james@mymailserver.com?password=secret&consumer.initialDelay=100&consumer.delay=100")
-                    .to("log:email")
-                    // use the SplitAttachmentsExpression which will split the message per attachment
-                    .split(splitAttachmentsExpression)
-                        // each message going to this mock has a single attachment
-                        .to("mock:split")
-                    .end();
-                // END SNIPPET: e1
-            }
-        };
-    }
 }
diff --git a/components/camel-mail/src/test/resources/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.xml b/components/camel-mail/src/test/resources/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.xml
new file mode 100644
index 0000000..a3d1276
--- /dev/null
+++ b/components/camel-mail/src/test/resources/org/apache/camel/component/mail/SpringMailSplitAttachmentsTest.xml
@@ -0,0 +1,42 @@
+<?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.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <bean id="splitAttachments" class="org.apache.camel.component.mail.SplitAttachmentsExpression">
+    <constructor-arg index="0" value="false"/>
+  </bean>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="pop3://james@mymailserver.com?password=secret&amp;consumer.initialDelay=100&amp;consumer.delay=100"/>
+      <to uri="log:email"/>
+      <split>
+        <ref>splitAttachments</ref>
+        <to uri="mock:split"/>
+      </split>
+    </route>
+  </camelContext>
+
+</beans>