You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/04/30 22:35:07 UTC

svn commit: r1741812 - in /webservices/axiom/branches/1.2.x: ./ axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Author: veithen
Date: Sat Apr 30 20:35:07 2016
New Revision: 1741812

URL: http://svn.apache.org/viewvc?rev=1741812&view=rev
Log:
Merge r1741786 and r1741791 to the 1.2 branch.

Modified:
    webservices/axiom/branches/1.2.x/   (props changed)
    webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Propchange: webservices/axiom/branches/1.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Apr 30 20:35:07 2016
@@ -14,4 +14,4 @@
 /webservices/axiom/branches/maven-site-plugin-3.5:1731125-1732708
 /webservices/axiom/branches/namespaceURIInterning:1293148-1293587
 /webservices/axiom/branches/osgi-redesign:1180368-1180596
-/webservices/axiom/trunk:1726096,1726101,1726419,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727541,1727549,1727640,1727660,1727688,1727743,1727755,1727758,1727761,1728022,1728240,1728929,1730261,1730278,1731157,1731314-1731315,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743,1739812,1740914
+/webservices/axiom/trunk:1726096,1726101,1726419,1726474-1726475,1726489,1727220,1727422,1727435,1727496,1727541,1727549,1727640,1727660,1727688,1727743,1727755,1727758,1727761,1728022,1728240,1728929,1730261,1730278,1731157,1731314-1731315,1731373,1731376,1731378,1731406,1731522,1731541,1732710,1733743,1739812,1740914,1741786,1741791

Modified: webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1741812&r1=1741811&r2=1741812&view=diff
==============================================================================
--- webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/axiom/branches/1.2.x/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Sat Apr 30 20:35:07 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.attachments;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -25,6 +27,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.util.Arrays;
@@ -43,7 +46,10 @@ import javax.mail.internet.MimeMultipart
 import javax.mail.util.ByteArrayDataSource;
 
 import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
+import org.apache.axiom.blob.Blobs;
+import org.apache.axiom.blob.MemoryBlob;
 import org.apache.axiom.ext.activation.SizeAwareDataSource;
+import org.apache.axiom.mime.ContentTypeBuilder;
 import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.MTOMConstants;
@@ -163,11 +169,24 @@ public class AttachmentsTest extends Abs
 
     private void testGetRootPartContentID(String contentTypeStartParam, String contentId)
             throws Exception {
-        // It doesn't actually matter what the stream *is* it just needs to exist
-        String contentType = "multipart/related; boundary=\"" + MTOMSample.SAMPLE1.getBoundary() +
-                "\"; type=\"text/xml\"; start=\"" + contentTypeStartParam + "\"";
-        InputStream inStream = MTOMSample.SAMPLE1.getInputStream();
-        Attachments attachments = new Attachments(inStream, contentType);
+        MimeMessage message = new MimeMessage((Session)null);
+        MimeMultipart mp = new MimeMultipart("related");
+        MimeBodyPart rootPart = new MimeBodyPart();
+        rootPart.setText("<root/>", "utf-8", "xml");
+        rootPart.addHeader("Content-Transfer-Encoding", "binary");
+        rootPart.addHeader("Content-ID", "<" + contentId + ">");
+        mp.addBodyPart(rootPart);
+        message.setContent(mp);
+        message.saveChanges();
+        MemoryBlob blob = Blobs.createMemoryBlob();
+        OutputStream out = blob.getOutputStream();
+        mp.writeTo(out);
+        out.close();
+
+        ContentTypeBuilder contentType = new ContentTypeBuilder(message.getContentType());
+        contentType.setParameter("start", contentTypeStartParam);
+        
+        Attachments attachments = new Attachments(blob.getInputStream(), contentType.toString());
         assertEquals("Did not obtain correct content ID", contentId,
                 attachments.getRootPartContentID());
     }
@@ -210,8 +229,8 @@ public class AttachmentsTest extends Abs
     public void testGetRootPartContentTypeWithContentIDMismatch() {
         String contentType = "multipart/related; boundary=\"" + MTOMSample.SAMPLE1.getBoundary() +
                 "\"; type=\"text/xml\"; start=\"<wr...@example.org>\"";
-        Attachments attachments = new Attachments(MTOMSample.SAMPLE1.getInputStream(), contentType);
         try {
+            Attachments attachments = new Attachments(MTOMSample.SAMPLE1.getInputStream(), contentType);
             attachments.getRootPartContentType();
             fail("Expected OMException");
         } catch (OMException ex) {
@@ -767,4 +786,40 @@ public class AttachmentsTest extends Abs
                 MTOMSample.QUOTED_PRINTABLE.getPart(1),
                 dh.getInputStream());
     }
+
+    /**
+     * Tests access to a root part that doesn't have a content ID. In this case, the
+     * {@link Attachments} API generates a fake content ID.
+     * 
+     * @throws Exception
+     */
+    public void testFakeRootPartContentID() throws Exception {
+        MimeMessage message = new MimeMessage((Session)null);
+        MimeMultipart mp = new MimeMultipart("related");
+        
+        MimeBodyPart bp1 = new MimeBodyPart();
+        bp1.setText("<root/>", "utf-8", "xml");
+        bp1.addHeader("Content-Transfer-Encoding", "binary");
+        mp.addBodyPart(bp1);
+        
+        MimeBodyPart bp2 = new MimeBodyPart();
+        bp2.setDataHandler(new DataHandler("Test", "text/plain"));
+        bp2.addHeader("Content-Transfer-Encoding", "binary");
+        mp.addBodyPart(bp2);
+        
+        message.setContent(mp);
+        message.saveChanges();
+        
+        MemoryBlob blob = Blobs.createMemoryBlob();
+        OutputStream out = blob.getOutputStream();
+        mp.writeTo(out);
+        out.close();
+        String contentType = message.getContentType();
+        
+        Attachments attachments = new Attachments(blob.getInputStream(), contentType);
+        String rootPartContentID = attachments.getRootPartContentID();
+        assertThat(rootPartContentID).isNotNull();
+        DataHandler rootPart = attachments.getDataHandler(rootPartContentID);
+        assertThat(rootPart.getContent()).isEqualTo("<root/>");
+    }
 }