You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ve...@apache.org on 2009/10/08 13:37:29 UTC

svn commit: r823134 - in /webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema: AbstractTestCase.java base64binary/Base64BinaryTest.java

Author: veithen
Date: Thu Oct  8 11:37:29 2009
New Revision: 823134

URL: http://svn.apache.org/viewvc?rev=823134&view=rev
Log:
Extended the ADB test suite to cover the following cases:
- MTOM messages that use unoptimized base64.
- DataHandler objects with zero length.

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java?rev=823134&r1=823133&r2=823134&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/AbstractTestCase.java Thu Oct  8 11:37:29 2009
@@ -27,6 +27,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.reflect.Array;
@@ -47,9 +48,12 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.mime.MultipartWriter;
+import org.apache.axiom.mime.impl.javamail.JavaMailMultipartWriterFactory;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.OMMultipartWriter;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAPEnvelope;
@@ -302,6 +306,7 @@
         testSerializeDeserializeWrapped(bean, expectedResult);
         testSerializeDeserializeUsingMTOM(bean, expectedResult, true);
         testSerializeDeserializeUsingMTOM(bean, expectedResult, false);
+        testSerializeDeserializeUsingMTOMWithoutOptimize(bean, expectedResult);
         testSerializeDeserializePrettified(bean, expectedResult);
         
         try {
@@ -319,6 +324,7 @@
         testSerializeDeserializeWrapped(helperModeBean, helperModeExpectedResult);
         testSerializeDeserializeUsingMTOM(helperModeBean, helperModeExpectedResult, true);
         testSerializeDeserializeUsingMTOM(helperModeBean, helperModeExpectedResult, false);
+        testSerializeDeserializeUsingMTOMWithoutOptimize(helperModeBean, helperModeExpectedResult);
         testSerializeDeserializePrettified(helperModeBean, helperModeExpectedResult);
     }
     
@@ -378,6 +384,26 @@
         assertBeanEquals(expectedResult, ADBBeanUtil.parse(bean.getClass(), cache ? bodyElement.getXMLStreamReader() : bodyElement.getXMLStreamReaderWithoutCaching()));
     }
     
+    // This is a bit special: it serializes the message using MTOM, but without using any xop:Include. This checks
+    // that MTOM decoding works properly even if the client uses unoptimized base64.
+    private static void testSerializeDeserializeUsingMTOMWithoutOptimize(Object bean, Object expectedResult) throws Exception {
+        SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+        envelope.getBody().addChild(ADBBeanUtil.getOMElement(bean));
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        OMOutputFormat format = new OMOutputFormat();
+        MultipartWriter mpWriter = JavaMailMultipartWriterFactory.INSTANCE.createMultipartWriter(buffer, format.getMimeBoundary());
+        OutputStream rootPartWriter = mpWriter.writePart("application/xop+xml; charset=UTF-8; type=\"text/xml\"", "binary", format.getRootContentId());
+        envelope.serialize(rootPartWriter, format);
+        rootPartWriter.close();
+        mpWriter.complete();
+        System.out.write(buffer.toByteArray());
+        String contentType = format.getContentTypeForMTOM("text/xml");
+        Attachments attachments = new Attachments(new ByteArrayInputStream(buffer.toByteArray()), contentType);
+        MTOMStAXSOAPModelBuilder builder = new MTOMStAXSOAPModelBuilder(StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()), attachments);
+        OMElement bodyElement = builder.getSOAPEnvelope().getBody().getFirstElement();
+        assertBeanEquals(expectedResult, ADBBeanUtil.parse(bean.getClass(), bodyElement.getXMLStreamReaderWithoutCaching()));
+    }
+    
     // This is used to check that ADB correctly handles element whitespace
     private static void testSerializeDeserializePrettified(Object bean, Object expectedResult) throws Exception {
         OMElement omElement = ADBBeanUtil.getOMElement(bean);

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java?rev=823134&r1=823133&r2=823134&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/base64binary/Base64BinaryTest.java Thu Oct  8 11:37:29 2009
@@ -27,14 +27,11 @@
 
 public class Base64BinaryTest extends AbstractTestCase {
 
-    public void testBase64Binary() throws Exception {
+    private void testBase64Binary(DataHandler dataHandler) throws Exception {
         TestBase64Binary testBase64Binary = new TestBase64Binary();
         Base64Binary base64Binary = new Base64Binary();
         testBase64Binary.setTestBase64Binary(base64Binary);
 
-        String testString = "new test string";
-
-        DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(testString.getBytes()));
         base64Binary.setBase64Binary(dataHandler);
         ContentType_type0 contentType_type0 = new ContentType_type0();
         contentType_type0.setContentType_type0("test content type");
@@ -43,6 +40,14 @@
         testSerializeDeserialize(testBase64Binary, false);
     }
 
+    public void testBase64Binary() throws Exception {
+        testBase64Binary(new DataHandler(new ByteArrayDataSource("new test string".getBytes())));
+    }
+
+    public void testBase64BinaryEmpty() throws Exception {
+        testBase64Binary(new DataHandler(new ByteArrayDataSource(new byte[0])));
+    }
+
     public void testHexBinary() throws Exception {
         TestHexBinary testHexBinary = new TestHexBinary();
         org.w3.www._2005._05.xmlmime.HexBinary hexBinary = new org.w3.www._2005._05.xmlmime.HexBinary();