ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1385149 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/util/stax/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/co...
Date Sat, 15 Sep 2012 18:47:25 GMT
Author: veithen
Date: Sat Sep 15 18:47:24 2012
New Revision: 1385149

URL: http://svn.apache.org/viewvc?rev=1385149&view=rev
Log:
AXIOM-401: Increased the test coverage for OMContainer#getXMLStreamReader and fixed DOMXMLStreamReader
to make the new test cases pass.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java
  (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderCommentEvent.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java?rev=1385149&r1=1385148&r2=1385149&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/AbstractXMLStreamReader.java
Sat Sep 15 18:47:24 2012
@@ -150,4 +150,38 @@ public abstract class AbstractXMLStreamR
             }
         }
     }
+
+    public String getElementText() throws XMLStreamException {
+        ///////////////////////////////////////////////////////
+        //// Code block directly from the API documentation ///
+        if (getEventType() != XMLStreamConstants.START_ELEMENT) {
+            throw new XMLStreamException(
+                    "parser must be on START_ELEMENT to read next text", getLocation());
+        }
+        int eventType = next();
+        StringBuffer content = new StringBuffer();
+        while (eventType != XMLStreamConstants.END_ELEMENT) {
+            if (eventType == XMLStreamConstants.CHARACTERS
+                    || eventType == XMLStreamConstants.CDATA
+                    || eventType == XMLStreamConstants.SPACE
+                    || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
+                content.append(getText());
+            } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
+                    || eventType == XMLStreamConstants.COMMENT) {
+                // skipping
+            } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
+                throw new XMLStreamException(
+                        "unexpected end of document when reading element text content");
+            } else if (eventType == XMLStreamConstants.START_ELEMENT) {
+                throw new XMLStreamException(
+                        "element text content may not contain START_ELEMENT");
+            } else {
+                throw new XMLStreamException(
+                        "Unexpected event type " + eventType, getLocation());
+            }
+            eventType = next();
+        }
+        return content.toString();
+        ///////////////////////////////////////////////////////////////
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1385149&r1=1385148&r2=1385149&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
Sat Sep 15 18:47:24 2012
@@ -915,39 +915,8 @@ class SwitchingWrapper extends AbstractX
             currentEvent = END_ELEMENT;
             return elementText;
         } else {
-            ///////////////////////////////////////////////////////
-            //// Code block directly from the API documentation ///
-            if (getEventType() != XMLStreamConstants.START_ELEMENT) {
-                throw new XMLStreamException(
-                        "parser must be on START_ELEMENT to read next text", getLocation());
-            }
-            int eventType = next();
-            StringBuffer content = new StringBuffer();
-            while (eventType != XMLStreamConstants.END_ELEMENT) {
-                if (eventType == XMLStreamConstants.CHARACTERS
-                        || eventType == XMLStreamConstants.CDATA
-                        || eventType == XMLStreamConstants.SPACE
-                        || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
-                    content.append(getText());
-                } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
-                        || eventType == XMLStreamConstants.COMMENT) {
-                    // skipping
-                } else if (eventType == XMLStreamConstants.END_DOCUMENT) {
-                    throw new XMLStreamException(
-                            "unexpected end of document when reading element text content");
-                } else if (eventType == XMLStreamConstants.START_ELEMENT) {
-                    throw new XMLStreamException(
-                            "element text content may not contain START_ELEMENT");
-                } else {
-                    throw new XMLStreamException(
-                            "Unexpected event type " + eventType, getLocation());
-                }
-                eventType = next();
-            }
-            return content.toString();
-            ///////////////////////////////////////////////////////////////
+            return super.getElementText();
         }
-
     }
 
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java?rev=1385149&r1=1385148&r2=1385149&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/factory/DOMXMLStreamReader.java
Sat Sep 15 18:47:24 2012
@@ -367,6 +367,13 @@ class DOMXMLStreamReader extends Abstrac
         return internalGetText().toCharArray();
     }
 
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
throws XMLStreamException {
+        String text = internalGetText();
+        int copied = Math.min(length, text.length()-sourceStart);
+        text.getChars(sourceStart, sourceStart + copied, target, targetStart);
+        return copied;
+    }
+
     public String getPITarget() {
         if (event == PROCESSING_INSTRUCTION) {
             return ((ProcessingInstruction)node).getTarget();
@@ -418,17 +425,6 @@ class DOMXMLStreamReader extends Abstrac
         throw new UnsupportedOperationException();
     }
 
-    public String getElementText() throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
-    }
-
-    public int getTextCharacters(int arg0, char[] arg1, int arg2, int arg3)
-            throws XMLStreamException {
-        // TODO
-        throw new UnsupportedOperationException();
-    }
-
     public boolean standaloneSet() {
         // TODO
         throw new UnsupportedOperationException();

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=1385149&r1=1385148&r2=1385149&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 Sep 15 18:47:24 2012
@@ -256,8 +256,17 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestGetTextWithMixedOMTextChildren(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromParser(metaFactory));
-        addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCommentEvent(metaFactory));
+        for (int i=0; i<builderFactories.length; i++) {
+            BuilderFactory bf = builderFactories[i];
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCommentEvent(metaFactory,
bf, true));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCommentEvent(metaFactory,
bf, false));
+        }
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderGetElementText(metaFactory));
+        for (int i=0; i<builderFactories.length; i++) {
+            BuilderFactory bf = builderFactories[i];
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderGetElementTextFromParser(metaFactory,
bf, true));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderGetElementTextFromParser(metaFactory,
bf, false));
+        }
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderGetNamespaceContext(metaFactory,
true));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderGetNamespaceContext(metaFactory,
false));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderNextTag(metaFactory));

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderCommentEvent.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderCommentEvent.java?rev=1385149&r1=1385148&r2=1385149&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderCommentEvent.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderCommentEvent.java
Sat Sep 15 18:47:24 2012
@@ -18,22 +18,33 @@
  */
 package org.apache.axiom.ts.om.element;
 
+import java.io.StringReader;
+
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.om.container.BuilderFactory;
+import org.xml.sax.InputSource;
 
 public class TestGetXMLStreamReaderCommentEvent extends AxiomTestCase {
-    public TestGetXMLStreamReaderCommentEvent(OMMetaFactory metaFactory) {
+    private final BuilderFactory builderFactory;
+    private final boolean cache;
+    
+    public TestGetXMLStreamReaderCommentEvent(OMMetaFactory metaFactory, BuilderFactory builderFactory,
boolean cache) {
         super(metaFactory);
+        this.builderFactory = builderFactory;
+        this.cache = cache;
+        builderFactory.addTestProperties(this);
+        addTestProperty("cache", Boolean.toString(cache));
     }
 
     protected void runTest() throws Throwable {
-        OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(),
-                "<a><!--comment text--></a>");
-        XMLStreamReader reader = element.getXMLStreamReader();
+        OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new
StringReader("<a><!--comment text--></a>")));
+        OMElement element = builder.getDocumentElement();
+        XMLStreamReader reader = element.getXMLStreamReader(cache);
         assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
         assertEquals(XMLStreamReader.COMMENT, reader.next());
         assertEquals("comment text", reader.getText());

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java?rev=1385149&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java
Sat Sep 15 18:47:24 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.io.StringReader;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.om.container.BuilderFactory;
+import org.xml.sax.InputSource;
+
+public class TestGetXMLStreamReaderGetElementTextFromParser extends AxiomTestCase {
+    private final BuilderFactory builderFactory;
+    private final boolean cache;
+    
+    public TestGetXMLStreamReaderGetElementTextFromParser(OMMetaFactory metaFactory, BuilderFactory
builderFactory, boolean cache) {
+        super(metaFactory);
+        this.builderFactory = builderFactory;
+        this.cache = cache;
+        builderFactory.addTestProperties(this);
+        addTestProperty("cache", Boolean.toString(cache));
+    }
+
+    protected void runTest() throws Throwable {
+        // Note: We test getElementText on a child element ("b") of the element from which
we request
+        //       the XMLStreamReader ("a"). This is to make sure that the XMLStreamReader
implementation actually
+        //       delegates to the underlying parser (which is not necessarily the case on
"a").
+        OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(
+                new StringReader("<a><b>AB<!--comment text-->CD</b></a>")));
+        OMElement element = builder.getDocumentElement();
+        
+        XMLStreamReader reader = element.getXMLStreamReader(cache);
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+
+        assertEquals("ABCD", reader.getElementText());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderGetElementTextFromParser.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message