You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/12/03 18:10:53 UTC

svn commit: r600597 - in /webservices/axis2/trunk/java/modules/integration/test/org/tempuri: ./ complex/ differenceEngine/ elementQualifier/

Author: scheu
Date: Mon Dec  3 09:10:52 2007
New Revision: 600597

URL: http://svn.apache.org/viewvc?rev=600597&view=rev
Log:
AXIS2-3328
Contributor: Brian Murray
Fix the xml comparison engine for wsdl files.  In some cases, different jvms produce
different (but logically similar) wsdl files.  Brian's fix corrects this.
Thanks Brian.

Added:
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLController.java
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLDifferenceEngine.java
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/WSDLElementQualifier.java
Modified:
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/BaseDataTypesTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/tempuri/complex/ComplexDataTypesTest.java

Modified: webservices/axis2/trunk/java/modules/integration/test/org/tempuri/BaseDataTypesTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/tempuri/BaseDataTypesTest.java?rev=600597&r1=600596&r2=600597&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/tempuri/BaseDataTypesTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/tempuri/BaseDataTypesTest.java Mon Dec  3 09:10:52 2007
@@ -20,9 +20,11 @@
 
 import org.apache.ws.java2wsdl.Java2WSDLBuilder;
 import org.apache.axis2.integration.TestingUtils;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.DifferenceEngine;
 import org.custommonkey.xmlunit.XMLTestCase;
 import org.custommonkey.xmlunit.XMLUnit;
-import org.custommonkey.xmlunit.Diff;
+import org.tempuri.elementQualifier.WSDLElementQualifier;
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileReader;
@@ -40,7 +42,12 @@
             builder.generateWSDL();
             FileReader control = new FileReader(wsdlLocation);
             StringReader test = new StringReader(new String(out.toByteArray()));
-            assertXMLEqual(control, test);
+            
+            Diff myDiff = new Diff(XMLUnit.buildDocument(XMLUnit.getControlParser(), control), 
+		               XMLUnit.buildDocument(XMLUnit.getControlParser(), test), 
+		               (DifferenceEngine) null, new WSDLElementQualifier());
+            if (!myDiff.similar()) 
+	            fail(myDiff.toString()); 
         } finally {
             XMLUnit.setIgnoreWhitespace(false);
         }

Modified: webservices/axis2/trunk/java/modules/integration/test/org/tempuri/complex/ComplexDataTypesTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/tempuri/complex/ComplexDataTypesTest.java?rev=600597&r1=600596&r2=600597&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/tempuri/complex/ComplexDataTypesTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/tempuri/complex/ComplexDataTypesTest.java Mon Dec  3 09:10:52 2007
@@ -18,15 +18,19 @@
  */
 package org.tempuri.complex;
 
+import org.custommonkey.xmlunit.Diff;
 import org.custommonkey.xmlunit.XMLTestCase;
 import org.custommonkey.xmlunit.XMLUnit;
+import org.tempuri.differenceEngine.WSDLController;
+import org.tempuri.differenceEngine.WSDLDifferenceEngine;
+import org.tempuri.elementQualifier.WSDLElementQualifier;
 import org.apache.ws.java2wsdl.Java2WSDLBuilder;
-import org.tempuri.BaseDataTypes;
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileReader;
 import java.io.StringReader;
 
+
 public class ComplexDataTypesTest extends XMLTestCase {
 
     private String wsdlLocation = System.getProperty("basedir", ".") + "/" + "test-resources/ComplexDataTypes/ComplexDataTypes.wsdl";
@@ -39,7 +43,12 @@
             builder.generateWSDL();
             FileReader control = new FileReader(wsdlLocation);
             StringReader test = new StringReader(new String(out.toByteArray()));
-            assertXMLEqual(control, test);
+            
+            Diff myDiff = new Diff(XMLUnit.buildDocument(XMLUnit.getControlParser(), control), 
+		               XMLUnit.buildDocument(XMLUnit.getControlParser(), test), 
+		               new WSDLDifferenceEngine(new WSDLController()), new WSDLElementQualifier());
+            if (!myDiff.similar()) 
+	            fail(myDiff.toString()); 
         } finally {
             XMLUnit.setIgnoreWhitespace(false);
         }

Added: webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLController.java?rev=600597&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLController.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLController.java Mon Dec  3 09:10:52 2007
@@ -0,0 +1,24 @@
+package org.tempuri.differenceEngine;
+
+import org.custommonkey.xmlunit.ComparisonController;
+import org.custommonkey.xmlunit.Difference;
+
+public class WSDLController implements ComparisonController {   
+    public WSDLController () {
+    }
+
+    /**
+     * Determine whether a Difference that this listener has been notified of
+     *  should halt further XML comparison. This implementation halts 
+     *  if the Difference is not recoverable.
+     * @param afterDifference the last Difference passed to <code>differenceFound</code>
+     * @return false if the difference is recoverable, otherwise return true
+     */
+    public boolean haltComparison(Difference afterDifference) {
+        if (afterDifference.isRecoverable()) {
+            return false;
+        }
+        
+        return true;
+    }
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLDifferenceEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLDifferenceEngine.java?rev=600597&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLDifferenceEngine.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/tempuri/differenceEngine/WSDLDifferenceEngine.java Mon Dec  3 09:10:52 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.tempuri.differenceEngine;
+
+import org.custommonkey.xmlunit.ComparisonController;
+import org.custommonkey.xmlunit.DifferenceEngine;
+import org.custommonkey.xmlunit.DifferenceListener;
+import org.w3c.dom.Attr;
+
+/**
+ * This class extends the DifferenceEngine class to overwrite the methods that
+ * incorrectly fail Diff.similar() for certain equivalent but not identical
+ * XML file comparisons.
+ */
+public class WSDLDifferenceEngine extends DifferenceEngine {
+    /**
+     * Simple constructor
+     * @param controller the instance used to determine whether a Difference
+     *  detected by this class should halt further comparison or not
+     * @see ComparisonController#haltComparison(Difference)
+     */
+    public WSDLDifferenceEngine(ComparisonController controller) {
+    	super(controller);
+    }
+        
+    /**
+     * Compare two attributes to determine if they are equivalent
+     * @param control a known attribute against which a test attribute is being compared
+     * @param test the generated attribute that is being tested against a known attribute
+     * @param listener 
+     * @throws DifferenceFoundException if there is a difference detected between
+     *  the two attributes
+     */
+    protected void compareAttribute(Attr control, Attr test,
+    DifferenceListener listener) throws DifferenceFoundException {    	
+    	// There are no getter methods for these private fields in DifferenceEngine
+    	// controlTracker.visited(control);
+    	// testTracker.visited(test);
+    	
+    	compare(control.getPrefix(), test.getPrefix(), control, test, 
+    		listener, NAMESPACE_PREFIX);
+
+        compare(getValueWithoutNamespace(control), getValueWithoutNamespace(test), control, test,
+            listener, ATTR_VALUE);
+        
+        compare(getValueNamespaceURI(control), getValueNamespaceURI(test), control, test,
+                listener, ATTR_VALUE);        
+        
+        compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
+            test.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
+            control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED);
+    }
+    
+    /**
+     * Obtain the value of this attribute with the namespace prefix removed (if present)
+     * @param attr the attribute for which the non namespaced value is sought
+     * @return the value of this attribute without a namespace prefix
+     */
+    protected String getValueWithoutNamespace(Attr attr) {
+    	String value = attr.getValue();
+    	int index = value.indexOf(':');
+    	int protocol = value.indexOf("://");
+    	
+    	if (value == null)
+    		return null;
+    	
+    	if (index == -1 || index == protocol)
+    		return value;
+    	
+    	return value.substring(index + 1);
+    }
+    
+    /**
+     * Obtain the namespace URI for the value of this attr (if a namespace prefix is present)
+     * @param attr the attribute for which the namespace URI of the value is sought
+     * @return the namespace URI of the attribute's value if a namespace prefix is 
+     *  present, otherwise return null
+     */
+    protected String getValueNamespaceURI(Attr attr) {
+    	String value = attr.getValue();
+    	int index = value.indexOf(':');
+    	int protocol = value.indexOf("://");
+    	
+    	if (value == null || index == -1 || index == protocol)
+    		return null;
+    	
+    	return attr.lookupNamespaceURI(value.substring(0, index));
+    }
+}

Added: webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/WSDLElementQualifier.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/WSDLElementQualifier.java?rev=600597&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/WSDLElementQualifier.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/tempuri/elementQualifier/WSDLElementQualifier.java Mon Dec  3 09:10:52 2007
@@ -0,0 +1,130 @@
+/*
+ * 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.tempuri.elementQualifier;
+
+import org.custommonkey.xmlunit.ElementQualifier;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * This interface implementation determines whether two elements should be compared
+ * when comparing WSDL files.  The nodes are intended for comparison when they are 
+ * defined by the same namespace URI, have the same tag name (without namespace), 
+ * and have the same name attribute.
+ */
+public class WSDLElementQualifier implements ElementQualifier {
+    
+    /**
+     * Determine whether two elements are comparable
+     * @param control an Element from the control XML NodeList
+     * @param test an Element from the test XML NodeList
+     * @return true if the elements are comparable, otherwise return false.  Two 
+     *  elements should be compared if they have the same namespace URI, the same
+     *  tag name (with namespace not present) and the same name attribute.
+     */
+    public boolean qualifyForComparison(Element control, Element test) {
+        return control != null 
+            && test != null 
+            && sameNamespaceURI(control, test)
+            && sameTagName(control, test)
+            && sameNameAttribute(control, test);
+    }
+    
+    /**
+     * Determine whether two nodes are associated with the same namespace URI 
+     * @param control an Element from the control XML NodeList
+     * @param test an Element from the test XML NodeList
+     * @return true if the two nodes are associated with the same namespace URI,
+     *  otherwise return false
+     */
+    protected boolean sameNamespaceURI(Node control, Node test) {
+        String controlNS = control.getNamespaceURI();
+        String testNS = test.getNamespaceURI();
+        
+        if (controlNS == null) {
+            return testNS == null;
+        }
+        
+        return controlNS.equals(testNS);
+    }
+    
+    /**
+     * Determine whether two nodes have the same tag name once any 
+     * namespace information is removed
+     * @param control an Element from the control XML NodeList
+     * @param test an Element from the test XML NodeList
+     * @return true if the two nodes have the same tag name not including 
+     *  namespace information (if present), otherwise return false
+     */
+    protected boolean sameTagName(Node control, Node test) {
+    	return getTagWithoutNamespace(control).equals(getTagWithoutNamespace(test));
+    }
+    
+    /**
+     * Remove any namespace information from a tag name
+     * @param node an Element from an XML NodeList
+     * @return the localName if the node includes namespace information, 
+     *  otherwise return the nodeName
+     */
+    protected String getTagWithoutNamespace(Node node) {
+        String name = node.getLocalName();
+        
+        if (name == null) {
+            return node.getNodeName();
+        }
+        
+        return name;
+    } 
+    
+    /**
+     * Determine whether two nodes have the same name attribute 
+     * @param control an Element from the control XML NodeList
+     * @param test an Element from the test XML NodeList
+     * @return true if the two nodes have the same name attribute 
+     *  (with the absence of a name attribute considered a specific
+     *  name attribute), otherwise return false
+     */
+    protected boolean sameNameAttribute(Node control, Node test) {
+    	return getNameAttribute(control).equals(getNameAttribute(test));
+    }
+    
+    /**
+     * Obtain the name attribute for the node
+     * @param node an Element for which the Name attribute is sought
+     * @return the name attribute for the node if the "name" attribute
+     *  exists, otherwise return ""
+     */
+    protected String getNameAttribute(Node node) {
+        NamedNodeMap nnMap = node.getAttributes();
+        
+        if (nnMap.getLength() == 0) {
+            return "";
+        }
+        
+        Node nameAttrNode = nnMap.getNamedItem("name");
+        if (nameAttrNode == null) {
+            return "";
+        }
+        
+        return nameAttrNode.getNodeValue();
+    } 
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org