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 2013/01/21 21:44:41 UTC

svn commit: r1436606 - in /webservices/axiom/trunk/modules: axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/jav...

Author: veithen
Date: Mon Jan 21 20:44:41 2013
New Revision: 1436606

URL: http://svn.apache.org/viewvc?rev=1436606&view=rev
Log:
Consolidated TestSerialize and TestGetSAXSource (org.apache.axiom.ts.om.container).

Added:
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SAXSerializer.java
      - copied, changed from r1436500, webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SAXSerializer.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java   (with props)
Removed:
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SAXSerializer.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetSAXSource.java
Modified:
    webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/axiom/trunk/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializationStrategy.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromXMLStreamReader.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToOutputStream.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToWriter.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToXMLStreamWriter.java

Modified: webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Mon Jan 21 20:44:41 2013
@@ -66,6 +66,9 @@ public class OMImplementationTest extend
         // TODO: this is not supported yet
         builder.exclude(TestGetXMLStreamReaderWithIncompleteDescendant.class, "(cache=false)");
         
+        // TODO: getSAXSource doesn't honor the cache flag yet
+        builder.exclude(TestSerialize.class, "(&(serializationStrategy=SAXSource)(cache=false))");
+        
         return builder.build();
     }
 }

Modified: webservices/axiom/trunk/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java Mon Jan 21 20:44:41 2013
@@ -50,6 +50,13 @@ public class OMImplementationTest extend
         
         // TODO: if there is a comment node surrounded by text, then these text nodes need to be merged
         builder.exclude(TestDigest.class, "(|(file=digest3.xml)(file=digest4.xml))");
+
+        // TODO: getSAXSource doesn't honor the cache flag yet
+        builder.exclude(org.apache.axiom.ts.om.container.TestSerialize.class, "(&(serializationStrategy=SAXSource)(cache=false))");
+        builder.exclude(org.apache.axiom.ts.om.sourcedelement.TestSerialize.class, "(&(serializationStrategy=SAXSource)(cache=false))");
+        
+        // TODO: the SAXSource returned by getSAXSource always expands OMSourcedElements
+        builder.exclude(org.apache.axiom.ts.om.sourcedelement.TestSerialize.class, "(&(serializationStrategy=SAXSource)(destructive=false))");
         
         return builder.build();
     }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Mon Jan 21 20:44:41 2013
@@ -35,6 +35,7 @@ import org.apache.axiom.ts.om.xpath.Test
 import org.apache.axiom.ts.strategy.BuilderFactory;
 import org.apache.axiom.ts.strategy.ExpansionStrategy;
 import org.apache.axiom.ts.strategy.serialization.SerializationStrategy;
+import org.apache.axiom.ts.strategy.serialization.SerializeFromSAXSource;
 import org.apache.axiom.ts.strategy.serialization.SerializeFromXMLStreamReader;
 import org.apache.axiom.ts.strategy.serialization.SerializeToOutputStream;
 import org.apache.axiom.ts.strategy.serialization.SerializeToWriter;
@@ -59,7 +60,9 @@ public class OMTestSuiteBuilder extends 
         new SerializeToXMLStreamWriter(true),
         new SerializeToXMLStreamWriter(false),
         new SerializeFromXMLStreamReader(true),
-        new SerializeFromXMLStreamReader(false) };
+        new SerializeFromXMLStreamReader(false),
+        new SerializeFromSAXSource(true),
+        new SerializeFromSAXSource(false) };
     
     private static final ExpansionStrategy[] expansionStrategies = {
         ExpansionStrategy.DONT_EXPAND,
@@ -140,13 +143,10 @@ public class OMTestSuiteBuilder extends 
                 // the entire document is serialized (so that the DTD is available)
                 if (!file.hasEntityReferences() || cf == OMContainerFactory.DOCUMENT) {
                     for (int k=0; k<serializationStrategies.length; k++) {
-                        addTest(new org.apache.axiom.ts.om.container.TestSerialize(metaFactory, file, containerFactories[j], serializationStrategies[k]));
-                    }
-                    // The SAXSource returned by getSAXSource is not able to reconstruct the internal subset.
-                    // Skip test documents that have a DTD with an internal subset.
-                    if (!file.hasInternalSubset()) {
-                        addTest(new org.apache.axiom.ts.om.container.TestGetSAXSource(metaFactory, file, cf, true));
-                        addTest(new org.apache.axiom.ts.om.container.TestGetSAXSource(metaFactory, file, cf, false));
+                        SerializationStrategy ss = serializationStrategies[k];
+                        if (ss.supportsInternalSubset() || !file.hasInternalSubset()) {
+                            addTest(new org.apache.axiom.ts.om.container.TestSerialize(metaFactory, file, containerFactories[j], ss));
+                        }
                     }
                 }
             }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestSerialize.java Mon Jan 21 20:44:41 2013
@@ -26,13 +26,12 @@ import java.net.URL;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.testutils.XMLAssertEx;
 import org.apache.axiom.testutils.conformance.ConformanceTestFile;
 import org.apache.axiom.ts.ConformanceTestCase;
 import org.apache.axiom.ts.strategy.serialization.SerializationStrategy;
 import org.apache.axiom.ts.strategy.serialization.XML;
 import org.apache.commons.io.IOUtils;
-import org.custommonkey.xmlunit.XMLAssert;
-import org.custommonkey.xmlunit.XMLUnit;
 import org.xml.sax.InputSource;
 
 public class TestSerialize extends ConformanceTestCase {
@@ -63,7 +62,7 @@ public class TestSerialize extends Confo
                 control[0].setSystemId(systemId);
                 InputSource actualIS = actual.getInputSource();
                 actualIS.setSystemId(systemId);
-                XMLAssert.assertXMLIdentical(XMLUnit.compareXML(control[0], actualIS), true);
+                XMLAssertEx.assertXMLIdentical(control[0], actualIS, false);
             } catch (Throwable ex) {
                 System.out.println("Control:");
                 dumpInputSource(control[1]);

Copied: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SAXSerializer.java (from r1436500, webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SAXSerializer.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SAXSerializer.java?p2=webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SAXSerializer.java&p1=webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SAXSerializer.java&r1=1436500&r2=1436606&rev=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/SAXSerializer.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SAXSerializer.java Mon Jan 21 20:44:41 2013
@@ -16,12 +16,12 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.axiom.ts.om.container;
+package org.apache.axiom.ts.strategy.serialization;
 
 import org.apache.xml.serializer.ToXMLStream;
 import org.xml.sax.SAXException;
 
-public class SAXSerializer extends ToXMLStream {
+final class SAXSerializer extends ToXMLStream {
     public void skippedEntity(String name) throws SAXException {
         // The Xalan serializer ignores skippedEntity events; output them as entity references
         entityReference(name);

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializationStrategy.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializationStrategy.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializationStrategy.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializationStrategy.java Mon Jan 21 20:44:41 2013
@@ -50,4 +50,13 @@ public interface SerializationStrategy e
      *         consumes the content
      */
     boolean isCaching();
+    
+    /**
+     * Determine if this serialization strategy is able to correctly serialize the internal subset
+     * of a DOCTYPE declaration.
+     * 
+     * @return <code>true</code> if this strategy correctly serializes the internal subset of a DTD,
+     *         <code>false</code> otherwise
+     */
+    boolean supportsInternalSubset();
 }

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java?rev=1436606&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java Mon Jan 21 20:44:41 2013
@@ -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.strategy.serialization;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.XMLReader;
+
+/**
+ * Serializes an {@link OMContainer} by processing the result of
+ * {@link OMContainer#getSAXSource(boolean)}.
+ */
+public class SerializeFromSAXSource implements SerializationStrategy {
+    private final boolean cache;
+    
+    public SerializeFromSAXSource(boolean cache) {
+        this.cache = cache;
+    }
+
+    public void addTestProperties(AxiomTestCase testCase) {
+        testCase.addTestProperty("serializationStrategy", "SAXSource");
+        testCase.addTestProperty("cache", String.valueOf(cache));
+    }
+
+    public XML serialize(OMContainer container) throws Exception {
+        SAXSource source = container.getSAXSource(cache);
+        XMLReader xmlReader = source.getXMLReader();
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        SAXSerializer serializer = new SAXSerializer();
+        // A SAXSource has no way to tell its consumer about the encoding of the document.
+        // Just set it to UTF-8 to have a well defined encoding.
+        serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+        serializer.setOutputStream(out);
+        xmlReader.setContentHandler(serializer);
+        xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", serializer);
+        xmlReader.parse(source.getInputSource());
+        return new XMLAsByteArray(out.toByteArray());
+    }
+
+    public boolean isPush() {
+        return true;
+    }
+
+    public boolean isCaching() {
+        return cache;
+    }
+
+    public boolean supportsInternalSubset() {
+        return false;
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromSAXSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromXMLStreamReader.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromXMLStreamReader.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeFromXMLStreamReader.java Mon Jan 21 20:44:41 2013
@@ -56,4 +56,8 @@ public class SerializeFromXMLStreamReade
     public boolean isCaching() {
         return cache;
     }
+
+    public boolean supportsInternalSubset() {
+        return true;
+    }
 }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToOutputStream.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToOutputStream.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToOutputStream.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToOutputStream.java Mon Jan 21 20:44:41 2013
@@ -57,4 +57,8 @@ public class SerializeToOutputStream imp
     public boolean isCaching() {
         return cache;
     }
+
+    public boolean supportsInternalSubset() {
+        return true;
+    }
 }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToWriter.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToWriter.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToWriter.java Mon Jan 21 20:44:41 2013
@@ -57,4 +57,8 @@ public class SerializeToWriter implement
     public boolean isCaching() {
         return cache;
     }
+
+    public boolean supportsInternalSubset() {
+        return true;
+    }
 }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToXMLStreamWriter.java?rev=1436606&r1=1436605&r2=1436606&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToXMLStreamWriter.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/strategy/serialization/SerializeToXMLStreamWriter.java Mon Jan 21 20:44:41 2013
@@ -61,4 +61,8 @@ public class SerializeToXMLStreamWriter 
     public boolean isCaching() {
         return cache;
     }
+
+    public boolean supportsInternalSubset() {
+        return true;
+    }
 }