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 2012/12/24 09:39:57 UTC

svn commit: r1425602 - in /webservices/commons/trunk/modules/axiom/modules: axiom-tests/src/test/java/org/apache/axiom/attachments/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/

Author: veithen
Date: Mon Dec 24 08:39:57 2012
New Revision: 1425602

URL: http://svn.apache.org/viewvc?rev=1425602&view=rev
Log:
AXIOM-311: Refactored a test case.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1425602&r1=1425601&r2=1425602&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Mon Dec 24 08:39:57 2012
@@ -20,110 +20,18 @@
 package org.apache.axiom.attachments;
 
 import org.apache.axiom.om.AbstractTestCase;
-import org.apache.axiom.om.MIMEResource;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.TestConstants;
 import org.apache.axiom.om.impl.MIMEOutputUtils;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.util.StAXParserConfiguration;
 import org.apache.axiom.soap.SOAPModelBuilder;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.StringWriter;
 
 public class AttachmentsTest extends AbstractTestCase {
-    public void testWritingBinaryAttachments() throws Exception {
-        MIMEResource testMessage = TestConstants.MTOM_MESSAGE;
-
-        // Read in message: SOAPPart and 2 image attachments
-        InputStream inStream = getTestResource(testMessage.getName());
-        Attachments attachments = new Attachments(inStream, testMessage.getContentType());
-        
-        attachments.getRootPartInputStream();
-
-        String[] contentIDs = attachments.getAllContentIDs();
-        
-        OMOutputFormat oof = new OMOutputFormat();
-        oof.setDoOptimize(true);
-        oof.setMimeBoundary(testMessage.getBoundary());
-        oof.setRootContentId(testMessage.getStart());
-        
-        // Write out the message
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, oof);
-        
-        OMXMLParserWrapper builder =
-            OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.DEFAULT, attachments);
-        OMElement om = builder.getDocumentElement();
-        om.serialize(writer);
-        om.close(false);
-        String outNormal = baos.toString();
-        
-        assertTrue(outNormal.indexOf("base64") == -1);
-        
-        // Now do it again but use base64 content-type-encoding for 
-        // binary attachments
-        baos = new ByteArrayOutputStream();
-        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
-                        Boolean.TRUE);
-        writer = new MTOMXMLStreamWriter(baos, oof);
-        builder = 
-            OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.DEFAULT, attachments);
-        om = builder.getDocumentElement();
-        om.serialize(writer);
-        om.close(false);
-        String outBase64 = baos.toString();
-        
-        
-        // Do a quick check to see if the data is base64 and is
-        // writing base64 compliant code.
-        assertTrue(outBase64.indexOf("base64") != -1);
-        assertTrue(outBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
-        
-        // Now read the data back in
-        InputStream is = new ByteArrayInputStream(outBase64.getBytes());
-        Attachments attachments2 = new Attachments(is, testMessage.getContentType());
-        
-        // Now write it back out with binary...
-        baos = new ByteArrayOutputStream();
-        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
-                        Boolean.FALSE);
-        writer = new MTOMXMLStreamWriter(baos, oof);
-        builder = 
-            OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.DEFAULT, attachments2);
-        om = builder.getDocumentElement();
-        om.serialize(writer);
-        om.close(false);
-        String outBase64ToNormal = baos.toString();
-        
-        assertTrue(outBase64ToNormal.indexOf("base64") == -1);
-        
-        // Now do it again but use base64 content-type-encoding for 
-        // binary attachments
-        is = new ByteArrayInputStream(outBase64.getBytes());
-        attachments2 = new Attachments(is, testMessage.getContentType());
-        baos = new ByteArrayOutputStream();
-        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
-                        Boolean.TRUE);
-        writer = new MTOMXMLStreamWriter(baos, oof);
-        builder = 
-            OMXMLBuilderFactory.createOMBuilder(StAXParserConfiguration.DEFAULT, attachments2);
-        om = builder.getDocumentElement();
-        om.serialize(writer);
-        om.close(false);
-        String outBase64ToBase64 = baos.toString();
-        
-        // Do a quick check to see if the data is base64 and is
-        // writing base64 compliant code.
-        assertTrue(outBase64ToBase64.indexOf("base64") != -1);
-        assertTrue(outBase64ToBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
-    }
-    
     public void testSWAWriteWithIncomingOrder() throws Exception {
 
         // Read the stream that has soap xml followed by BAttachment then AAttachment

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1425602&r1=1425601&r2=1425602&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Mon Dec 24 08:39:57 2012
@@ -478,6 +478,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.text.TestBase64StreamingWithSerialize(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestDigest(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestGetTextCharactersFromDataHandler(metaFactory));
+        addTest(new org.apache.axiom.ts.om.xop.TestSerialize(metaFactory));
         Method[] methods = AXIOMXPathTestCase.class.getMethods();
         for (int i=0; i<methods.length; i++) {
             String methodName = methods[i].getName();

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java?rev=1425602&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java Mon Dec 24 08:39:57 2012
@@ -0,0 +1,129 @@
+/*
+ * 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.om.xop;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.MIMEResource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.TestConstants;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestSerialize extends AxiomTestCase {
+    public TestSerialize(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        MIMEResource testMessage = TestConstants.MTOM_MESSAGE;
+
+        // Read in message: SOAPPart and 2 image attachments
+        InputStream inStream = AbstractTestCase.getTestResource(testMessage.getName());
+        Attachments attachments = new Attachments(inStream, testMessage.getContentType());
+        
+        attachments.getRootPartInputStream();
+
+        String[] contentIDs = attachments.getAllContentIDs();
+        
+        OMOutputFormat oof = new OMOutputFormat();
+        oof.setDoOptimize(true);
+        oof.setMimeBoundary(testMessage.getBoundary());
+        oof.setRootContentId(testMessage.getStart());
+        
+        // Write out the message
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, oof);
+        
+        OMXMLParserWrapper builder =
+            OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, attachments);
+        OMElement om = builder.getDocumentElement();
+        om.serialize(writer);
+        om.close(false);
+        String outNormal = baos.toString();
+        
+        assertTrue(outNormal.indexOf("base64") == -1);
+        
+        // Now do it again but use base64 content-type-encoding for 
+        // binary attachments
+        baos = new ByteArrayOutputStream();
+        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
+                        Boolean.TRUE);
+        writer = new MTOMXMLStreamWriter(baos, oof);
+        builder = 
+            OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, attachments);
+        om = builder.getDocumentElement();
+        om.serialize(writer);
+        om.close(false);
+        String outBase64 = baos.toString();
+        
+        
+        // Do a quick check to see if the data is base64 and is
+        // writing base64 compliant code.
+        assertTrue(outBase64.indexOf("base64") != -1);
+        assertTrue(outBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
+        
+        // Now read the data back in
+        InputStream is = new ByteArrayInputStream(outBase64.getBytes());
+        Attachments attachments2 = new Attachments(is, testMessage.getContentType());
+        
+        // Now write it back out with binary...
+        baos = new ByteArrayOutputStream();
+        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
+                        Boolean.FALSE);
+        writer = new MTOMXMLStreamWriter(baos, oof);
+        builder = 
+            OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, attachments2);
+        om = builder.getDocumentElement();
+        om.serialize(writer);
+        om.close(false);
+        String outBase64ToNormal = baos.toString();
+        
+        assertTrue(outBase64ToNormal.indexOf("base64") == -1);
+        
+        // Now do it again but use base64 content-type-encoding for 
+        // binary attachments
+        is = new ByteArrayInputStream(outBase64.getBytes());
+        attachments2 = new Attachments(is, testMessage.getContentType());
+        baos = new ByteArrayOutputStream();
+        oof.setProperty(OMOutputFormat.USE_CTE_BASE64_FOR_NON_TEXTUAL_ATTACHMENTS, 
+                        Boolean.TRUE);
+        writer = new MTOMXMLStreamWriter(baos, oof);
+        builder = 
+            OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, attachments2);
+        om = builder.getDocumentElement();
+        om.serialize(writer);
+        om.close(false);
+        String outBase64ToBase64 = baos.toString();
+        
+        // Do a quick check to see if the data is base64 and is
+        // writing base64 compliant code.
+        assertTrue(outBase64ToBase64.indexOf("base64") != -1);
+        assertTrue(outBase64ToBase64.indexOf("GBgcGBQgHBwcJCQgKDBQNDAsL") != -1);
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/xop/TestSerialize.java
------------------------------------------------------------------------------
    svn:eol-style = native