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/27 12:07:45 UTC
svn commit: r1426162 - 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/element/
axiom-testsui...
Author: veithen
Date: Thu Dec 27 11:07:44 2012
New Revision: 1426162
URL: http://svn.apache.org/viewvc?rev=1426162&view=rev
Log:
AXIOM-311: Refactored StaxParserTest.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml (with props)
Removed:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/StaxParserTest.java
Modified:
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-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=1426162&r1=1426161&r2=1426162&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 Thu Dec 27 11:07:44 2012
@@ -210,6 +210,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestGetAttributeWithXmlPrefix2(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildElements(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildElementsConcurrentModification(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestGetChildElementsConsumed(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildren(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildrenConcurrentModification(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetChildrenRemove1(metaFactory));
@@ -278,6 +279,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderNextTag(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderOnNonRootElement(metaFactory, true));
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderOnNonRootElement(metaFactory, false));
+ addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithCaching(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithNamespaceURIInterning(metaFactory));
if (supportsOMSourcedElement) {
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant(metaFactory));
@@ -313,6 +315,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestSerialization(metaFactory, "U", "D",
"<person><name xmlns=\"urn:ns\">John</name><age xmlns=\"urn:ns\">34</age><weight xmlns=\"urn:ns\">50</weight></person>"));
addTest(new org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestSerializeAndConsumeConsumed(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSerializeAndConsumePartiallyBuilt(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestSetNamespace(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java?rev=1426162&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java Thu Dec 27 11:07:44 2012
@@ -0,0 +1,70 @@
+/*
+ * 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.element;
+
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that an attempt to iterate over the child elements using
+ * {@link OMElement#getChildElements()} results in the expected exception if the part of the
+ * document has already been consumed by {@link OMContainer#getXMLStreamReaderWithoutCaching()}.
+ */
+public class TestGetChildElementsConsumed extends AxiomTestCase {
+ public TestGetChildElementsConsumed(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
+ metaFactory.getOMFactory(),
+ TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
+
+ OMElement documentElement = builder.getDocumentElement();
+ XMLStreamReader reader = documentElement.getXMLStreamReaderWithoutCaching();
+
+ //consume the parser. this should force the xml stream to be exhausted without
+ //building the tree
+ while (reader.hasNext()) {
+ reader.next();
+ }
+
+ //try to find the children of the document element. This should produce an
+ //error since the underlying stream is fully consumed without building the object tree
+ try {
+ Iterator childElements = documentElement.getChildElements();
+ while (childElements.hasNext()) {
+ childElements.next();
+ }
+ fail("The stream should've been consumed by now!");
+ } catch (Exception e) {
+ //if we are here without failing, then we are successful
+ }
+
+ documentElement.close(false);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetChildElementsConsumed.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java?rev=1426162&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java Thu Dec 27 11:07:44 2012
@@ -0,0 +1,72 @@
+/*
+ * 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.element;
+
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the object model can still be accessed after using
+ * {@link OMContainer#getXMLStreamReader()}.
+ */
+public class TestGetXMLStreamReaderWithCaching extends AxiomTestCase {
+ public TestGetXMLStreamReaderWithCaching(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
+ metaFactory.getOMFactory(),
+ TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
+
+ OMElement documentElement = builder.getDocumentElement();
+ XMLStreamReader reader = documentElement.getXMLStreamReader();
+
+ //consume the parser. this should force the xml stream to be exhausted but the
+ //tree to be fully built
+ while (reader.hasNext()) {
+ reader.next();
+ }
+
+ //try to find the children of the document element. This should *NOT* produce an
+ //error even when the underlying stream is fully consumed , the object tree is already complete
+ Iterator childElements = documentElement.getChildElements();
+ int count = 0;
+ try {
+ while (childElements.hasNext()) {
+ childElements.next();
+ count++;
+ }
+ } catch (Exception e) {
+ fail("The object tree needs to be built and traversing the children is to be a success!");
+ }
+
+ assertEquals("Number of elements need to be 2", count, 2);
+
+ documentElement.close(false);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithCaching.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java?rev=1426162&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java Thu Dec 27 11:07:44 2012
@@ -0,0 +1,72 @@
+/*
+ * 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.element;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMContainer#serializeAndConsume(XMLStreamWriter)} throws an appropriate
+ * exception if the part of the tree has already been consumed using
+ * {@link OMContainer#getXMLStreamReaderWithoutCaching()}.
+ */
+public class TestSerializeAndConsumeConsumed extends AxiomTestCase {
+ public TestSerializeAndConsumeConsumed(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
+ metaFactory.getOMFactory(),
+ TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
+
+ OMElement documentElement = builder.getDocumentElement();
+
+ XMLStreamReader reader = documentElement.getXMLStreamReaderWithoutCaching();
+
+ //consume the parser. this should force the xml stream to be exhausted without
+ //building the tree
+ while (reader.hasNext()) {
+ reader.next();
+ }
+
+ //try to find the children of the document element. This should produce an
+ //error since the underlying stream is fully consumed without building the object tree
+ try {
+ XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(System.out);
+ documentElement.serializeAndConsume(writer);
+ fail("Stream should be consumed by now");
+ } catch (XMLStreamException e) {
+ //wea re cool
+ } catch (Exception e) {
+ fail("This should throw an XMLStreamException");
+ }
+
+ documentElement.close(false);
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSerializeAndConsumeConsumed.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml?rev=1426162&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml Thu Dec 27 11:07:44 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<purchase-order xmlns="http://openuri.org/easypo">
+<customer>
+ <name>Gladys Kravitz</name>
+ <address>Anytown, PA</address>
+ </customer>
+ <date>2005-03-06T14:06:12.697+06:00</date>
+</purchase-order>
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/resources/org/apache/axiom/ts/om/element/purchase-order.xml
------------------------------------------------------------------------------
svn:eol-style = native