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/04/22 12:50:12 UTC
svn commit: r1328840 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-tests/src/test/java/org/apache/axiom/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/
Author: veithen
Date: Sun Apr 22 10:50:12 2012
New Revision: 1328840
URL: http://svn.apache.org/viewvc?rev=1328840&view=rev
Log:
AXIOM-311: Refactored another test case.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.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/om/OMSourcedElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java?rev=1328840&r1=1328839&r2=1328840&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMSourcedElementTest.java Sun Apr 22 10:50:12 2012
@@ -38,25 +38,20 @@ import java.io.ByteArrayOutputStream;
* the OMDataSourceExt interface, InputStreamDataSource and ByteArrayDataSource.
*/
public class OMSourcedElementTest extends AbstractTestCase implements OMConstants {
- protected OMFactory ombuilderFactory;
- protected SOAPFactory soapFactory;
- protected SOAPEnvelope soapEnvelope;
- ByteArrayDataSource bads1;
- ByteArrayDataSource bads2;
- InputStreamDataSource isds1;
- InputStreamDataSource isds2;
- CharArrayDataSource cads;
- String localName = "myPayload";
- OMNamespace ns;
+ private SOAPFactory soapFactory;
+ private SOAPEnvelope soapEnvelope;
+ private ByteArrayDataSource bads1;
+ private InputStreamDataSource isds1;
+ private CharArrayDataSource cads;
+ private String localName = "myPayload";
+ private OMNamespace ns;
private final String ENCODING = "utf-8";
- String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
- String payload2 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload Two</tns:myPayload>";
+ private String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
public OMSourcedElementTest(String testName) {
super(testName);
- ombuilderFactory = OMAbstractFactory.getOMFactory();
soapFactory = OMAbstractFactory.getSOAP11Factory();
}
@@ -66,15 +61,12 @@ public class OMSourcedElementTest extend
protected void setUp() throws Exception {
super.setUp();
soapEnvelope = soapFactory.createSOAPEnvelope();
- SOAPBody soapBody = soapFactory.createSOAPBody(soapEnvelope);
- SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
+ soapFactory.createSOAPBody(soapEnvelope);
+ soapFactory.createSOAPHeader(soapEnvelope);
bads1 = new ByteArrayDataSource(payload1.getBytes(ENCODING), ENCODING);
- bads2 = new ByteArrayDataSource(payload2.getBytes(ENCODING), ENCODING);
ByteArrayInputStream bais1 = new ByteArrayInputStream(payload1.getBytes(ENCODING));
- ByteArrayInputStream bais2 = new ByteArrayInputStream(payload2.getBytes(ENCODING));
isds1 = new InputStreamDataSource(bais1, ENCODING);
- isds2 = new InputStreamDataSource(bais2, ENCODING);
cads = new CharArrayDataSource(payload1.toCharArray());
ns = soapFactory.createOMNamespace("urn://test", "tns");
}
@@ -314,64 +306,4 @@ public class OMSourcedElementTest extend
payload1.equals(payload));
}
-
- /**
- * Verifies that a OMDataSource can be replaced with another one
- * @throws Exception
- */
- public void testOMSEReplacement() throws Exception {
- SOAPBody soapBody = soapEnvelope.getBody();
- OMFactory factory = soapBody.getOMFactory();
- OMSourcedElement omse = factory.createOMElement(bads1, localName, ns);
- soapBody.addChild(omse);
- OMNode firstChild = soapBody.getFirstOMChild();
- assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
- OMSourcedElement child = (OMSourcedElement) firstChild;
- assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
- assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
- child.getDataSource() instanceof ByteArrayDataSource);
-
- // Write out the body
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- soapBody.serialize(baos);
- String output = baos.toString(ENCODING);
-// System.out.println(output);
- assertTrue("The payload was not present in the output",
- output.indexOf(payload1) > 0);
- assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
-
- // Replace with payload2.
- // Important note, it is legal to replace the OMDataSource, but
- // the namespace and local name of the OMSourcedElement cannot be changed.
- child.setDataSource(bads2);
-
- // Write out the body
- baos = new ByteArrayOutputStream();
- soapBody.serialize(baos);
- output = baos.toString(ENCODING);
-// System.out.println(output);
- assertTrue("The payload was not present in the output",
- output.indexOf(payload2) > 0);
- assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
-
- // Now Replace with payload1 from an InputStreamDataSource
- child.setDataSource(isds1);
- baos = new ByteArrayOutputStream();
- soapBody.serialize(baos);
- output = baos.toString(ENCODING);
-// System.out.println(output);
- assertTrue("The payload was not present in the output",
- output.indexOf(payload1) > 0);
-
- // Now Replace with payload2 from an InputStreamDataSource.
- // Note at this point, the child's tree is expanded.
- child.setDataSource(isds2);
- baos = new ByteArrayOutputStream();
- soapBody.serialize(baos);
- output = baos.toString(ENCODING);
-// System.out.println(output);
- assertTrue("The payload was not present in the output",
- output.indexOf(payload2) > 0);
-
- }
}
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=1328840&r1=1328839&r2=1328840&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 Sun Apr 22 10:50:12 2012
@@ -350,6 +350,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterEmbedded(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterFromReader(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestSerializeToXMLWriterFromReaderEmbedded(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestSetDataSource(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestSetDataSourceOnAlreadyExpandedElement(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java?rev=1328840&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java Sun Apr 22 10:50:12 2012
@@ -0,0 +1,108 @@
+/*
+ * 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.sourcedelement;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.ds.ByteArrayDataSource;
+import org.apache.axiom.om.ds.InputStreamDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Verifies that a OMDataSource can be replaced with another one
+ */
+public class TestSetDataSource extends AxiomTestCase {
+ public TestSetDataSource(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void testOMSEReplacement() throws Exception {
+ String ENCODING = "utf-8";
+ String payload1 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
+ String payload2 = "<tns:myPayload xmlns:tns=\"urn://test\">Payload Two</tns:myPayload>";
+ ByteArrayDataSource bads1 = new ByteArrayDataSource(payload1.getBytes(ENCODING), ENCODING);
+ ByteArrayDataSource bads2 = new ByteArrayDataSource(payload2.getBytes(ENCODING), ENCODING);
+ InputStreamDataSource isds1 = new InputStreamDataSource(new ByteArrayInputStream(payload1.getBytes(ENCODING)), ENCODING);
+ InputStreamDataSource isds2 = new InputStreamDataSource(new ByteArrayInputStream(payload2.getBytes(ENCODING)), ENCODING);
+
+ OMFactory factory = metaFactory.getOMFactory();
+ OMElement parent = factory.createOMElement("parent", null);
+ OMSourcedElement omse = factory.createOMElement(bads1, "myPayload", factory.createOMNamespace("urn://test", "tns"));
+ parent.addChild(omse);
+ OMNode firstChild = parent.getFirstOMChild();
+ assertTrue("Expected OMSourcedElement child", firstChild instanceof OMSourcedElement);
+ OMSourcedElement child = (OMSourcedElement) firstChild;
+ assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
+ assertTrue("OMSourcedElement should be backed by a ByteArrayDataSource",
+ child.getDataSource() instanceof ByteArrayDataSource);
+
+ // Write out the body
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ parent.serialize(baos);
+ String output = baos.toString(ENCODING);
+// System.out.println(output);
+ assertTrue("The payload was not present in the output",
+ output.indexOf(payload1) > 0);
+ assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
+
+ // Replace with payload2.
+ // Important note, it is legal to replace the OMDataSource, but
+ // the namespace and local name of the OMSourcedElement cannot be changed.
+ child.setDataSource(bads2);
+
+ // Write out the body
+ baos = new ByteArrayOutputStream();
+ parent.serialize(baos);
+ output = baos.toString(ENCODING);
+// System.out.println(output);
+ assertTrue("The payload was not present in the output",
+ output.indexOf(payload2) > 0);
+ assertTrue("OMSourcedElement is expanded. This is unexpected", !child.isExpanded());
+
+ // Now Replace with payload1 from an InputStreamDataSource
+ child.setDataSource(isds1);
+ baos = new ByteArrayOutputStream();
+ parent.serialize(baos);
+ output = baos.toString(ENCODING);
+// System.out.println(output);
+ assertTrue("The payload was not present in the output",
+ output.indexOf(payload1) > 0);
+
+ // Now Replace with payload2 from an InputStreamDataSource.
+ // Note at this point, the child's tree is expanded.
+ child.setDataSource(isds2);
+ baos = new ByteArrayOutputStream();
+ parent.serialize(baos);
+ output = baos.toString(ENCODING);
+// System.out.println(output);
+ assertTrue("The payload was not present in the output",
+ output.indexOf(payload2) > 0);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestSetDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native