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/29 20:06:59 UTC
svn commit: r1426807 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/
Author: veithen
Date: Sat Dec 29 19:06:59 2012
New Revision: 1426807
URL: http://svn.apache.org/viewvc?rev=1426807&view=rev
Log:
AXIOM-311: Refactored the test cases for AXIOM-96.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.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/impl/serializer/OMSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java?rev=1426807&r1=1426806&r2=1426807&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java Sat Dec 29 19:06:59 2012
@@ -20,13 +20,10 @@
package org.apache.axiom.om.impl.serializer;
import org.apache.axiom.om.AbstractTestCase;
-import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.OMConstants;
import org.apache.axiom.om.TestConstants;
-import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.soap.SOAPBody;
@@ -107,158 +104,6 @@ public class OMSerializerTest extends Ab
assertTrue(outputString != null && !"".equals(outputString) && outputString.length() > 1);
}
- /**
- * Scenario:
- * A) Builder reads a soap message.
- * B) The payload of the message is created by a customer builder
- * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
- * D) The payload of the message should not be expanded into OM.
- *
- * Expansion of the message results in both a time and space penalty.
- * @throws Exception
- */
- public void testElementPullStreamAndOMExpansion() throws Exception {
- // Create a builder from a message containing an interesting payload
- StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(
- getTestResource("soap/OMElementTest.xml"), null);
-
- // Create a custom builder to store the sub trees as a byte array instead of a full tree
- ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
-
- // Register the custom builder on the builder so that they body payload is stored as bytes
- builder.registerCustomBuilderForPayload(customBuilder);
-
-
- // Create an output stream
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
-
- // Now use StreamingOMSerializer to write the input stream to the output stream
- SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
- SOAPBody body = env.getBody();
- OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
-
- StreamingOMSerializer serializer = new StreamingOMSerializer();
- serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
- writer);
- writer.flush();
-
- String outputString = new String(byteArrayOutputStream.toByteArray());
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString != null && !"".equals(outputString) && outputString.length() > 1);
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString.contains("axis2:input"));
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString.contains("This is some text"));
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString.contains("Some Other Text"));
-
- assertTrue("Expectation is that an OMSourcedElement was created for the payload",
- omse != null);
- assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
- !omse.isExpanded());
- }
-
- /**
- * Scenario:
- * A) Builder reads a soap message.
- * B) The payload of the message is created by a customer builder
- * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
- * D) The payload of the message should not be expanded into OM.
- *
- * Expansion of the message results in both a time and space penalty.
- * @throws Exception
- */
- public void testElementPullStreamAndOMExpansion2() throws Exception {
- // Create a builder from a message containing an interesting payload
- StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(
- getTestResource("soap/soapmessageWithXSI.xml"), null);
-
- // Create a custom builder to store the sub trees as a byte array instead of a full tree
- ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
-
- // Register the custom builder on the builder so that they body payload is stored as bytes
- builder.registerCustomBuilderForPayload(customBuilder);
-
-
- // Create an output stream
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
-
- // Now use StreamingOMSerializer to write the input stream to the output stream
- SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
- SOAPBody body = env.getBody();
- OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
-
- StreamingOMSerializer serializer = new StreamingOMSerializer();
- serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
- writer);
- writer.flush();
-
- String outputString = new String(byteArrayOutputStream.toByteArray());
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString != null && !"".equals(outputString) && outputString.length() > 1);
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString.contains("Hello World"));
-
- assertTrue("Expectation is that an OMSourcedElement was created for the payload",
- omse != null);
- assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
- !omse.isExpanded());
- }
-
- /**
- * Scenario:
- * A) Builder reads a soap message.
- * B) The payload of the message is created by a customer builder
- * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
- * D) The payload of the message should not be expanded into OM.
- *
- * Expansion of the message results in both a time and space penalty.
- * @throws Exception
- */
- public void testElementPullStreamAndOMExpansion3() throws Exception {
- // Create a builder from a message containing an interesting payload
- StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(
- getTestResource("soap/noprettyprint.xml"), null);
-
- // Create a custom builder to store the sub trees as a byte array instead of a full tree
- ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
-
- // Register the custom builder on the builder so that they body payload is stored as bytes
- builder.registerCustomBuilderForPayload(customBuilder);
-
-
- // Create an output stream
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
-
- // Now use StreamingOMSerializer to write the input stream to the output stream
- SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
- SOAPBody body = env.getBody();
- OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
-
- StreamingOMSerializer serializer = new StreamingOMSerializer();
- serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
- writer);
- writer.flush();
-
- String outputString = new String(byteArrayOutputStream.toByteArray());
- assertTrue("Expected output was incorrect. Received:" + outputString,
- outputString != null && !"".equals(outputString) && outputString.length() > 1);
- int indexHelloWorld = outputString.indexOf("Hello World");
- assertTrue("Expected output was incorrect. Received:" + outputString,
- indexHelloWorld > 0);
- int indexHelloWorld2 = outputString.indexOf("Hello World", indexHelloWorld+1);
- assertTrue("Expected output was incorrect. Received:" + outputString,
- indexHelloWorld2 < 0);
-
- assertTrue("Expectation is that an OMSourcedElement was created for the payload",
- omse != null);
- assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
- !omse.isExpanded());
- }
-
public void testXSITypePullStream() throws Exception {
// Read the SOAP Message that defines prefix "usr" on the envelope and only uses it within an xsi:type
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=1426807&r1=1426806&r2=1426807&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 Sat Dec 29 19:06:59 2012
@@ -383,6 +383,11 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.factory.TestFactoryIsSingleton(metaFactory));
addTest(new org.apache.axiom.ts.om.factory.TestGetMetaFactory(metaFactory));
addTest(new org.apache.axiom.ts.om.misc.TestAxiom95(metaFactory));
+ if (supportsOMSourcedElement) {
+ addTest(new org.apache.axiom.ts.om.misc.TestElementPullStreamAndOMExpansion(metaFactory));
+ addTest(new org.apache.axiom.ts.om.misc.TestElementPullStreamAndOMExpansion2(metaFactory));
+ addTest(new org.apache.axiom.ts.om.misc.TestElementPullStreamAndOMExpansion3(metaFactory));
+ }
addTest(new org.apache.axiom.ts.om.namespace.TestEquals(metaFactory));
addTest(new org.apache.axiom.ts.om.namespace.TestEqualsWithNullPrefix(metaFactory));
addTest(new org.apache.axiom.ts.om.namespace.TestGetNamespaceURI(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java?rev=1426807&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java Sat Dec 29 19:06:59 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.misc;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Scenario:
+ * A) Builder reads a soap message.
+ * B) The payload of the message is created by a customer builder
+ * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
+ * D) The payload of the message should not be expanded into OM.
+ *
+ * Expansion of the message results in both a time and space penalty.
+ */
+public class TestElementPullStreamAndOMExpansion extends AxiomTestCase {
+ public TestElementPullStreamAndOMExpansion(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // Create a builder from a message containing an interesting payload
+ StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory,
+ AbstractTestCase.getTestResource("soap/OMElementTest.xml"), null);
+
+ // Create a custom builder to store the sub trees as a byte array instead of a full tree
+ ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
+
+ // Register the custom builder on the builder so that they body payload is stored as bytes
+ builder.registerCustomBuilderForPayload(customBuilder);
+
+
+ // Create an output stream
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
+
+ // Now use StreamingOMSerializer to write the input stream to the output stream
+ SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
+ SOAPBody body = env.getBody();
+ OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
+
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
+ writer);
+ writer.flush();
+
+ String outputString = new String(byteArrayOutputStream.toByteArray());
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString != null && !"".equals(outputString) && outputString.length() > 1);
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString.contains("axis2:input"));
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString.contains("This is some text"));
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString.contains("Some Other Text"));
+
+ assertTrue("Expectation is that an OMSourcedElement was created for the payload",
+ omse != null);
+ assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
+ !omse.isExpanded());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java?rev=1426807&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java Sat Dec 29 19:06:59 2012
@@ -0,0 +1,88 @@
+/*
+ * 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.misc;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Scenario:
+ * A) Builder reads a soap message.
+ * B) The payload of the message is created by a customer builder
+ * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
+ * D) The payload of the message should not be expanded into OM.
+ *
+ * Expansion of the message results in both a time and space penalty.
+ */
+public class TestElementPullStreamAndOMExpansion2 extends AxiomTestCase {
+ public TestElementPullStreamAndOMExpansion2(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // Create a builder from a message containing an interesting payload
+ StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory,
+ AbstractTestCase.getTestResource("soap/soapmessageWithXSI.xml"), null);
+
+ // Create a custom builder to store the sub trees as a byte array instead of a full tree
+ ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
+
+ // Register the custom builder on the builder so that they body payload is stored as bytes
+ builder.registerCustomBuilderForPayload(customBuilder);
+
+
+ // Create an output stream
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
+
+ // Now use StreamingOMSerializer to write the input stream to the output stream
+ SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
+ SOAPBody body = env.getBody();
+ OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
+
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
+ writer);
+ writer.flush();
+
+ String outputString = new String(byteArrayOutputStream.toByteArray());
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString != null && !"".equals(outputString) && outputString.length() > 1);
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString.contains("Hello World"));
+
+ assertTrue("Expectation is that an OMSourcedElement was created for the payload",
+ omse != null);
+ assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
+ !omse.isExpanded());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java?rev=1426807&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java Sat Dec 29 19:06:59 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.misc;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMSourcedElement;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.ds.custombuilder.ByteArrayCustomBuilder;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Scenario:
+ * A) Builder reads a soap message.
+ * B) The payload of the message is created by a customer builder
+ * C) The resulting OM is serialized (pulled) prior to completion of the intial read.
+ * D) The payload of the message should not be expanded into OM.
+ *
+ * Expansion of the message results in both a time and space penalty.
+ */
+public class TestElementPullStreamAndOMExpansion3 extends AxiomTestCase {
+ public TestElementPullStreamAndOMExpansion3(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ // Create a builder from a message containing an interesting payload
+ StAXBuilder builder = (StAXBuilder)OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory,
+ AbstractTestCase.getTestResource("soap/noprettyprint.xml"), null);
+
+ // Create a custom builder to store the sub trees as a byte array instead of a full tree
+ ByteArrayCustomBuilder customBuilder = new ByteArrayCustomBuilder("utf-8");
+
+ // Register the custom builder on the builder so that they body payload is stored as bytes
+ builder.registerCustomBuilderForPayload(customBuilder);
+
+
+ // Create an output stream
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(byteArrayOutputStream);
+
+ // Now use StreamingOMSerializer to write the input stream to the output stream
+ SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
+ SOAPBody body = env.getBody();
+ OMSourcedElement omse = (OMSourcedElement) body.getFirstElement();
+
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(env.getXMLStreamReaderWithoutCaching(),
+ writer);
+ writer.flush();
+
+ String outputString = new String(byteArrayOutputStream.toByteArray());
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ outputString != null && !"".equals(outputString) && outputString.length() > 1);
+ int indexHelloWorld = outputString.indexOf("Hello World");
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ indexHelloWorld > 0);
+ int indexHelloWorld2 = outputString.indexOf("Hello World", indexHelloWorld+1);
+ assertTrue("Expected output was incorrect. Received:" + outputString,
+ indexHelloWorld2 < 0);
+
+ assertTrue("Expectation is that an OMSourcedElement was created for the payload",
+ omse != null);
+ assertTrue("Expectation is that the OMSourcedElement was not expanded by serialization ",
+ !omse.isExpanded());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/misc/TestElementPullStreamAndOMExpansion3.java
------------------------------------------------------------------------------
svn:eol-style = native