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 2015/05/08 20:21:31 UTC

svn commit: r1678413 - in /webservices/axiom/trunk/testing: axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/ testutils/src/main/java/org/apache/axiom/testutils/stax/

Author: veithen
Date: Fri May  8 18:21:31 2015
New Revision: 1678413

URL: http://svn.apache.org/r1678413
Log:
Fix an issue with the testing code that occurs because DOM (Xerces) sorts attributes by name.

Added:
    webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java   (with props)
Modified:
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/BuilderFactory.java
    webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/BuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/BuilderFactory.java?rev=1678413&r1=1678412&r2=1678413&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/BuilderFactory.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/dimension/BuilderFactory.java Fri May  8 18:21:31 2015
@@ -74,6 +74,8 @@ public abstract class BuilderFactory ext
             // stores the unparsed replacement value. Therefore OMEntityReference#getReplacementText()
             // returns null for nodes created from a DOM tree.
             comparator.setCompareEntityReplacementValue(false);
+            // DOM (or at least Xerces) sorts attributes
+            comparator.setSortAttributes(true);
         }
 
         public void addTestParameters(MatrixTestCase testCase) {

Added: webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java?rev=1678413&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java (added)
+++ webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java Fri May  8 18:21:31 2015
@@ -0,0 +1,93 @@
+/*
+ * 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.testutils.stax;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+final class AttributeSortingXMLStreamReaderFilter extends StreamReaderDelegate {
+    private int[] indexMap;
+    
+    public AttributeSortingXMLStreamReaderFilter(XMLStreamReader reader) {
+        super(reader);
+    }
+
+    @Override
+    public int next() throws XMLStreamException {
+        indexMap = null;
+        return super.next();
+    }
+
+    @Override
+    public int nextTag() throws XMLStreamException {
+        indexMap = null;
+        return super.nextTag();
+    }
+
+    private int getIndex(int index) {
+        if (indexMap == null) {
+            int n = super.getAttributeCount();
+            indexMap = new int[n];
+            SortedMap<String,Integer> map = new TreeMap<String,Integer>();
+            for (int i=0; i<n; i++) {
+                map.put(super.getAttributeName(i).toString(), i);
+            }
+            int newIndex = 0;
+            for (int orgIndex : map.values()) {
+                indexMap[newIndex++] = orgIndex;
+            }
+        }
+        return indexMap[index];
+    }
+    
+    @Override
+    public String getAttributeLocalName(int index) {
+        return super.getAttributeLocalName(getIndex(index));
+    }
+
+    @Override
+    public QName getAttributeName(int index) {
+        return super.getAttributeName(getIndex(index));
+    }
+
+    @Override
+    public String getAttributeNamespace(int index) {
+        return super.getAttributeNamespace(getIndex(index));
+    }
+
+    @Override
+    public String getAttributePrefix(int index) {
+        return super.getAttributePrefix(getIndex(index));
+    }
+
+    @Override
+    public String getAttributeType(int index) {
+        return super.getAttributeType(getIndex(index));
+    }
+
+    @Override
+    public String getAttributeValue(int index) {
+        return super.getAttributeValue(getIndex(index));
+    }
+}

Propchange: webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/AttributeSortingXMLStreamReaderFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java?rev=1678413&r1=1678412&r2=1678413&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java (original)
+++ webservices/axiom/trunk/testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java Fri May  8 18:21:31 2015
@@ -47,11 +47,12 @@ import javax.xml.stream.XMLStreamReader;
  * (return values or exceptions thrown) of these invocations are compared to each other.
  */
 public class XMLStreamReaderComparator {
-    private final XMLStreamReader expected;
-    private final XMLStreamReader actual;
+    private XMLStreamReader expected;
+    private XMLStreamReader actual;
     private boolean compareEntityReplacementValue = true;
     private boolean compareCharacterEncodingScheme = true;
     private boolean compareEncoding = true;
+    private boolean sortAttributes = false;
     private final LinkedList<QName> path = new LinkedList<QName>();
     
     /**
@@ -227,7 +228,15 @@ public class XMLStreamReaderComparator {
         compareEncoding = value;
     }
 
+    public void setSortAttributes(boolean sortAttributes) {
+        this.sortAttributes = sortAttributes;
+    }
+
     public void compare() throws Exception {
+        if (sortAttributes) {
+            expected = new AttributeSortingXMLStreamReaderFilter(expected);
+            actual = new AttributeSortingXMLStreamReaderFilter(actual);
+        }
         while (true) {
             int eventType = ((Integer)assertSameResult("getEventType")).intValue();
             if (eventType == XMLStreamReader.START_ELEMENT) {