You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/05/13 16:13:22 UTC

svn commit: r1795076 - in /axis/axis2/java/core/trunk/modules: integration/test/org/apache/axis2/engine/ json/ json/test/org/apache/axis2/json/ transport/tcp/test/org/apache/axis2/transport/tcp/

Author: veithen
Date: Sat May 13 16:13:21 2017
New Revision: 1795076

URL: http://svn.apache.org/viewvc?rev=1795076&view=rev
Log:
Eliminate unnecessary usages of StAXUtils.createXMLStreamWriter.

Modified:
    axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java
    axis/axis2/java/core/trunk/modules/json/pom.xml
    axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
    axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java
    axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java

Modified: axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java?rev=1795076&r1=1795075&r2=1795076&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java (original)
+++ axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/HandlerFailureTest.java Sat May 13 16:13:21 2017
@@ -20,7 +20,6 @@
 package org.apache.axis2.engine;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.context.MessageContext;
@@ -69,7 +68,7 @@ public class HandlerFailureTest extends
             ServiceClient sender = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
             
             OMElement result = sender.sendReceive(TestingUtils.createDummyOMElement());
-            result.serializeAndConsume(StAXUtils.createXMLStreamWriter(System.out));
+            result.serializeAndConsume(System.out);
             fail("the test must fail due to the intentional failure of the \"culprit\" handler");
         } catch (AxisFault e) {
             log.info(e.getMessage());

Modified: axis/axis2/java/core/trunk/modules/json/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/pom.xml?rev=1795076&r1=1795075&r2=1795076&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/json/pom.xml Sat May 13 16:13:21 2017
@@ -85,6 +85,11 @@
             <artifactId>commons-httpclient</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.ws.commons.axiom</groupId>
+            <artifactId>axiom-truth</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <url>http://axis.apache.org/axis2/java/core/</url>
     <scm>

Modified: axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java?rev=1795076&r1=1795075&r2=1795076&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java (original)
+++ axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java Sat May 13 16:13:21 2017
@@ -19,102 +19,43 @@
 
 package org.apache.axis2.json;
 
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
-import org.codehaus.jettison.json.JSONException;
 import org.custommonkey.xmlunit.XMLTestCase;
-import org.xml.sax.SAXException;
 
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
+import static com.google.common.truth.Truth.assertAbout;
+import static org.apache.axiom.truth.xml.XMLTruth.xml;
+
 import java.io.StringReader;
 
 public class JSONDataSourceTest extends XMLTestCase {
 
-    public void testMappedSerialize1() throws Exception {
-        String jsonString = getMappedJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        JSONDataSource source = getMappedDataSource(jsonString);
-        source.serialize(outStream, new OMOutputFormat());
-        assertXMLEqual("<mapping><inner><first>test string one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
-                outStream.toString("utf-8"));
-    }
-
-    public void testMappedSerialize2() throws Exception {
-        String jsonString = getMappedJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        OutputStreamWriter writer = new OutputStreamWriter(outStream);
-        JSONDataSource source = getMappedDataSource(jsonString);
-        source.serialize(writer, new OMOutputFormat());
-        writer.flush();
-        assertXMLEqual("<mapping><inner><first>test string one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
-                outStream.toString("utf-8"));
-    }
-
-    public void testMappedSerialize3() throws Exception {
-        String jsonString = getMappedJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(outStream);
-        JSONDataSource source = getMappedDataSource(jsonString);
-        source.serialize(writer);
-        writer.flush();
-        assertXMLEqual("<mapping><inner><first>test string one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
-                outStream.toString("utf-8"));
-    }
-
-    public void testBadgerfishSerialize1() throws Exception {
-        String jsonString = getBadgerfishJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
-        source.serialize(outStream, new OMOutputFormat());
-        assertXMLEqual("<p xmlns=\"http://def.ns\" xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam att=\"lets\">555</sam></p>",
-                outStream.toString("utf-8"));
-    }
-
-    public void testBadgerfishSerialize2() throws Exception {
-        String jsonString = getBadgerfishJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        OutputStreamWriter writer = new OutputStreamWriter(outStream);
-        JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
-        source.serialize(writer, new OMOutputFormat());
-        writer.flush();
-        assertXMLEqual("<p xmlns=\"http://def.ns\" xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam att=\"lets\">555</sam></p>",
-                outStream.toString("utf-8"));
-    }
-
-    public void testBadgerfishSerialize3() throws XMLStreamException, JSONException, IOException,
-            ParserConfigurationException, SAXException {
-        String jsonString = getBadgerfishJSONString();
-        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(outStream);
-        JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
-        source.serialize(writer);
-        writer.flush();
-        assertXMLEqual("<p xmlns=\"http://def.ns\" xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam att=\"lets\">555</sam></p>",
-                outStream.toString("utf-8"));
+    public void testMappedSerialize() throws Exception {
+        JSONDataSource source = getMappedDataSource(
+                "{\"mapping\":{\"inner\":[{\"first\":\"test string one\"},\"test string two\"],\"name\":\"foo\"}}");
+        assertAbout(xml())
+                .that(OMAbstractFactory.getOMFactory().createOMElement(source))
+                .hasSameContentAs(
+                        "<mapping><inner><first>test string one</first></inner><inner>test string two</inner><name>foo</name></mapping>");
+    }
+
+    public void testBadgerfishSerialize() throws Exception {
+        JSONBadgerfishDataSource source = getBadgerfishDataSource(
+                "{\"p\":{\"@xmlns\":{\"bb\":\"http://other.nsb\",\"aa\":\"http://other.ns\",\"$\":\"http://def.ns\"},\"sam\":{\"$\":\"555\", \"@att\":\"lets\"}}}");
+        assertAbout(xml())
+                .that(OMAbstractFactory.getOMFactory().createOMElement(source))
+                .hasSameContentAs(
+                        "<p xmlns=\"http://def.ns\" xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam att=\"lets\">555</sam></p>");
     }
 
     private JSONBadgerfishDataSource getBadgerfishDataSource(String jsonString) {
         return new JSONBadgerfishDataSource(new StringReader(jsonString));
     }
 
-    private String getBadgerfishJSONString() {
-        return "{\"p\":{\"@xmlns\":{\"bb\":\"http://other.nsb\",\"aa\":\"http://other.ns\",\"$\":\"http://def.ns\"},\"sam\":{\"$\":\"555\", \"@att\":\"lets\"}}}";
-    }
-
     private JSONDataSource getMappedDataSource(String jsonString) {
         MessageContext messageContext = new MessageContext();
         messageContext.setAxisService(new AxisService());
         return new JSONDataSource(new StringReader(jsonString), messageContext);
     }
-
-    private String getMappedJSONString() {
-        return "{\"mapping\":{\"inner\":[{\"first\":\"test string one\"},\"test string two\"],\"name\":\"foo\"}}";
-    }
 }

Modified: axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java?rev=1795076&r1=1795075&r2=1795076&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPEchoRawXMLTest.java Sat May 13 16:13:21 2017
@@ -25,7 +25,6 @@ import org.apache.axiom.om.OMAbstractFac
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axis2.AxisFault;
@@ -115,8 +114,7 @@ public class TCPEchoRawXMLTest extends T
         AxisCallback callback = new AxisCallback() {
             public void onComplete(MessageContext msgCtx) {
                 try {
-                    msgCtx.getEnvelope().serialize(StAXUtils
-                            .createXMLStreamWriter(System.out));
+                    msgCtx.getEnvelope().serialize(System.out);
                 } catch (XMLStreamException e) {
                     onError(e);
                 } finally {
@@ -171,8 +169,7 @@ public class TCPEchoRawXMLTest extends T
         sender.setOptions(options);
         OMElement result = sender.sendReceive(operationName, payload);
 
-        result.serialize(StAXUtils.createXMLStreamWriter(
-                System.out));
+        result.serialize(System.out);
         sender.cleanup();
     }
 
@@ -195,8 +192,7 @@ public class TCPEchoRawXMLTest extends T
         sender.setOptions(options);
         OMElement result = sender.sendReceive(operationName, payloadElement);
 
-        result.serialize(StAXUtils.createXMLStreamWriter(
-                System.out));
+        result.serialize(System.out);
         sender.cleanup();
 
     }
@@ -235,8 +231,7 @@ public class TCPEchoRawXMLTest extends T
         MessageContext response = opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
         SOAPEnvelope env = response.getEnvelope();
         assertNotNull(env);
-        env.getBody().serialize(StAXUtils.createXMLStreamWriter(
-                System.out));
+        env.getBody().serialize(System.out);
         sender.cleanup();
     }
 

Modified: axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java?rev=1795076&r1=1795075&r2=1795076&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/tcp/test/org/apache/axis2/transport/tcp/TCPTwoChannelEchoRawXMLTest.java Sat May 13 16:13:21 2017
@@ -25,7 +25,6 @@ import org.apache.axiom.om.OMAbstractFac
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.EndpointReference;
@@ -102,8 +101,7 @@ public class TCPTwoChannelEchoRawXMLTest
             AxisCallback callback = new AxisCallback() {
                 public void onComplete(MessageContext msgCtx) {
                     try {
-                        msgCtx.getEnvelope().serializeAndConsume(StAXUtils
-                                .createXMLStreamWriter(System.out));
+                        msgCtx.getEnvelope().serializeAndConsume(System.out);
                     } catch (XMLStreamException e) {
                         onError(e);
                     } finally {