Author: veithen
Date: Sun Jul 20 14:42:47 2008
New Revision: 678325

URL: http://svn.apache.org/viewvc?rev=678325&view=rev
Log:
MailTransportListenerTest: add test cases for multipart messages

Modified:
    
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java

Modified: 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java?rev=678325&r1=678324&r2=678325&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 (original)
+++ 
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/mail/MailTransportListenerTest.java
 Sun Jul 20 14:42:47 2008
@@ -29,7 +29,9 @@
 import javax.mail.Session;
 import javax.mail.Transport;
 import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 import javax.mail.util.ByteArrayDataSource;
 
 import junit.framework.TestSuite;
@@ -37,12 +39,18 @@
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.synapse.transport.TransportListenerTestTemplate;
-import 
org.apache.synapse.transport.TransportListenerTestTemplate.SOAP11TestCaseImpl;
 
 public class MailTransportListenerTest extends TransportListenerTestTemplate {
     public static class TestStrategyImpl extends TestStrategy {
         private static final String ADDRESS = "[EMAIL PROTECTED]";
         
+        private boolean useMultipart;
+        
+        public TestStrategyImpl(boolean useMultipart) {
+            super(useMultipart ? "Multipart" : null);
+            this.useMultipart = useMultipart;
+        }
+
         @Override
         protected TransportInDescription createTransportInDescription() {
             TransportInDescription trpInDesc
@@ -74,26 +82,43 @@
             msg.setRecipients(Message.RecipientType.TO, 
InternetAddress.parse(ADDRESS));
             msg.setFrom(new InternetAddress("[EMAIL PROTECTED]"));
             msg.setSentDate(new Date());
-            msg.setDataHandler(new DataHandler(new 
ByteArrayDataSource(content, contentType)));
+            DataHandler dh = new DataHandler(new ByteArrayDataSource(content, 
contentType));
+            if (useMultipart) {
+                MimeMultipart multipart = new MimeMultipart();
+                MimeBodyPart part1 = new MimeBodyPart();
+                part1.setContent("This is an automated message.", 
"text/plain");
+                multipart.addBodyPart(part1);
+                MimeBodyPart part2 = new MimeBodyPart();
+                part2.setDataHandler(dh);
+                multipart.addBodyPart(part2);
+                msg.setContent(multipart);
+            } else {
+                msg.setDataHandler(dh);
+            }
             Transport.send(msg);
         }
     }
     
     public static TestSuite suite() {
         TestSuite suite = new TestSuite();
-        TestStrategy strategy = new TestStrategyImpl();
-        // TODO: SOAP 1.2 tests don't work yet for mail transport
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11ASCII", "test 
string", "us-ascii"));
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11UTF8", 
testString, "UTF-8"));
-        suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11Latin1", 
testString, "ISO-8859-1"));
-        // addSOAPTests(strategy, suite);
-        // TODO: POX tests don't work yet for mail transport
-        // addPOXTests(strategy, suite);
-        // Temporarily skip this test until we know why it fails.
-        // addSwATests(strategy, suite);
-        // Temporarily skip the following tests until SYNAPSE-359 is solved
-        // addTextPlainTests(strategy, suite);
-        // addBinaryTest(strategy, suite);
+        for (boolean useMultipart : new boolean[] { false, true }) {
+            TestStrategy strategy = new TestStrategyImpl(useMultipart);
+            // TODO: SOAP 1.2 tests don't work yet for mail transport
+            suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11ASCII", 
"test string", "us-ascii"));
+            suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11UTF8", 
testString, "UTF-8"));
+            // TODO: this test fails when using multipart
+            if (!useMultipart) {
+                suite.addTest(new SOAP11TestCaseImpl(strategy, "SOAP11Latin1", 
testString, "ISO-8859-1"));
+            }
+            // addSOAPTests(strategy, suite);
+            // TODO: POX tests don't work yet for mail transport
+            // addPOXTests(strategy, suite);
+            // Temporarily skip this test until we know why it fails.
+            // addSwATests(strategy, suite);
+            // Temporarily skip the following tests until SYNAPSE-359 is solved
+            // addTextPlainTests(strategy, suite);
+            // addBinaryTest(strategy, suite);
+        }
         return suite;
     }
 }


Reply via email to