ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1719694 - in /webservices/axiom/trunk/testing: axiom-truth/src/main/java/org/apache/axiom/truth/ jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/ xml-truth/ xml-truth/src/main/java/org/apache/axiom/truth/xml/ xml-truth/src/main/java/...
Date Sat, 12 Dec 2015 14:56:51 GMT
Author: veithen
Date: Sat Dec 12 14:56:50 2015
New Revision: 1719694

URL: http://svn.apache.org/viewvc?rev=1719694&view=rev
Log:
Add support for DOM2 implementations in xml-truth.

Added:
    webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java
  (with props)
    webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/CompareTest.java
      - copied, changed from r1719685, webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMCompareTest.java
    webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java
  (with props)
Removed:
    webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMCompareTest.java
Modified:
    webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomXML.java
    webservices/axiom/trunk/testing/xml-truth/pom.xml
    webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMTraverser.java
    webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMXML.java
    webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
    webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLSubject.java
    webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/spi/XML.java
    webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMTraverserTest.java

Modified: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomXML.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomXML.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomXML.java
(original)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomXML.java
Sat Dec 12 14:56:50 2015
@@ -30,6 +30,11 @@ final class AxiomXML implements XML {
     }
 
     @Override
+    public boolean isReportingElementContentWhitespace() {
+        return true;
+    }
+
+    @Override
     public Traverser createTraverser(boolean expandEntityReferences) {
         return new AxiomTraverser(root, expandEntityReferences);
     }

Added: webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java?rev=1719694&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java
(added)
+++ webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java
Sat Dec 12 14:56:50 2015
@@ -0,0 +1,51 @@
+/*
+ * 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.jaxp;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.testing.multiton.Multiton;
+
+public abstract class DOMImplementation extends Multiton {
+    public static final DOMImplementation XERCES = new DOMImplementation("xerces") {
+        @Override
+        public DocumentBuilderFactory newDocumentBuilderFactory() {
+            return new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
+        }
+    };
+    
+    public static final DOMImplementation CRIMSON = new DOMImplementation("crimson") {
+        @Override
+        public DocumentBuilderFactory newDocumentBuilderFactory() {
+            return new org.apache.crimson.jaxp.DocumentBuilderFactoryImpl();
+        }
+    };
+    
+    private final String name;
+
+    private DOMImplementation(String name) {
+        this.name = name;
+    }
+
+    public final String getName() {
+        return name;
+    }
+    
+    public abstract DocumentBuilderFactory newDocumentBuilderFactory();
+}

Propchange: webservices/axiom/trunk/testing/jaxp-testsuite/src/main/java/org/apache/axiom/ts/jaxp/DOMImplementation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/testing/xml-truth/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/pom.xml?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/pom.xml (original)
+++ webservices/axiom/trunk/testing/xml-truth/pom.xml Sat Dec 12 14:56:50 2015
@@ -46,8 +46,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>xerces</groupId>
-            <artifactId>xercesImpl</artifactId>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>jaxp-testsuite</artifactId>
+            <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>

Modified: webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMTraverser.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMTraverser.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMTraverser.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMTraverser.java
Sat Dec 12 14:56:50 2015
@@ -37,12 +37,14 @@ import com.google.common.base.Strings;
 
 final class DOMTraverser implements Traverser {
     private final Node root;
+    private final boolean dom3;
     private final boolean expandEntityReferences;
     private Node node;
     private boolean descend;
     
-    DOMTraverser(Node root, boolean expandEntityReferences) {
+    DOMTraverser(Node root, boolean dom3, boolean expandEntityReferences) {
         this.root = root;
+        this.dom3 = dom3;
         this.expandEntityReferences = expandEntityReferences;
         if (root.getNodeType() == Node.DOCUMENT_NODE) {
             node = root;
@@ -93,7 +95,7 @@ final class DOMTraverser implements Trav
                     }
                 case Node.TEXT_NODE:
                     descend = false;
-                    return ((Text)node).isElementContentWhitespace() ? Event.WHITESPACE :
Event.TEXT;
+                    return dom3 && ((Text)node).isElementContentWhitespace() ? Event.WHITESPACE
: Event.TEXT;
                 case Node.ENTITY_REFERENCE_NODE:
                     if (expandEntityReferences) {
                         descend = !visited;

Modified: webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMXML.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMXML.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMXML.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/DOMXML.java
Sat Dec 12 14:56:50 2015
@@ -20,17 +20,26 @@ package org.apache.axiom.truth.xml;
 
 import org.apache.axiom.truth.xml.spi.Traverser;
 import org.apache.axiom.truth.xml.spi.XML;
+import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
 final class DOMXML implements XML {
     private final Node root;
+    private final boolean dom3;
     
     DOMXML(Node root) {
         this.root = root;
+        Document document = root instanceof Document ? (Document)root : root.getOwnerDocument();
+        dom3 = document.getImplementation().hasFeature("XML", "3.0");
+    }
+
+    @Override
+    public boolean isReportingElementContentWhitespace() {
+        return dom3;
     }
 
     @Override
     public Traverser createTraverser(boolean expandEntityReferences) {
-        return new DOMTraverser(root, expandEntityReferences);
+        return new DOMTraverser(root, dom3, expandEntityReferences);
     }
 }

Modified: webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/StAXXML.java
Sat Dec 12 14:56:50 2015
@@ -30,6 +30,11 @@ import com.ctc.wstx.stax.WstxInputFactor
 
 abstract class StAXXML implements XML {
     @Override
+    public boolean isReportingElementContentWhitespace() {
+        return true;
+    }
+
+    @Override
     public final Traverser createTraverser(boolean expandEntityReferences) throws TraverserException
{
         WstxInputFactory factory = new WstxInputFactory();
         factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.valueOf(expandEntityReferences));

Modified: webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLSubject.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLSubject.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLSubject.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/XMLSubject.java
Sat Dec 12 14:56:50 2015
@@ -354,15 +354,6 @@ public final class XMLSubject extends Su
                 }
             };
         }
-        if (treatWhitespaceAsText) {
-            traverser = new Filter(traverser) {
-                @Override
-                public Event next() throws TraverserException {
-                    Event event = super.next();
-                    return event == Event.WHITESPACE ? Event.TEXT : event;
-                }
-            };
-        }
         if (ignoreRedundantNamespaceDeclarations && !ignoreNamespaceDeclarations)
{
             traverser = new RedundantNamespaceDeclarationFilter(traverser);
         }
@@ -386,11 +377,22 @@ public final class XMLSubject extends Su
     public void hasSameContentAs(Object other) {
         try {
             Traverser actual = createTraverser(xml);
-            Traverser expected = createTraverser(XMLTruth.xml(other));
+            XML expectedXML = XMLTruth.xml(other);
+            Traverser expected = createTraverser(expectedXML);
             while (true) {
                 Event actualEvent = actual.next();
                 Event expectedEvent = expected.next();
-                assertThat(actualEvent).isEqualTo(expectedEvent);
+                if (expectedEvent == Event.WHITESPACE || expectedEvent == Event.TEXT) {
+                    if (!xml.isReportingElementContentWhitespace()) {
+                        assertThat(actualEvent).isEqualTo(Event.TEXT);
+                    } else if (treatWhitespaceAsText || !expectedXML.isReportingElementContentWhitespace())
{
+                        assertThat(actualEvent).isAnyOf(Event.WHITESPACE, Event.TEXT);
+                    } else {
+                        assertThat(actualEvent).isEqualTo(expectedEvent);
+                    }
+                } else {
+                    assertThat(actualEvent).isEqualTo(expectedEvent);
+                }
                 if (expectedEvent == null) {
                     break;
                 }

Modified: webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/spi/XML.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/spi/XML.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/spi/XML.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/main/java/org/apache/axiom/truth/xml/spi/XML.java
Sat Dec 12 14:56:50 2015
@@ -19,5 +19,14 @@
 package org.apache.axiom.truth.xml.spi;
 
 public interface XML {
+    /**
+     * Check whether element content whitespace will be reported as {@link Event#WHITESPACE}
events.
+     * 
+     * @return {@link true} if element content whitespace will be reported as
+     *         {@link Event#WHITESPACE} events; {@link false} if element content whitespace
+     *         reporting is not supported and {@link Event#TEXT} events will be generated
+     */
+    boolean isReportingElementContentWhitespace();
+    
     Traverser createTraverser(boolean expandEntityReferences) throws TraverserException;
 }

Copied: webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/CompareTest.java
(from r1719685, webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMCompareTest.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/CompareTest.java?p2=webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/CompareTest.java&p1=webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMCompareTest.java&r1=1719685&r2=1719694&rev=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMCompareTest.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/CompareTest.java
Sat Dec 12 14:56:50 2015
@@ -22,37 +22,37 @@ import static com.google.common.truth.Tr
 import static org.apache.axiom.testing.multiton.Multiton.getInstances;
 import static org.apache.axiom.truth.xml.XMLTruth.xml;
 
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import junit.framework.TestSuite;
 
 import org.apache.axiom.testutils.suite.MatrixTestCase;
 import org.apache.axiom.testutils.suite.MatrixTestSuiteBuilder;
 import org.apache.axiom.ts.xml.XMLSample;
-import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
 
-public class DOMCompareTest extends MatrixTestCase {
+public class CompareTest extends MatrixTestCase {
     private XMLSample sample;
+    private final XMLObjectFactory left;
+    private final XMLObjectFactory right;
     private boolean expandEntityReferences;
 
-    public DOMCompareTest(XMLSample sample, boolean expandEntityReferences) {
+    public CompareTest(XMLSample sample, XMLObjectFactory left, XMLObjectFactory right,
+            boolean expandEntityReferences) {
         this.sample = sample;
+        this.left = left;
+        this.right = right;
         this.expandEntityReferences = expandEntityReferences;
         addTestParameter("sample", sample.getName());
+        addTestParameter("left", left.getName());
+        addTestParameter("right", right.getName());
         addTestParameter("expandEntityReferences", expandEntityReferences);
     }
     
     @Override
     protected void runTest() throws Throwable {
-        DocumentBuilderFactory factory = new DocumentBuilderFactoryImpl();
-        factory.setNamespaceAware(true);
-        // If necessary, let DOMTraverser expand entity references
-        factory.setExpandEntityReferences(false);
         assertAbout(xml())
-                .that(factory.newDocumentBuilder().parse(sample.getUrl().toString()))
+                .that(left.toXMLObject(sample))
                 .ignoringWhitespaceInPrologAndEpilog()
                 .expandingEntityReferences(expandEntityReferences)
-                .hasSameContentAs(sample.getUrl());
+                .hasSameContentAs(right.toXMLObject(sample));
     }
 
     public static TestSuite suite() {
@@ -60,8 +60,12 @@ public class DOMCompareTest extends Matr
             @Override
             protected void addTests() {
                 for (XMLSample sample : getInstances(XMLSample.class)) {
-                    addTest(new DOMCompareTest(sample, true));
-                    addTest(new DOMCompareTest(sample, false));
+                    for (XMLObjectFactory left : getInstances(XMLObjectFactory.class)) {
+                        for (XMLObjectFactory right : getInstances(XMLObjectFactory.class))
{
+                            addTest(new CompareTest(sample, left, right, true));
+                            addTest(new CompareTest(sample, left, right, false));
+                        }
+                    }
                 }
             }
         }.build();

Modified: webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMTraverserTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMTraverserTest.java?rev=1719694&r1=1719693&r2=1719694&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMTraverserTest.java
(original)
+++ webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/DOMTraverserTest.java
Sat Dec 12 14:56:50 2015
@@ -28,7 +28,7 @@ import org.junit.Test;
 public class DOMTraverserTest {
     @Test
     public void testEntityReferenceExpansion() throws Exception {
-        Traverser t = new CoalescingFilter(new DOMTraverser(XMLSample.ENTITY_REFERENCE_NESTED.getDocument(),
true));
+        Traverser t = new CoalescingFilter(new DOMXML(XMLSample.ENTITY_REFERENCE_NESTED.getDocument()).createTraverser(true));
         assertThat(t.next()).isEqualTo(Event.DOCUMENT_TYPE);
         assertThat(t.next()).isEqualTo(Event.START_ELEMENT);
         assertThat(t.next()).isEqualTo(Event.TEXT);

Added: webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java?rev=1719694&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java
(added)
+++ webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java
Sat Dec 12 14:56:50 2015
@@ -0,0 +1,67 @@
+/*
+ * 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.truth.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.testing.multiton.Instances;
+import org.apache.axiom.testing.multiton.Multiton;
+import org.apache.axiom.ts.jaxp.DOMImplementation;
+import org.apache.axiom.ts.xml.XMLSample;
+
+public abstract class XMLObjectFactory extends Multiton {
+    public static final XMLObjectFactory DEFAULT = new XMLObjectFactory("url") {
+        @Override
+        public Object toXMLObject(XMLSample sample) {
+            return sample.getUrl();
+        }
+    };
+    
+    private final String name;
+
+    private XMLObjectFactory(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public abstract Object toXMLObject(XMLSample sample) throws Exception;
+
+    @Instances
+    private static XMLObjectFactory[] instances() {
+        List<XMLObjectFactory> instances = new ArrayList<>();
+        for (final DOMImplementation impl : getInstances(DOMImplementation.class)) {
+            instances.add(new XMLObjectFactory(impl.getName() + "-dom") {
+                @Override
+                public Object toXMLObject(XMLSample sample) throws Exception {
+                    DocumentBuilderFactory factory = impl.newDocumentBuilderFactory();
+                    factory.setNamespaceAware(true);
+                    factory.setExpandEntityReferences(false);
+                    return factory.newDocumentBuilder().parse(sample.getUrl().toString());
+                }
+            });
+        }
+        return instances.toArray(new XMLObjectFactory[instances.size()]);
+    }
+}

Propchange: webservices/axiom/trunk/testing/xml-truth/src/test/java/org/apache/axiom/truth/xml/XMLObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message