camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r760942 - in /camel/branches/camel-1.x: ./ components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java components/camel-xmpp/src/test/resources/
Date Wed, 01 Apr 2009 16:00:51 GMT
Author: ningjiang
Date: Wed Apr  1 16:00:50 2009
New Revision: 760942

URL: http://svn.apache.org/viewvc?rev=760942&view=rev
Log:
Merged revisions 760937 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r760937 | ningjiang | 2009-04-01 23:53:03 +0800 (Wed, 01 Apr 2009) | 1 line
  
  CAMEL-1507 Refactored the MimeMultipartAlternativeTest
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
    camel/branches/camel-1.x/components/camel-xmpp/src/test/resources/   (props changed)

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr  1 16:00:50 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java?rev=760942&r1=760941&r2=760942&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
(original)
+++ camel/branches/camel-1.x/components/camel-mail/src/test/java/org/apache/camel/component/mail/MimeMultipartAlternativeTest.java
Wed Apr  1 16:00:50 2009
@@ -35,12 +35,10 @@
     private String alternativeBody = "hello world! (plain text)";
     private String htmlBody = "<html><body><h1>Hello</h1>World<img
src=\"cid:0001\"></body></html>";
 
-    public void testMultipartEmailWithInlineAttachments() throws Exception {
-        // START SNIPPET: e1
-
-        // create an exchange with a normal body and attachment to be produced as email
+    private void sendMultipartEmail(boolean useInlineattachments) throws Exception {
+     // create an exchange with a normal body and attachment to be produced as email
         MailEndpoint endpoint = context.getEndpoint("smtp://ryan@mymailserver.com?password=secret",
MailEndpoint.class);
-        endpoint.getConfiguration().setUseInlineAttachments(true);
+        endpoint.getConfiguration().setUseInlineAttachments(useInlineattachments);
         endpoint.getConfiguration().setAlternateBodyHeader(MailConfiguration.DEFAULT_ALTERNATE_BODY_HEADER);
 
         // create the exchange with the mail message that is multipart with a file and a
Hello World text/plain message.
@@ -55,10 +53,13 @@
         // start the producer
         producer.start();
         // and let it go (processes the exchange by sending the email)
-        producer.process(exchange);
-
-        // END SNIPPET: e1
+        producer.process(exchange); 
+        
+        producer.stop();
 
+    }
+    
+    private void verifyTheRecivedEmail(String expectString) throws Exception {
         // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
         Thread.sleep(1000);
 
@@ -67,10 +68,11 @@
         Exchange out = mock.assertExchangeReceived(0);
         mock.assertIsSatisfied();
 
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
+        ((MailMessage)out.getIn()).getMessage().writeTo(baos);
+        String dumpedMessage = baos.toString();
+        assertTrue("There should have the " + expectString, dumpedMessage.indexOf(expectString)
> 0);
         if (log.isTraceEnabled()) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
-            ((MailMessage)out.getIn()).getMessage().writeTo(baos);
-            String dumpedMessage = baos.toString();
             log.trace("multipart alternative: \n" + dumpedMessage);
         }
          
@@ -83,59 +85,16 @@
         assertEquals(1, attachments.size());
         assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
 
-        producer.stop();
+        
     }
-
+    public void testMultipartEmailWithInlineAttachments() throws Exception {
+        sendMultipartEmail(true);
+        verifyTheRecivedEmail("Content-Disposition: inline; filename=\"cid:0001\"");
+    }    
+        
     public void testMultipartEmailWithRegularAttachments() throws Exception {
-        // START SNIPPET: e1
-
-        // create an exchange with a normal body and attachment to be produced as email
-        MailEndpoint endpoint = context.getEndpoint("smtp://ryan@mymailserver.com?password=secret",
MailEndpoint.class);
-        endpoint.getConfiguration().setUseInlineAttachments(false);
-        endpoint.getConfiguration().setAlternateBodyHeader(MailConfiguration.DEFAULT_ALTERNATE_BODY_HEADER);
-
-        // create the exchange with the mail message that is multipart with a file and a
Hello World text/plain message.
-        Exchange exchange = endpoint.createExchange();
-        Message in = exchange.getIn();
-        in.setBody(htmlBody);
-        in.setHeader("mail_alternateBody", alternativeBody);
-        in.setHeader("sendInlineAttachments", false);
-        in.addAttachment("cid:0001", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
-
-        // create a producer that can produce the exchange (= send the mail)
-        Producer producer = endpoint.createProducer();
-        // start the producer
-        producer.start();
-        // and let it go (processes the exchange by sending the email)
-        producer.process(exchange);
-
-        // END SNIPPET: e1
-
-        // need some time for the mail to arrive on the inbox (consumed and sent to the mock)
-        Thread.sleep(1000);
-
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        Exchange out = mock.assertExchangeReceived(0);
-        mock.assertIsSatisfied();
-
-        if (log.isTraceEnabled()) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(((MailMessage)out.getIn()).getMessage().getSize());
-            ((MailMessage)out.getIn()).getMessage().writeTo(baos);
-            String dumpedMessage = baos.toString();
-            log.trace("multipart alternative: \n" + dumpedMessage);
-        }
-
-        // plain text
-        assertEquals(alternativeBody, out.getIn().getBody(String.class));
-
-        // attachment
-        Map<String, DataHandler> attachments = out.getIn().getAttachments();
-        assertNotNull("Should not have null attachments", attachments);
-        assertEquals(1, attachments.size());
-        assertEquals("multipart body should have 2 parts", 2, out.getIn().getBody(MimeMultipart.class).getCount());
-
-        producer.stop();
+        sendMultipartEmail(false);
+        verifyTheRecivedEmail("Content-Disposition: attachment; filename=\"cid:0001\"");
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

Propchange: camel/branches/camel-1.x/components/camel-xmpp/src/test/resources/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr  1 16:00:50 2009
@@ -1 +1 @@
-/camel/trunk/components/camel-xmpp/src/test/resources:757693,757743,757865,758539,758563,758617,758692,758990,759362,759887,759931,760890,760909
+/camel/trunk/components/camel-xmpp/src/test/resources:757693,757743,757865,758539,758563,758617,758692,758990,759362,759887,759931,760890,760909,760937



Mime
View raw message