From: <bo...@us...> - 2007-05-18 05:25:54
|
Revision: 210 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=210&view=rev Author: bodewig Date: 2007-05-17 22:25:53 -0700 (Thu, 17 May 2007) Log Message: ----------- make attribute check symmetric Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-05-16 11:25:23 UTC (rev 209) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-05-18 05:25:53 UTC (rev 210) @@ -485,6 +485,14 @@ NamedNodeMap testAttr, DifferenceListener listener) throws DifferenceFoundException { + ArrayList allTestAttrs = new ArrayList(); + for (int i=0; i < testAttr.getLength(); ++i) { + Attr nextAttr = (Attr) testAttr.item(i); + if (!isXMLNSAttribute(nextAttr)) { + allTestAttrs.add(nextAttr); + } + } + for (int i=0; i < controlAttr.getLength(); ++i) { Attr nextAttr = (Attr) controlAttr.item(i); if (isXMLNSAttribute(nextAttr)) { @@ -501,6 +509,10 @@ compareTo = (Attr) testAttr.getNamedItem(attrName); } + if (compareTo != null) { + allTestAttrs.remove(compareTo); + } + if (isRecognizedXMLSchemaInstanceAttribute(nextAttr)) { compareRecognizedXMLSchemaInstanceAttribute(nextAttr, compareTo, @@ -525,6 +537,20 @@ } } } + + for (Iterator iter = allTestAttrs.iterator(); iter.hasNext(); ) { + Attr nextAttr = (Attr) iter.next(); + if (isRecognizedXMLSchemaInstanceAttribute(nextAttr)) { + compareRecognizedXMLSchemaInstanceAttribute(null, nextAttr, + listener); + } else { + compare(null, + getUnNamespacedNodeName(nextAttr, + isNamespaced(nextAttr)), + control, test, listener, ATTR_NAME_NOT_FOUND); + } + } + controlTracker.clearTrackedAttribute(); testTracker.clearTrackedAttribute(); } @@ -577,17 +603,20 @@ Attr test, DifferenceListener listener) throws DifferenceFoundException { + Attr nonNullNode = control != null ? control : test; Difference d = XMLConstants.W3C_XML_SCHEMA_INSTANCE_SCHEMA_LOCATION_ATTR - .equals(control.getLocalName()) + .equals(nonNullNode.getLocalName()) ? SCHEMA_LOCATION : NO_NAMESPACE_SCHEMA_LOCATION; - controlTracker.visited(control); + if (control != null) { + controlTracker.visited(control); + } if (test != null) { testTracker.visited(test); } - compare(control.getValue(), + compare(control != null ? control.getValue() : "[not specified]", test != null ? test.getValue() : "[not specified]", control, test, listener, d); } Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-05-16 11:25:23 UTC (rev 209) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-05-18 05:25:53 UTC (rev 210) @@ -81,15 +81,18 @@ List differences = detailedDiff.getAllDifferences(); - assertEquals("size: " + detailedDiff, 4, differences.size()); + assertEquals("size: " + detailedDiff, 5, differences.size()); assertEquals("first: " + detailedDiff, DifferenceConstants.ELEMENT_NUM_ATTRIBUTES, differences.get(0)); assertEquals("second: " + detailedDiff, DifferenceConstants.ATTR_VALUE, differences.get(1)); assertEquals("third: " + detailedDiff, DifferenceConstants.ATTR_SEQUENCE, differences.get(2)); - assertEquals("fourth: " + detailedDiff, - DifferenceConstants.HAS_CHILD_NODES, differences.get(3)); + assertEquals("forth: " + detailedDiff, + DifferenceConstants.ATTR_NAME_NOT_FOUND, + differences.get(3)); + assertEquals("fifth: " + detailedDiff, + DifferenceConstants.HAS_CHILD_NODES, differences.get(4)); } public void testPrototypeIsADetailedDiff() throws Exception { Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2007-05-16 11:25:23 UTC (rev 209) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2007-05-18 05:25:53 UTC (rev 210) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 200, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -686,7 +686,7 @@ /** * inspired by {@link * http://day-to-day-stuff.blogspot.com/2007/05/comparing-xml-in-junit-test.html - * Erik von Oosten's Weblog }, made us implement special handling + * Erik von Oosten's Weblog}, made us implement special handling * of schemaLocation. */ public void testNamespacePrefixDiff() throws Exception { Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2007-05-16 11:25:23 UTC (rev 209) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java 2007-05-18 05:25:53 UTC (rev 210) @@ -801,9 +801,9 @@ Element test = document.createElement("foo"); engine.compare(control, test, listener, null); assertEquals(expectedDifference, listener.comparingWhat); - //resetListener(); - //engine.compare(test, control, listener, null); - //assertEquals(expectedDifference, listener.comparingWhat); + resetListener(); + engine.compare(test, control, listener, null); + assertEquals(expectedDifference, listener.comparingWhat); } public void testDifferentSchemaLocation() throws Exception { @@ -831,6 +831,15 @@ assertEquals(expectedDifference, listener.comparingWhat); } + public void testMissingAttribute() throws Exception { + Element control = document.createElement("foo"); + control.setAttribute("bar", "baz"); + Element test = document.createElement("foo"); + test.setAttribute("baz", "bar"); + engine.compare(control, test, listener, null); + assertEquals(ATTR_NAME_NOT_FOUND_ID, listener.comparingWhat); + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { Document controlDoc = XMLUnit.buildControlDocument(control); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |