From: <bo...@us...> - 2013-02-01 16:30:10
|
Revision: 499 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=499&view=rev Author: bodewig Date: 2013-02-01 16:30:03 +0000 (Fri, 01 Feb 2013) Log Message: ----------- partial fix for comparison of XSI type attribute values. See Bug 3602981 Modified Paths: -------------- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLConstants.java branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java Property Changed: ---------------- branches/xmlunit-1.x/ Property changes on: branches/xmlunit-1.x ___________________________________________________________________ Added: svn:ignore + build Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2011-11-02 07:59:58 UTC (rev 498) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2013-02-01 16:30:03 UTC (rev 499) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2009, Jeff Martin, Tim Bacon +Copyright (c) 2001-2013, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -704,6 +704,18 @@ } /** + * @param attr + * @return true if the attribute is an XML Schema Instance + * namespace attribute XMLUnit treats in a special way. + */ + private boolean isXMLSchemaTypeAttribute(Attr attr) { + return XMLConstants + .W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(attr.getNamespaceURI()) + && XMLConstants.W3C_XML_SCHEMA_INSTANCE_TYPE_ATTR + .equals(attr.getLocalName()); + } + + /** * Compare two attributes * @param control * @param test @@ -717,15 +729,41 @@ compare(control.getPrefix(), test.getPrefix(), control, test, listener, NAMESPACE_PREFIX); - - compare(control.getValue(), test.getValue(), control, test, - listener, ATTR_VALUE); - + if (isXMLSchemaTypeAttribute(control) + && isXMLSchemaTypeAttribute(test)) { + compareXMLSchemaTypeAttributeValues(control, test, listener); + } else { + compare(control.getValue(), test.getValue(), 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); } + private void compareXMLSchemaTypeAttributeValues(Attr control, Attr test, + DifferenceListener listener) + throws DifferenceFoundException { + String controlValue = control.getValue(); + String testValue = test.getValue(); + + String controlLocal = controlValue; + String controlPrefix = ""; + String testLocal = testValue; + String testPrefix = ""; + int controlColon = controlValue.indexOf(":"); + if (controlColon > 0) { + controlLocal = controlValue.substring(controlColon); + controlPrefix = controlValue.substring(0, controlColon); + } + int testColon = testValue.indexOf(":"); + if (testColon > 0) { + testLocal = testValue.substring(testColon); + testPrefix = testValue.substring(0, testColon); + } + compare(controlLocal, testLocal, control, test, listener, ATTR_VALUE); + } + /** * Compare two CDATA sections - unused, kept for backwards compatibility * @param control Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLConstants.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLConstants.java 2011-11-02 07:59:58 UTC (rev 498) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/XMLConstants.java 2013-02-01 16:30:03 UTC (rev 499) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2007 Jeff Martin, Tim Bacon +Copyright (c) 2001-2013 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -157,4 +157,10 @@ */ String W3C_XML_SCHEMA_INSTANCE_NO_NAMESPACE_SCHEMA_LOCATION_ATTR = "noNamespaceSchemaLocation"; + + /** + * "type" + */ + public static final String W3C_XML_SCHEMA_INSTANCE_TYPE_ATTR + = "type"; } Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java 2011-11-02 07:59:58 UTC (rev 498) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java 2013-02-01 16:30:03 UTC (rev 499) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008, Jeff Martin, Tim Bacon +Copyright (c) 2001-2013, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -908,5 +908,34 @@ ElementNameAndAttributeQualifier()); assertTrue(diff.toString(), diff.similar()); } + + /** + * @see http://sourceforge.net/tracker/?func=detail&atid=377768&aid=3602981&group_id=23187 + */ + public void testXsiTypeSpecialCase() throws Exception { + String test = "<ns1:Square xsi:type=\"ns1:Shape\" " + + "xmlns:ns1=\"http://example.com/\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; + + String control = "<ns2:Square xsi:type=\"ns2:Shape\" " + + "xmlns:ns2=\"http://example.com/\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; + Diff diff = new Diff(control, test); + assertTrue(diff.toString(), diff.similar()); + } + + public void XtestXsiTypeSpecialCaseDoesntIgnorePrefix() throws Exception { + String test = "<ns1:Square xsi:type=\"ns1:Shape\" " + + "xmlns:ns1=\"http://example.com/\" " + + "xmlns:ns2=\"http://example.com/another-uri/\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; + + String control = "<ns1:Square xsi:type=\"ns2:Shape\" " + + "xmlns:ns1=\"http://example.com/\" " + + "xmlns:ns2=\"http://example.com/another-uri/\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; + Diff diff = new Diff(control, test); + assertFalse(diff.toString(), diff.similar()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |