Author: veithen
Date: Sun Aug 21 16:57:36 2011
New Revision: 1160010

URL: http://svn.apache.org/viewvc?rev=1160010&view=rev
Log:
AXIOM-377: Make sure that buildWithAttachments still behaves as expected, i.e. 
completely reads all referenced MIME parts.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1160010&r1=1160009&r2=1160010&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
 Sun Aug 21 16:57:36 2011
@@ -48,9 +48,6 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.NullOutputStream;
 
 public class AttachmentsTest extends AbstractTestCase {
-    String img1FileName = "mtom/img/test.jpg";
-    String img2FileName = "mtom/img/test2.jpg";
-    
     private static String getAttachmentsDir() {
         File attachmentsDir = new File(System.getProperty("basedir", ".") + 
"/target/attachments");
         attachmentsDir.mkdirs();
@@ -65,7 +62,7 @@ public class AttachmentsTest extends Abs
                 
.getDataHandler("2.urn:uuid:[email protected]");
         InputStream dataIs = dh.getDataSource().getInputStream();
 
-        InputStream expectedDataIs = getTestResource(img2FileName);
+        InputStream expectedDataIs = 
getTestResource(TestConstants.MTOM_MESSAGE_IMAGE2);
 
         // Compare data across streams
         IOTestUtils.compareStreams(dataIs, expectedDataIs);
@@ -264,11 +261,11 @@ public class AttachmentsTest extends Abs
         IncomingAttachmentStreams ias = 
attachments.getIncomingAttachmentStreams();
 
         dataIs = ias.getNextStream();
-        expectedDataIs = getTestResource(img1FileName);
+        expectedDataIs = getTestResource(TestConstants.MTOM_MESSAGE_IMAGE1);
         IOTestUtils.compareStreams(dataIs, expectedDataIs);
 
         dataIs = ias.getNextStream();
-        expectedDataIs = getTestResource(img2FileName);
+        expectedDataIs = getTestResource(TestConstants.MTOM_MESSAGE_IMAGE2);
         IOTestUtils.compareStreams(dataIs, expectedDataIs);
 
         // Confirm that no more streams are left

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java?rev=1160010&r1=1160009&r2=1160010&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/TestConstants.java
 Sun Aug 21 16:57:36 2011
@@ -43,6 +43,8 @@ public class TestConstants {
                         "charset=UTF-8;" +
                         "action=\"mtomSample\"";
     public static final String MTOM_MESSAGE_INLINED = 
"mtom/MTOMAttachmentStream_inlined.xml";
+    public static final String MTOM_MESSAGE_IMAGE1 = "mtom/img/test.jpg";
+    public static final String MTOM_MESSAGE_IMAGE2 = "mtom/img/test2.jpg";
     
     
     private TestConstants() {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java?rev=1160010&r1=1160009&r2=1160010&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java
 Sun Aug 21 16:57:36 2011
@@ -486,7 +486,8 @@ public abstract class TextNodeImpl exten
     public void buildWithAttachments() {
         this.build();
         if (isOptimized()) {
-            this.getDataHandler();
+            // The call to getDataSource ensures that the MIME part is 
completely read
+            ((DataHandler)this.getDataHandler()).getDataSource();
         }
     }
 

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=1160010&r1=1160009&r2=1160010&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
 Sun Aug 21 16:57:36 2011
@@ -432,7 +432,8 @@ public class OMTextImpl extends OMNodeIm
             this.build();
         }
         if (isOptimized()) {
-            this.getDataHandler();
+            // The call to getDataSource ensures that the MIME part is 
completely read
+            ((DataHandler)this.getDataHandler()).getDataSource();
         }
     }
     

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java?rev=1160010&r1=1160009&r2=1160010&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java
 Sun Aug 21 16:57:36 2011
@@ -105,6 +105,7 @@ public class SOAPTestSuiteBuilder extend
         addTest(new 
org.apache.axiom.ts.soap11.header.TestGetHeaderBlocksWithNSURIWithParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap11.header.TestGetHeadersToProcessWithParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.envelope.TestAddElementAfterBody(metaFactory));
+        addTest(new 
org.apache.axiom.ts.soap12.envelope.TestBuildWithAttachments(metaFactory));
         addTest(new org.apache.axiom.ts.soap12.fault.TestGetNode(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.fault.TestGetNodeWithParser(metaFactory));
         addTest(new 
org.apache.axiom.ts.soap12.fault.TestMoreChildrenAddition(metaFactory));

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java?rev=1160010&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java
 Sun Aug 21 16:57:36 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.axiom.ts.soap12.envelope;
+
+import java.io.InputStream;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestBuildWithAttachments extends AxiomTestCase {
+    public TestBuildWithAttachments(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        InputStream in = 
AbstractTestCase.getTestResource(TestConstants.MTOM_MESSAGE);
+        Attachments attachments = new Attachments(in, 
TestConstants.MTOM_MESSAGE_CONTENT_TYPE);
+        SOAPEnvelope envelope = new MTOMStAXSOAPModelBuilder(
+                
StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()),
+                metaFactory.getSOAP12Factory(), attachments,
+                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI).getSOAPEnvelope();
+        envelope.buildWithAttachments();
+        in.close();
+        Iterator it = envelope.getBody().getFirstElement().getChildElements();
+        OMElement image1 = (OMElement)it.next();
+        OMElement image2 = (OMElement)it.next();
+        
+        
IOTestUtils.compareStreams(((DataHandler)((OMText)image1.getFirstOMChild()).getDataHandler()).getInputStream(),
+                
AbstractTestCase.getTestResource(TestConstants.MTOM_MESSAGE_IMAGE1));
+
+        
IOTestUtils.compareStreams(((DataHandler)((OMText)image2.getFirstOMChild()).getDataHandler()).getInputStream(),
+                
AbstractTestCase.getTestResource(TestConstants.MTOM_MESSAGE_IMAGE2));
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestBuildWithAttachments.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to