You can subscribe to this list here.
2007 |
Jan
|
Feb
(3) |
Mar
(18) |
Apr
(39) |
May
(15) |
Jun
(12) |
Jul
(3) |
Aug
(23) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(21) |
Feb
(23) |
Mar
(33) |
Apr
(8) |
May
(1) |
Jun
(22) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(6) |
Nov
|
Dec
(11) |
2009 |
Jan
(5) |
Feb
|
Mar
(2) |
Apr
(24) |
May
(36) |
Jun
(18) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(3) |
Nov
(1) |
Dec
|
2010 |
Jan
(5) |
Feb
(3) |
Mar
|
Apr
(15) |
May
(24) |
Jun
(11) |
Jul
(8) |
Aug
(34) |
Sep
(42) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
(13) |
Feb
(32) |
Mar
(35) |
Apr
(31) |
May
(33) |
Jun
(30) |
Jul
(32) |
Aug
(31) |
Sep
(30) |
Oct
(31) |
Nov
(32) |
Dec
(31) |
2012 |
Jan
(35) |
Feb
(31) |
Mar
(31) |
Apr
(30) |
May
(31) |
Jun
(34) |
Jul
(23) |
Aug
(30) |
Sep
(30) |
Oct
(29) |
Nov
(30) |
Dec
(32) |
2013 |
Jan
(25) |
Feb
(39) |
Mar
(1) |
Apr
(18) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(20) |
Sep
(41) |
Oct
(32) |
Nov
(9) |
Dec
(31) |
2014 |
Jan
(31) |
Feb
(30) |
Mar
(34) |
Apr
(60) |
May
(31) |
Jun
(28) |
Jul
(32) |
Aug
(28) |
Sep
(26) |
Oct
(32) |
Nov
(43) |
Dec
(115) |
2015 |
Jan
(106) |
Feb
(101) |
Mar
(51) |
Apr
(32) |
May
(63) |
Jun
(18) |
Jul
|
Aug
(18) |
Sep
|
Oct
(1) |
Nov
(84) |
Dec
(63) |
2016 |
Jan
(26) |
Feb
(17) |
Mar
(104) |
Apr
(30) |
May
(6) |
Jun
(30) |
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(48) |
Dec
(22) |
2017 |
Jan
(15) |
Feb
(29) |
Mar
(43) |
Apr
(29) |
May
(25) |
Jun
(28) |
Jul
(62) |
Aug
(35) |
Sep
(35) |
Oct
(72) |
Nov
(10) |
Dec
(4) |
2018 |
Jan
(7) |
Feb
(4) |
Mar
|
Apr
(46) |
May
(20) |
Jun
(12) |
Jul
(9) |
Aug
(42) |
Sep
(4) |
Oct
(17) |
Nov
(32) |
Dec
(31) |
2019 |
Jan
(21) |
Feb
(14) |
Mar
|
Apr
(74) |
May
(25) |
Jun
(43) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(10) |
2020 |
Jan
(1) |
Feb
|
Mar
(26) |
Apr
(8) |
May
(62) |
Jun
(4) |
Jul
(25) |
Aug
|
Sep
(21) |
Oct
(24) |
Nov
(26) |
Dec
(9) |
2021 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(11) |
Nov
(1) |
Dec
(12) |
2022 |
Jan
(47) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(14) |
2023 |
Jan
(3) |
Feb
|
Mar
(60) |
Apr
(9) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
(5) |
Feb
|
Mar
|
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
(17) |
Sep
(2) |
Oct
|
Nov
|
Dec
(1) |
2025 |
Jan
|
Feb
|
Mar
(88) |
Apr
(64) |
May
(47) |
Jun
(20) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: SourceForge.net <no...@so...> - 2008-03-27 10:22:08
|
Feature Requests item #1854284, was opened at 2007-12-19 18:43 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1854284&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: XMLUnit for Java Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Jesper Goertz (jgortz) Assigned to: Nobody/Anonymous (nobody) Summary: upgrade difference to irrecoverable Initial Comment: "By providing an implementation of the DifferenceListener interface you can decide for yourself which type of difference is significant in your context. You may “upgrade” differences in element order to irrecoverable ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-27 11:17 Message: Logged In: YES user_id=113148 Originator: NO fixed in trunk, documentation should follow soon http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=256 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1854284&group_id=23187 |
From: <bo...@us...> - 2008-03-26 20:59:58
|
Revision: 256 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=256&view=rev Author: bodewig Date: 2008-03-26 13:59:54 -0700 (Wed, 26 Mar 2008) Log Message: ----------- Make it possible to upgrade Differences from recoverable to non-recoverable Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2008-03-26 20:49:12 UTC (rev 255) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2008-03-26 20:59:54 UTC (rev 256) @@ -81,6 +81,9 @@ case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: difference.setRecoverable(true); break; + case RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: + difference.setRecoverable(false); + break; default: throw new IllegalArgumentException(returnValue + " is not a defined " Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2008-03-26 20:49:12 UTC (rev 255) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2008-03-26 20:59:54 UTC (rev 256) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -307,6 +307,10 @@ haltComparison = true; } break; + case RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: + identical = similar = false; + haltComparison = true; + break; default: throw new IllegalArgumentException(returnValue + " is not a defined DifferenceListener.RETURN_... value"); Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java 2008-03-26 20:49:12 UTC (rev 255) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java 2008-03-26 20:59:54 UTC (rev 256) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -62,6 +62,12 @@ * interpreted as being similar. */ int RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR = 2; + /** + * Override return value for the <code>differenceFound</code> method. + * Indicates that the nodes identified as being similar should be + * interpreted as being different. + */ + int RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT = 3; /** * Receive notification that 2 nodes are different. * @param difference a Difference instance as defined in {@link Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 20:49:12 UTC (rev 255) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 20:59:54 UTC (rev 256) @@ -744,4 +744,24 @@ } } + public void testUpgradingOfRecoverableDifference() throws Exception { + String control = "<foo:bar xmlns:foo='urn:foo'/>"; + String test = "<bar xmlns='urn:foo'/>"; + Diff diff = buildDiff(control, test); + assertFalse(diff.toString(), diff.identical()); + assertTrue(diff.toString(), diff.similar()); + + diff = buildDiff(control, test); + diff.overrideDifferenceListener(new DifferenceListener() { + public int differenceFound(Difference d) { + return RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT; + } + public void skippedComparison(Node c, Node t) { + fail("skippedComparison shouldn't get invoked"); + } + }); + + assertFalse(diff.toString(), diff.identical()); + assertFalse(diff.toString(), diff.similar()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-26 20:49:38
|
Revision: 255 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=255&view=rev Author: bodewig Date: 2008-03-26 13:49:12 -0700 (Wed, 26 Mar 2008) Log Message: ----------- Test DetailedDiff in subclass Modified Paths: -------------- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 05:02:03 UTC (rev 254) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 20:49:12 UTC (rev 255) @@ -721,7 +721,7 @@ + "</env:Envelope>"; XMLUnit.setIgnoreWhitespace(true); try { - Diff diff = XMLUnit.compareXML(control, test); + Diff diff = buildDiff(control, test); assertTrue(diff.toString(), diff.identical()); } finally { XMLUnit.setIgnoreWhitespace(false); @@ -737,10 +737,11 @@ String test = "<a>\r\n <b/>\r\n</a>"; XMLUnit.setIgnoreWhitespace(true); try { - Diff diff = XMLUnit.compareXML(control, test); + Diff diff = buildDiff(control, test); assertTrue(diff.toString(), diff.identical()); } finally { XMLUnit.setIgnoreWhitespace(false); } } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-26 05:02:08
|
Revision: 254 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=254&view=rev Author: bodewig Date: 2008-03-25 22:02:03 -0700 (Tue, 25 Mar 2008) Log Message: ----------- normalizeWhitespace trims text and this is by design Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-03-26 04:33:47 UTC (rev 253) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-03-26 05:02:03 UTC (rev 254) @@ -736,7 +736,8 @@ * * <p>Normalized in this context means that all whitespace is * replaced by the space character and adjacent whitespace - * characters are collapsed to a single space character.</p> + * characters are collapsed to a single space character. It will + * also trim the resulting character content on both ends.</p> * * <p>The default value is false.</p> * Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 04:33:47 UTC (rev 253) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-26 05:02:03 UTC (rev 254) @@ -671,7 +671,7 @@ public void testNormalizedWhitespace() throws Exception { String xml1 = "<foo>a = b;</foo>"; - String xml2 = "<foo>\r\n\ta = b; \r\n</foo>"; + String xml2 = "<foo>\r\n\ta =\tb; \r\n</foo>"; try { assertFalse(buildDiff(xml1, xml2).identical()); assertFalse(buildDiff(xml1, xml2).similar()); @@ -743,21 +743,4 @@ XMLUnit.setIgnoreWhitespace(false); } } - - /** - * @see https://sourceforge.net/forum/message.php?msg_id=4843316 - */ - public void XtestNormalizeWhiteSpaceDoesntStripLeadingSpace() - throws Exception { - String control = "<name>value</name>"; - String test = "<name> value</name>"; - XMLUnit.setNormalizeWhitespace(true); - try { - Diff diff = XMLUnit.compareXML(control, test); - assertFalse(diff.toString(), diff.similar()); - } finally { - XMLUnit.setNormalizeWhitespace(false); - } - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-26 04:57:04
|
Bugs item #1917796, was opened at 2008-03-18 06:08 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1917796&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: Java 1.1 >Status: Closed >Resolution: Wont Fix Priority: 5 Private: No Submitted By: Stefan Bodewig (bodewig) Assigned to: Stefan Bodewig (bodewig) Summary: setNormalizeWhitespace strips leading spaces Initial Comment: http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=251 ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-26 05:57 Message: Logged In: YES user_id=113148 Originator: YES Actually this is not a bug but the intended behavior, see http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#Comparing:%20Configuration "It will also trim the resulting character content on both ends." ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1917796&group_id=23187 |
From: <bo...@us...> - 2008-03-26 04:33:44
|
Revision: 253 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=253&view=rev Author: bodewig Date: 2008-03-25 21:33:47 -0700 (Tue, 25 Mar 2008) Log Message: ----------- document new examples Modified Paths: -------------- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-03-18 05:10:22 UTC (rev 252) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-03-26 04:33:47 UTC (rev 253) @@ -1865,8 +1865,8 @@ node 4 to test node 4.</para> </section> - <section id="MultiLevelElementNameAndTextQualifier"> - <title><literal>org.custommonkey.xmlunit.examples.MultiLevelElementNameAndTextQualifier</literal></title> + <section id="RecursiveElementNameAndTextQualifier"> + <title><literal>org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier</literal></title> <para>All <literal>ElementQualifier</literal>s seen so far only looked at the <literal>Element</literal>s themselves and @@ -1878,7 +1878,7 @@ <example id="htmltable"> <title>Example for - <literal>MultiLevelElementNameAndTextQualifier</literal> + <literal>RecursiveElementNameAndTextQualifier</literal> (the comments are not part of the example)</title> <programlisting language="HTML"><![CDATA[ <!-- control --> @@ -1914,29 +1914,58 @@ <literal>ElementQualifier</literal> that looks at the element's name, as well as the name of the first child element and the text nested into that first child element. This is what - <literal>MultiLevelElementNameAndTextQualifier</literal> does. - <literal>MultiLevelElementNameAndTextQualifier</literal>'s - constructor expects a single argument which is the nesting - level of the expected text. If you use an argument of 1, - <literal>MultiLevelElementNameAndTextQualifier</literal> is - identical to <literal>ElementNameAndTextQualifier</literal>. - In <xref linkend="htmltable"/> a value of 2 would be - needed.</para> + <literal>RecursiveElementNameAndTextQualifier</literal> + does.</para> + <para><literal>RecursiveElementNameAndTextQualifier</literal> + ignores whitespace between the elements leading up to the + nested text.</para> + </section> + + <section id="MultiLevelElementNameAndTextQualifier"> + <title><literal>org.custommonkey.xmlunit.examples.MultiLevelElementNameAndTextQualifier</literal></title> + + <para> + <literal>MultiLevelElementNameAndTextQualifier</literal> has + in a way been the predecessor + of <xref linkend="RecursiveElementNameAndTextQualifier"><literal>RecursiveElementNameAndTextQualifier</literal></xref>. + It also matches element names and those of nested child + elements until it finds matches, but + unlike <literal>RecursiveElementNameAndTextQualifier</literal>, + you must + tell <literal>MultiLevelElementNameAndTextQualifier</literal> + at which nesting level it should expect the nested text. + </para> + + <para> + <literal>MultiLevelElementNameAndTextQualifier</literal>'s + constructor expects a single argument which is the nesting + level of the expected text. If you use an argument of 1, + <literal>MultiLevelElementNameAndTextQualifier</literal> is + identical to <literal>ElementNameAndTextQualifier</literal>. + In <xref linkend="htmltable"/> a value of 2 would be + needed.</para> + <para>By default - <literal>MultiLevelElementNameAndTextQualifier</literal> will - not ignore whitespace between the elements leading up to the - nested text. If your piece of XML contains this sort of - whitespace (like <xref linkend="htmltable"/> which contains a - newline and several space characters between - <literal><tr></literal> and - <literal><td></literal>) you can either instruct XMLUnit - to ignore whitespace completely (see + <literal>MultiLevelElementNameAndTextQualifier</literal> + will not ignore whitespace between the elements leading up + to the nested text. If your piece of XML contains this sort + of whitespace (like <xref linkend="htmltable"/> which + contains a newline and several space characters between + <literal><tr></literal> and + <literal><td></literal>) you can either instruct + XMLUnit to ignore whitespace completely (see <xref linkend="Whitespace Handling"/>) or use the two-arg - constructor of - <literal>MultiLevelElementNameAndTextQualifier</literal> - introduced with XMLUnit 1.2 and set the - <literal>ignoreEmptyTexts</literal> argument to true.</para> + constructor of + <literal>MultiLevelElementNameAndTextQualifier</literal> + introduced with XMLUnit 1.2 and set the + <literal>ignoreEmptyTexts</literal> argument to + true.</para> + + <para>In + general <literal>RecursiveElementNameAndTextQualifier</literal> + requires less knowledge upfront and its whitespace-handling + is more intuitive.</para> </section> </section> @@ -3336,6 +3365,27 @@ definitions written in RELAX NG or other schema languages in addition to W3C XML Schema. See <xref linkend="JAXP 1.3 Validation"/> for details.</listitem> + + <listitem>New examples have been added: + <itemizedlist> + <listitem><literal>RecursiveElementNameAndTextQualifier</literal> + - a more flexible <literal>ElementQualifier</literal> + that fills the same need as + <literal>MultiLevelElementNameAndTextQualifier</literal> + See + <xref linkend="RecursiveElementNameAndTextQualifier"/> + for more details.</listitem> + + <listitem><literal>CaseInsensitiveDifferenceListener</literal> + a - <literal>DifferenceListener</literal> that ignores + case when comparing texts.</listitem> + + <listitem><literal>FloatingPointTolerantDifferenceListener</literal> + a - <literal>DifferenceListener</literal> that tries + to parse texts as floting point numbers and compares + them using a configurable tolerance.</listitem> + </itemizedlist> + </listitem> </itemizedlist> </section> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-25 12:25:48
|
Bugs item #1902448, was opened at 2008-02-26 20:33 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1902448&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Duplicate Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Error in comparing doubles Initial Comment: When comparing elements of type xsd:double xmlunit does not see 3.14159265358979E0 and 3.14159265358979 as equivalent. ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-25 13:25 Message: Logged In: YES user_id=113148 Originator: NO https://sourceforge.net/tracker/index.php?func=detail&aid=1902394&group_id=23187&atid=377771 now, since I moved it from "bugs" to "feature requests" ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2008-03-24 17:17 Message: Logged In: NO https://sourceforge.net/tracker/index.php?func=detail&aid=1902394&group_id=23187&atid=377768 Yields the following error:Artifact: Invalid ArtifactID; this Tracker item may have moved to a different Tracker since this URL was generated ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-02-28 12:00 Message: Logged In: YES user_id=113148 Originator: NO https://sourceforge.net/tracker/index.php?func=detail&aid=1902394&group_id=23187&atid=377768 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1902448&group_id=23187 |
From: SourceForge.net <no...@so...> - 2008-03-24 16:17:35
|
Bugs item #1902448, was opened at 2008-02-26 11:33 Message generated for change (Comment added) made by nobody You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1902448&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Duplicate Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Error in comparing doubles Initial Comment: When comparing elements of type xsd:double xmlunit does not see 3.14159265358979E0 and 3.14159265358979 as equivalent. ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2008-03-24 09:17 Message: Logged In: NO https://sourceforge.net/tracker/index.php?func=detail&aid=1902394&group_id=23187&atid=377768 Yields the following error:Artifact: Invalid ArtifactID; this Tracker item may have moved to a different Tracker since this URL was generated ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-02-28 03:00 Message: Logged In: YES user_id=113148 Originator: NO https://sourceforge.net/tracker/index.php?func=detail&aid=1902394&group_id=23187&atid=377768 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1902448&group_id=23187 |
From: <bo...@us...> - 2008-03-18 05:10:18
|
Revision: 252 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=252&view=rev Author: bodewig Date: 2008-03-17 22:10:22 -0700 (Mon, 17 Mar 2008) Log Message: ----------- disable failing test Modified Paths: -------------- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-18 05:02:30 UTC (rev 251) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-18 05:10:22 UTC (rev 252) @@ -747,7 +747,7 @@ /** * @see https://sourceforge.net/forum/message.php?msg_id=4843316 */ - public void testNormalizeWhiteSpaceDoesntStripLeadingSpace() + public void XtestNormalizeWhiteSpaceDoesntStripLeadingSpace() throws Exception { String control = "<name>value</name>"; String test = "<name> value</name>"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-18 05:08:46
|
Bugs item #1917796, was opened at 2008-03-18 06:08 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1917796&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: Java 1.1 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Stefan Bodewig (bodewig) Assigned to: Stefan Bodewig (bodewig) Summary: setNormalizeWhitespace strips leading spaces Initial Comment: http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=251 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1917796&group_id=23187 |
From: <bo...@us...> - 2008-03-18 05:02:28
|
Revision: 251 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=251&view=rev Author: bodewig Date: 2008-03-17 22:02:30 -0700 (Mon, 17 Mar 2008) Log Message: ----------- Add test for forum thread 1973067 Modified Paths: -------------- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-14 15:48:26 UTC (rev 250) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java 2008-03-18 05:02:30 UTC (rev 251) @@ -744,4 +744,20 @@ } } + /** + * @see https://sourceforge.net/forum/message.php?msg_id=4843316 + */ + public void testNormalizeWhiteSpaceDoesntStripLeadingSpace() + throws Exception { + String control = "<name>value</name>"; + String test = "<name> value</name>"; + XMLUnit.setNormalizeWhitespace(true); + try { + Diff diff = XMLUnit.compareXML(control, test); + assertFalse(diff.toString(), diff.similar()); + } finally { + XMLUnit.setNormalizeWhitespace(false); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-14 15:50:29
|
Feature Requests item #1878549, was opened at 2008-01-23 23:50 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1878549&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: XMLUnit for Java Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Frank Callahan (fcallahan) Assigned to: Nobody/Anonymous (nobody) Summary: recursive ElementQualifier implementation Initial Comment: An implementation of the ElementQualifier interface is needed that can match comparable control and test nodes at arbitrary levels of nesting. While working on an automated regression tool, I found that MultiLevelElementNameAndTextQualifier could not correctly match comparable nodes in deeply nested and complex SOAP response messages. The data contents of these nodes were identical, but they occurred in different orders. Also, MultiLevelElementNameAndTextQualifier requires that the number of levels to explore in each candidate comparable pair be specified in advance of running a comparison. QA testers using the tool would have to enter a number as their best quess of how deep to look, a requirement that would make the tool less useful to them. To solve this problem, I wrote a recursive implementation of ElementQualifier that is able to find all the comparable nodes in a control and test SOAP response message. Probably there are other XMLUnit users who have had to write something similar, so it might be a good idea to include a recursive ElementQualifier in the XMLUnit examples package. The Open Source Review Board at my company, Fidelity Investments, has approved making this originally proprietary code available as a potential contribution to XMLUnit, so please consider adding it to the examples package, making any changes that would make it more consistent with your code standards. It does work fine "as is" though. Anyhow, the code for the RecursiveElementNameAndTextQualifier is pasted in below, so anyone who wants to is welcome to try it. Also, it's in an attached file. /** Based on XMLUnit example MultiLevelElementNameAndTextQualifier. Frank Callahan */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.custommonkey.xmlunit.ElementNameQualifier; import org.custommonkey.xmlunit.ElementQualifier; /** * Compares all Element and Text nodes in two pieces of XML. Allows elements of * complex, deeply nested types that are returned in different orders but have * the same content to be recognized as comparable. */ public class RecursiveElementNameAndTextQualifier implements ElementQualifier { private static final ElementNameQualifier NAME_QUALIFIER = new ElementNameQualifier(); /** * Uses element names and the text nested an arbitrary level of child * elements deeper into the element to compare elements. Checks all nodes, * not just first child element. * * <p> * Does not ignore empty text nodes. */ public RecursiveElementNameAndTextQualifier() { } /** * Returns result of recursive comparison of all the nodes of a control and * test element. * */ public boolean qualifyForComparison(Element currentControl, Element currentTest) { return compareNodes(currentControl, currentTest); } private boolean compareNodes(Node currentControl, Node currentTest) { try { // if they are elements, compare names of the two nodes if (!NAME_QUALIFIER.qualifyForComparison((Element) currentControl, (Element) currentTest)) { return false; } // Compare the control and test elements' children NodeList controlNodes = null; NodeList testNodes = null; // Check that both nodes have children and, if so, get lists of them if (currentControl.hasChildNodes() && currentTest.hasChildNodes()) { controlNodes = currentControl.getChildNodes(); testNodes = currentTest.getChildNodes(); } else if (currentControl.hasChildNodes() || currentTest.hasChildNodes()) { return false; // if both nodes are empty, they are comparable } else { return true; } // check that both node lists have the same length if (controlNodes.getLength() != testNodes.getLength()) { return false; } // Do checks of test and control nodes' children int nNodes = controlNodes.getLength(); for (int i = 0; i < nNodes; i++) { Node testNode = testNodes.item(i); Node controlNode = controlNodes.item(i); // check if both node are same type if (controlNode.getNodeType() != testNode.getNodeType()) { return false; } // compare text nodes if (controlNode.getNodeType() == Node.TEXT_NODE) { // compare concatenated, trimmed text nodes if (!catText(controlNode).equals(catText(testNode))) { return false; } // recursive check of current child control and test nodes' // children } else if (!compareNodes((Element) controlNode, (Element) testNode)) { return false; } } // All descendants of current control and test nodes are comparable return true; } catch (Exception e) { return false; } } /** * Concatenates contiguous Text nodes and removes all leading and trailing whitespace. * @param textNode * @return */ private String catText(Node textNode) { assert (textNode.getNodeType() == Node.TEXT_NODE); StringBuffer text = new StringBuffer(); Node next = textNode; do { if (next.getNodeValue() != null) { text.append(next.getNodeValue().trim()); next = next.getNextSibling(); } } while (next != null && next.getNodeType() == Node.TEXT_NODE); return text.toString(); } } ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-14 16:50 Message: Logged In: YES user_id=113148 Originator: NO I committed a slightly modified version that properly deals with adjacent text nodes (testMultipleTextValues failed with your implementation). http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=250 Thanks ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1878549&group_id=23187 |
From: <bo...@us...> - 2008-03-14 15:48:30
|
Revision: 250 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=250&view=rev Author: bodewig Date: 2008-03-14 08:48:26 -0700 (Fri, 14 Mar 2008) Log Message: ----------- Add RecursiveElementNameAndTextQualifier contributed by Frank Callahan; Issue 1878549 Added Paths: ----------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/RecursiveElementNameAndTextQualifier.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_RecursiveElementNameAndTextQualifier.java Added: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/RecursiveElementNameAndTextQualifier.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/RecursiveElementNameAndTextQualifier.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/RecursiveElementNameAndTextQualifier.java 2008-03-14 15:48:26 UTC (rev 250) @@ -0,0 +1,198 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.examples; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.custommonkey.xmlunit.ElementNameQualifier; +import org.custommonkey.xmlunit.ElementQualifier; + +/** + * Compares all Element and Text nodes in two pieces of XML. Allows elements of + * complex, deeply nested types that are returned in different orders but have + * the same content to be recognized as comparable. + * + * @author Frank Callahan + */ +public class RecursiveElementNameAndTextQualifier implements ElementQualifier { + + private static final ElementNameQualifier NAME_QUALIFIER = + new ElementNameQualifier(); + + /** + * Uses element names and the text nested an arbitrary level of + * child elements deeper into the element to compare + * elements. Checks all nodes, not just first child element. + * + * <p> Does not ignore empty text nodes. + */ + public RecursiveElementNameAndTextQualifier() { + } + + /** + * Returns result of recursive comparison of all the nodes of a + * control and test element. + */ + public boolean qualifyForComparison(Element currentControl, + Element currentTest) { + return compareNodes(currentControl, currentTest); + } + + private boolean compareNodes(Node currentControl, Node currentTest) { + try { + + // if they are elements, compare names of the two nodes + if (!NAME_QUALIFIER.qualifyForComparison((Element) currentControl, + (Element) currentTest)) { + return false; + } + + // Compare the control and test elements' children + + NodeList controlNodes = null; + NodeList testNodes = null; + + // Check that both nodes have children and, if so, get lists of them + + if (currentControl.hasChildNodes() && currentTest.hasChildNodes()) { + controlNodes = currentControl.getChildNodes(); + testNodes = currentTest.getChildNodes(); + } else if (currentControl.hasChildNodes() + || currentTest.hasChildNodes()) { + return false; + + // if both nodes are empty, they are comparable + } else { + return true; + } + + // check that both node lists have the same length + + if (countNodesWithoutConsecutiveTextNodes(controlNodes) + != countNodesWithoutConsecutiveTextNodes(testNodes)) { + return false; + } + + // Do checks of test and control nodes' children + + final int cNodes = controlNodes.getLength(); + final int tNodes = testNodes.getLength(); + + int i, j; + for (i = j = 0; i < cNodes && j < tNodes; i++, j++) { + Node testNode = testNodes.item(i); + Node controlNode = controlNodes.item(j); + + // check if both node are same type + if (controlNode.getNodeType() != testNode.getNodeType()) { + return false; + } + // compare text nodes + if (controlNode.getNodeType() == Node.TEXT_NODE) { + // compare concatenated, trimmed text nodes + if (!catText(controlNode).equals(catText(testNode))) { + return false; + } + + // swallow adjacent Text nodes + for (; i < cNodes - 1 + && controlNodes.item(i + 1).getNodeType() == Node.TEXT_NODE; + i++); + for (; j < tNodes - 1 + && testNodes.item(j + 1).getNodeType() == Node.TEXT_NODE; + j++); + + // recursive check of current child control and test nodes' + // children + + } else if (!compareNodes((Element) controlNode, + (Element) testNode)) { + return false; + } + } + if (i != cNodes || j != tNodes) { + return false; + } + + // All descendants of current control and test nodes are comparable + return true; + } catch (Exception e) { + return false; + } + } + /** + * Concatenates contiguous Text nodes and removes all leading and + * trailing whitespace. + * @param textNode + * @return + */ + private static String catText(Node textNode) { + StringBuffer text = new StringBuffer(); + Node next = textNode; + + do { + if (next.getNodeValue() != null) { + text.append(next.getNodeValue().trim()); + next = next.getNextSibling(); + } + } while (next != null && next.getNodeType() == Node.TEXT_NODE); + + return text.toString(); + } + + /** + * Calculates the number of Nodes that are either not Text nodes + * or are Text nodes whose previous sibling isn't a Text node as + * well. I.e. consecutive Text nodes are counted as a single + * node. + */ + private static int countNodesWithoutConsecutiveTextNodes(NodeList l) { + int count = 0; + boolean lastNodeWasText = false; + final int length = l.getLength(); + for (int i = 0; i < length; i++) { + Node n = l.item(i); + if (!lastNodeWasText || n.getNodeType() != Node.TEXT_NODE) { + count++; + } + lastNodeWasText = n.getNodeType() == Node.TEXT_NODE; + } + return count; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/RecursiveElementNameAndTextQualifier.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_RecursiveElementNameAndTextQualifier.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_RecursiveElementNameAndTextQualifier.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_RecursiveElementNameAndTextQualifier.java 2008-03-14 15:48:26 UTC (rev 250) @@ -0,0 +1,173 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.examples; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.ElementNameAndTextQualifier; +import org.custommonkey.xmlunit.ElementQualifier; +import org.custommonkey.xmlunit.XMLUnit; + +/** + * JUnit testcase for RecursiveElementNameAndTextQualifier with most + * tests copied from MultiLevelElementNameAndTextQualifier' test. + * @see test_Diff#testRepeatedElementNamesWithTextQualification() + */ +public class test_RecursiveElementNameAndTextQualifier extends TestCase { + private static final String TAG_NAME = "tagYoureIt"; + private static final String TAG_NAME2 = "tagYoureIt2"; + private static final String TEXT_A = "textA"; + private static final String TEXT_B = "textB"; + private Document document; + + // copy of ElementNameAndTextQualifier test + public void testSingleTextValue() throws Exception { + ElementQualifier qualifier = + new RecursiveElementNameAndTextQualifier(); + + Element control = document.createElement(TAG_NAME); + control.appendChild(document.createTextNode(TEXT_A)); + + Element test = document.createElement(TAG_NAME); + + assertFalse("control text not comparable to empty text", + qualifier.qualifyForComparison(control, test)); + + test.appendChild(document.createTextNode(TEXT_A)); + assertTrue("control textA comparable to test textA", + qualifier.qualifyForComparison(control, test)); + + test = document.createElement(TAG_NAME); + + test.appendChild(document.createTextNode(TEXT_B)); + assertFalse("control textA not comparable to test textB", + qualifier.qualifyForComparison(control, test)); + } + + // copy of ElementNameAndTextQualifier test + public void testMultipleTextValues() throws Exception { + ElementQualifier qualifier = + new RecursiveElementNameAndTextQualifier(); + + Element control = document.createElement(TAG_NAME); + control.appendChild(document.createTextNode(TEXT_A)); + control.appendChild(document.createTextNode(TEXT_B)); + + Element test = document.createElement(TAG_NAME); + test.appendChild(document.createTextNode(TEXT_A + TEXT_B)); + assertTrue("denormalised control text comparable to normalised test text", + qualifier.qualifyForComparison(control, test)); + } + + // three levels + public void testThreeLevels() throws Exception { + ElementQualifier qualifier = + new RecursiveElementNameAndTextQualifier(); + + Element control = document.createElement(TAG_NAME); + Element child = document.createElement(TAG_NAME2); + control.appendChild(child); + Element child2 = document.createElement(TAG_NAME); + child.appendChild(child2); + child2.appendChild(document.createTextNode(TEXT_B)); + + Element test = document.createElement(TAG_NAME); + child = document.createElement(TAG_NAME2); + test.appendChild(child); + child2 = document.createElement(TAG_NAME); + child.appendChild(child2); + child2.appendChild(document.createTextNode(TEXT_B)); + + assertTrue(qualifier.qualifyForComparison(control, test)); + } + + /** + * @see https://sourceforge.net/forum/forum.php?thread_id=1440169&forum_id=73274 + */ + public void testThread1440169() throws Exception { + String s1 = "<a><b><c>foo</c></b><b><c>bar</c></b></a>"; + String s2 = "<a><b><c>bar</c></b><b><c>foo</c></b></a>"; + Diff d = new Diff(s1, s2); + assertFalse(d.similar()); + + // reset + d = new Diff(s1, s2); + d.overrideElementQualifier(new ElementNameAndTextQualifier()); + assertFalse(d.similar()); + + // reset once again + d = new Diff(s1, s2); + d.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); + assertTrue(d.similar()); + + } + + public void testUserGuideExample() throws Exception { + String control = + "<table>\n" + + " <tr>\n" + + " <td>foo</td>\n" + + " </tr>\n" + + " <tr>\n" + + " <td>bar</td>\n" + + " </tr>\n" + + "</table>\n"; + String test = + "<table>\n" + + " <tr>\n" + + " <td>bar</td>\n" + + " </tr>\n" + + " <tr>\n" + + " <td>foo</td>\n" + + " </tr>\n" + + "</table>\n"; + + Diff d = new Diff(control, test); + d.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); + assertTrue(d.toString(), d.similar()); + } + + public void setUp() throws Exception { + document = XMLUnit.newControlParser().newDocument(); + } + +} Property changes on: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_RecursiveElementNameAndTextQualifier.java ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-14 02:20:16
|
Feature Requests item #1902394, was opened at 2008-02-26 10:14 Message generated for change (Comment added) made by sf-robot You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1902394&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed Resolution: Duplicate Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Error in comparing doubles Initial Comment: When comparing elements of type xsd:double xmlunit does not see 3.14159265358979E0 and 3.14159265358979 as equivalent. ---------------------------------------------------------------------- >Comment By: SourceForge Robot (sf-robot) Date: 2008-03-13 19:20 Message: Logged In: YES user_id=1312539 Originator: NO This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker). ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-02-28 03:42 Message: Logged In: YES user_id=113148 Originator: NO XMLUnit doesn't recognize Schema types at all, so it certainly doesn't do any other sort of comparison than a string match. There is an enhancement request https://sourceforge.net/tracker/index.php?func=detail&aid=1762410&group_id=23187&atid=377771 that would address this, I'm marking this as a duplicate of it. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1902394&group_id=23187 |
From: SourceForge.net <no...@so...> - 2008-03-14 02:20:15
|
Bugs item #1875554, was opened at 2008-01-19 15:43 Message generated for change (Comment added) made by sf-robot You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1875554&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed Resolution: Works For Me Priority: 5 Private: No Submitted By: Petteri Räty (betelgeus) Assigned to: Nobody/Anonymous (nobody) Summary: testURIResolverForStylesheet fails with JDK >=1.5 Initial Comment: [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.004 sec [junit] Running org.custommonkey.xmlunit.test_SimpleXpathEngine testURIResolverForStylesheet Failure should fail because of unknown include URI junit.framework.AssertionFailedError: should fail because of unknown include URI at org.custommonkey.xmlunit.test_Transform.testURIResolverForStylesheet(test_Transform.java:137) 0.015 happens with 1.5 and 1.6. Doesn't matter whether I use the XSLT implementation from the JDK or Xalan 2.7 ---------------------------------------------------------------------- >Comment By: SourceForge Robot (sf-robot) Date: 2008-03-13 19:20 Message: Logged In: YES user_id=1312539 Originator: NO This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker). ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-02-28 03:39 Message: Logged In: YES user_id=113148 Originator: NO strange, it passes for me on JDK 1.6 as well as Apache Gump running Java 5 http://vmgump.apache.org/gump/public/xmlunit/xmlunit/gump_work/build_xmlunit_xmlunit.html or Java 6 http://gump.zones.apache.org/gump/test/xmlunit/xmlunit/gump_work/build_xmlunit_xmlunit.html ---------------------------------------------------------------------- Comment By: Petteri Räty (betelgeus) Date: 2008-01-19 15:44 Message: Logged In: YES user_id=924568 Originator: YES [junit] Tests run: 8, Failures: 1, Errors: 0, Time elapsed: 0.209 sec [junit] TEST org.custommonkey.xmlunit.test_Transform FAILED Wrong line pasted ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1875554&group_id=23187 |
From: SourceForge.net <no...@so...> - 2008-03-13 17:10:52
|
Feature Requests item #1762410, was opened at 2007-07-27 22:55 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1762410&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: XMLUnit for Java Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Ken Estes (kestesisme) Assigned to: Nobody/Anonymous (nobody) Summary: use tolerance for floating point values in XML Initial Comment: We produce XML which has numerical values scattered through out the XML both in nodes and attributes. <svg xmlns="http://www.w3.org/2000/svg" width="0.085in" height="0.085in"> <text text-anchor="end" y="92" x="15">36</text> <fo:block-container height="2pc" width="46.5pc" left="2.5pc" top="64pc"> The numerical values can be produced by computations which are carried out in software or hardware. Because of round off errors we need to have a custom string equals function which will allow for round off in the numeric portions of the string. Enclosed please find a file which will perform such numeric comparisons. Here is my suggestion for how to hook it into XMLUnit. /** * Test two non-null values for inequality * @param expected * @param actual * @return TRUE if the values are not equals() equal (taking whitespace * into account if necessary) */ private boolean unequalNotNull(Object expected, Object actual) { boolean bothStrings = (expected instanceof String && actual instanceof String); if (!bothStrings) { return !(expected.equals(actual)); } String expectedString = (String) expected; String actualString = (String) actual; if (XMLUnit.getIgnoreWhitespace()) { expectedString = expected.trim(); actualString = actual.trim(); } if (XMLUnit.getNormalizeWhitespace()) { expectedString = normalizeWhitespace(expectedString); actualString = normalizeWhitespace(actualString); } if (XMLUnit.getTolerantNumericCompare) { return !StringCmpNumericTolerance.equals(expected,actualString); } return !expectedString.equals(actualString); } ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-13 18:10 Message: Logged In: YES user_id=113148 Originator: NO Like I said, this can be done using a DifferenceListener. A simplisitic one (for usage see its unit test) is now part of the examples package. http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=249 ---------------------------------------------------------------------- Comment By: Ken Estes (kestesisme) Date: 2008-01-28 19:06 Message: Logged In: YES user_id=1855117 Originator: YES It would be simplest for my case to wrap the standard DifferenceEngine with another class, because what I wish to change is the method unequalNotNull(Object expected, Object actual) in this class. However this is difficult with the current code structure. 1) The DifferenceEngine class has methods which are private/final and this makes extending the object diffcult 2) it is not clear how to pass my new class into the Diff(,) object to be used instead of the normal differenceEngine. I was hoping to use the diff constructor Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator) But this is a tangle of dependencies. My DifferenceEngine needs to be constructed first, so that I could pass it into the Diff. However to construct my class I need to pass in the Diff (this is the only class which implements ComparisonController) that it will be used for as a parameter. I suggest that you should separate the implementations of DifferenceListener, ComparisonController and not keep diff as an implementation of both since the dependency issues for both are quite separate. And Worse there is no setDifferenceEngine() method for Diff() so that I could create my own DifferenceEngine after the diff was constructed (and pass in the already constructed diff as a parameter) then override the default difference engine with what I just created. In sort overriding the DifferenceEngine class is quite difficult. ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-01-04 11:38 Message: Logged In: YES user_id=113148 Originator: NO Hi Ken, to be honest I feel we would be stretching XMLUnit quite a bit if we added special purpose options like handling of numeric values to its core. The same could be said for case insensitive comparisons of element and attribute names (HTML as a use-case) or texts and so on. It should be possible to use a DifferenceListener of your own that wrapped whatever DifferenceListener would get used normally and performed some special sort of comparision for ATTR_VALUE Differences. We might even add such a DifferenceListener in XMLUnit's examples package. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1762410&group_id=23187 |
From: <bo...@us...> - 2008-03-13 17:08:49
|
Revision: 249 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=249&view=rev Author: bodewig Date: 2008-03-13 10:08:43 -0700 (Thu, 13 Mar 2008) Log Message: ----------- Add a simplistic DifferenceListener that uses a tolerance when comparing numbers Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java Added Paths: ----------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/FloatingPointTolerantDifferenceListener.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_FloatingPointTolerantDifferenceListener.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java 2008-03-12 16:57:59 UTC (rev 248) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java 2008-03-13 17:08:43 UTC (rev 249) @@ -60,6 +60,7 @@ DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } } - return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; + // some string is null, delegate + return super.textualDifference(d); } } \ No newline at end of file Added: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/FloatingPointTolerantDifferenceListener.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/FloatingPointTolerantDifferenceListener.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/FloatingPointTolerantDifferenceListener.java 2008-03-13 17:08:43 UTC (rev 249) @@ -0,0 +1,73 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceListener; + +/** + * Expects texts to be floating point numbers and treats them as + * identical if they only differ by a given tolerance value (or less). + */ +public class FloatingPointTolerantDifferenceListener + extends TextDifferenceListenerBase { + + private final double tolerance; + + public FloatingPointTolerantDifferenceListener(DifferenceListener delegateTo, + double tolerance) { + super(delegateTo); + this.tolerance = tolerance; + } + + protected int textualDifference(Difference d) { + String control = d.getControlNodeDetail().getValue(); + String test = d.getTestNodeDetail().getValue(); + if (control != null && test != null) { + try { + double controlVal = Double.parseDouble(control); + double testVal = Double.parseDouble(test); + return Math.abs(controlVal - testVal) < tolerance + ? DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL + : DifferenceListener.RETURN_ACCEPT_DIFFERENCE; + } catch (NumberFormatException nfe) { + // ignore, delegate to nested DifferenceListener + } + } + // no numbers or null, delegate + return super.textualDifference(d); + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/FloatingPointTolerantDifferenceListener.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java 2008-03-12 16:57:59 UTC (rev 248) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java 2008-03-13 17:08:43 UTC (rev 249) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2006-2008, Jeff Martin, Tim Bacon +Copyright (c) 2008, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Added: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_FloatingPointTolerantDifferenceListener.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_FloatingPointTolerantDifferenceListener.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_FloatingPointTolerantDifferenceListener.java 2008-03-13 17:08:43 UTC (rev 249) @@ -0,0 +1,84 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import java.util.Locale; +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceListener; +import org.w3c.dom.Node; + +public class test_FloatingPointTolerantDifferenceListener extends TestCase { + + public void testFloatingPointTolerance() throws Exception { + String control = "<foo value=\"2.718281828\"/>"; + String test = "<foo value=\"2.71\"/>"; + Diff d = new Diff(control, test); + + FloatingPointTolerantDifferenceListener c = + new FloatingPointTolerantDifferenceListener(new DifferenceListener() { + public int differenceFound(Difference d) { + fail("differenceFound shouldn't get invoked, but" + + " was with type " + d.getId()); + return -42; + } + public void skippedComparison(Node c, Node t) { + fail("skippedComparison shouldn't get invoked"); + } + }, 1e-2); + + d.overrideDifferenceListener(c); + assertTrue(d.identical()); + + c = new FloatingPointTolerantDifferenceListener(new DifferenceListener() { + public int differenceFound(Difference d) { + fail("differenceFound shouldn't get invoked, but" + + " was with type " + d.getId()); + return -42; + } + public void skippedComparison(Node c, Node t) { + fail("skippedComparison shouldn't get invoked"); + } + }, 1e-3); + + d = new Diff(control, test); + d.overrideDifferenceListener(c); + assertFalse(d.identical()); + } + +} \ No newline at end of file Property changes on: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_FloatingPointTolerantDifferenceListener.java ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-12 16:57:54
|
Revision: 248 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=248&view=rev Author: bodewig Date: 2008-03-12 09:57:59 -0700 (Wed, 12 Mar 2008) Log Message: ----------- Add simplistic DifferenceListener that ignores case Added Paths: ----------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CaseInsensitiveDifferenceListener.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_TextDifferenceListenerBase.java Added: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java 2008-03-12 16:57:59 UTC (rev 248) @@ -0,0 +1,65 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import java.util.Locale; +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceListener; + +/** + * Ignores case for all textual content. + */ +public class CaseInsensitiveDifferenceListener + extends TextDifferenceListenerBase { + + public CaseInsensitiveDifferenceListener(DifferenceListener delegateTo) { + super(delegateTo); + } + + protected int textualDifference(Difference d) { + String control = d.getControlNodeDetail().getValue(); + if (control != null) { + control = control.toLowerCase(Locale.US); + if (d.getTestNodeDetail().getValue() != null + && control.equals(d.getTestNodeDetail().getValue() + .toLowerCase(Locale.US))) { + return + DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; + } + } + return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CaseInsensitiveDifferenceListener.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java 2008-03-12 16:57:59 UTC (rev 248) @@ -0,0 +1,124 @@ +/* +****************************************************************** +Copyright (c) 2006-2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceConstants; +import org.custommonkey.xmlunit.DifferenceListener; +import org.w3c.dom.Node; + +/** + * Base class that delegates all differences to another DifferenceListener. + * + * <p>Subclasses get a chance to hook into special methods that will + * be invoked for differences in textual values of attributes, CDATA + * sections, Text or comment nodes.</p> + */ +public abstract class TextDifferenceListenerBase + implements DifferenceListener { + + private final DifferenceListener delegateTo; + + protected TextDifferenceListenerBase(DifferenceListener delegateTo) { + this.delegateTo = delegateTo; + } + + /** + * Delegates to the nested DifferenceListener unless the + * Difference is of type {@link DifferenceConstants#ATTR_VALUE_ID + * ATTR_VALUE_ID}, {@link DifferenceConstants#CDATA_VALUE_ID + * CDATA_VALUE_ID}, {@link DifferenceConstants#COMMENT_VALUE_ID + * COMMENT_VALUE_ID} or {@link DifferenceConstants#TEXT_VALUE_ID + * TEXT_VALUE_ID} - for those special differences {@link + * #attributeDifference attributeDifference}, {@link + * #cdataDifference cdataDifference}, {@link #commentDifference + * commentDifference} or {@link #textDifference textDifference} + * are invoked respectively. + */ + public int differenceFound(Difference difference) { + switch (difference.getId()) { + case DifferenceConstants.ATTR_VALUE_ID: + return attributeDifference(difference); + case DifferenceConstants.CDATA_VALUE_ID: + return cdataDifference(difference); + case DifferenceConstants.COMMENT_VALUE_ID: + return commentDifference(difference); + case DifferenceConstants.TEXT_VALUE_ID: + return textDifference(difference); + } + return delegateTo.differenceFound(difference); + } + + /** + * Delegates to {@link #textualDifference textualDifference}. + */ + protected int attributeDifference(Difference d) { + return textualDifference(d); + } + + /** + * Delegates to {@link #textualDifference textualDifference}. + */ + protected int cdataDifference(Difference d) { + return textualDifference(d); + } + + /** + * Delegates to {@link #textualDifference textualDifference}. + */ + protected int commentDifference(Difference d) { + return textualDifference(d); + } + + /** + * Delegates to {@link #textualDifference textualDifference}. + */ + protected int textDifference(Difference d) { + return textualDifference(d); + } + + /** + * Delegates to the nested DifferenceListener. + */ + protected int textualDifference(Difference d) { + return delegateTo.differenceFound(d); + } + + public void skippedComparison(Node control, Node test) { + delegateTo.skippedComparison(control, test); + } + +} \ No newline at end of file Property changes on: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/TextDifferenceListenerBase.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CaseInsensitiveDifferenceListener.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CaseInsensitiveDifferenceListener.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CaseInsensitiveDifferenceListener.java 2008-03-12 16:57:59 UTC (rev 248) @@ -0,0 +1,83 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import java.util.Locale; +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceListener; +import org.w3c.dom.Node; + +public class test_CaseInsensitiveDifferenceListener extends TestCase { + + private static final String ATTR = "aTtr"; + private static final String CDATA = "C Data"; + private static final String CMMT = "a Comment"; + private static final String TEXT = "some Text"; + + public void testCaseInsensitive() throws Exception { + String control = getDoc(ATTR, CDATA, CMMT, TEXT); + String test = getDoc(ATTR.toUpperCase(Locale.US), + CDATA.toUpperCase(Locale.US), + CMMT.toUpperCase(Locale.US), + TEXT.toUpperCase(Locale.US)); + Diff d = new Diff(control, test); + + CaseInsensitiveDifferenceListener c = + new CaseInsensitiveDifferenceListener(new DifferenceListener() { + public int differenceFound(Difference d) { + fail("differenceFound shouldn't get invoked, but" + + " was with type " + d.getId()); + return -42; + } + public void skippedComparison(Node c, Node t) { + fail("skippedComparison shouldn't get invoked"); + } + }); + + d.overrideDifferenceListener(c); + assertTrue(d.identical()); + } + + private static String getDoc(String attr, String cdata, String comment, + String text) { + return "<root><first attr=\"" + attr + "\"/><!--" + comment + "-->" + + "<second><![CDATA[" + cdata + "]]></second><third>" + text + + "</third></root>"; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CaseInsensitiveDifferenceListener.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_TextDifferenceListenerBase.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_TextDifferenceListenerBase.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_TextDifferenceListenerBase.java 2008-03-12 16:57:59 UTC (rev 248) @@ -0,0 +1,151 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ +package org.custommonkey.xmlunit.examples; + +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceListener; +import org.w3c.dom.Node; + +public class test_TextDifferenceListenerBase extends TestCase { + private static final String C_ATTR = "controlAttr"; + private static final String T_ATTR = "testAttr"; + private static final String C_CDATA = "controlCdata"; + private static final String T_CDATA = "testCdata"; + private static final String C_CMMT = "controlComment"; + private static final String T_CMMT = "testComment"; + private static final String C_TEXT = "controlText"; + private static final String T_TEXT = "testText"; + + public void testTextDifferenceDelegations() throws Exception { + final int[] invocations = new int[4]; + + String control = getDoc(C_ATTR, C_CDATA, C_CMMT, C_TEXT); + String test = getDoc(T_ATTR, T_CDATA, T_CMMT, T_TEXT); + + TextDifferenceListenerBase b = new TextDifferenceListenerBase(null) { + protected int attributeDifference(Difference d) { + assertEquals(C_ATTR, d.getControlNodeDetail().getValue()); + assertEquals(T_ATTR, d.getTestNodeDetail().getValue()); + invocations[0]++; + return 1; + } + + protected int cdataDifference(Difference d) { + assertEquals(C_CDATA, d.getControlNodeDetail().getValue()); + assertEquals(T_CDATA, d.getTestNodeDetail().getValue()); + invocations[1]++; + return 1; + } + + protected int commentDifference(Difference d) { + assertEquals(C_CMMT, d.getControlNodeDetail().getValue()); + assertEquals(T_CMMT, d.getTestNodeDetail().getValue()); + invocations[2]++; + return 1; + } + + protected int textDifference(Difference d) { + assertEquals(C_TEXT, d.getControlNodeDetail().getValue()); + assertEquals(T_TEXT, d.getTestNodeDetail().getValue()); + invocations[3]++; + return 1; + } + }; + + Diff d = new Diff(control, test); + d.overrideDifferenceListener(b); + + assertTrue(d.identical()); + + for (int i = 0; i < invocations.length; i++) { + assertEquals(1, invocations[i]); + } + } + + public void testTextualDifference() throws Exception { + final int[] invocations = new int[1]; + + String control = getDoc(C_ATTR, C_CDATA, C_CMMT, C_TEXT); + String test = getDoc(T_ATTR, T_CDATA, T_CMMT, T_TEXT); + + TextDifferenceListenerBase b = new TextDifferenceListenerBase(null) { + protected int textualDifference(Difference d) { + invocations[0]++; + return 1; + } + }; + + Diff d = new Diff(control, test); + d.overrideDifferenceListener(b); + + assertTrue(d.identical()); + assertEquals(4, invocations[0]); + } + + public void testFullDelegation() throws Exception { + final int[] invocations = new int[1]; + + String control = getDoc(C_ATTR, C_CDATA, C_CMMT, C_TEXT); + String test = getDoc(T_ATTR, T_CDATA, T_CMMT, T_TEXT); + + TextDifferenceListenerBase b = + new TextDifferenceListenerBase(new DifferenceListener() { + public int differenceFound(Difference d) { + invocations[0]++; + return 1; + } + public void skippedComparison(Node c, Node t) { + fail("skippedComparison shouldn't get invoked"); + } + }) {}; + + Diff d = new Diff(control, test); + d.overrideDifferenceListener(b); + + assertTrue(d.identical()); + assertEquals(4, invocations[0]); + } + + private static String getDoc(String attr, String cdata, String comment, + String text) { + return "<root><first attr=\"" + attr + "\"/><!--" + comment + "-->" + + "<second><![CDATA[" + cdata + "]]></second><third>" + text + + "</third></root>"; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_TextDifferenceListenerBase.java ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-07 11:52:51
|
Revision: 247 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=247&view=rev Author: bodewig Date: 2008-03-07 03:51:51 -0800 (Fri, 07 Mar 2008) Log Message: ----------- some RELAX NG experiments Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java trunk/xmlunit/tests/etc/invalidBook.xml trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java Added Paths: ----------- trunk/xmlunit/tests/etc/Book.rng trunk/xmlunit/tests/etc/Book.rngc Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-07 04:56:39 UTC (rev 246) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-07 11:51:51 UTC (rev 247) @@ -50,10 +50,10 @@ /** * Validator class based of {@link javax.xml.validation javax.xml.validation}. * - * <p>This class currently only provides support for validating schema - * definitions. It defaults to the W3C XML Schema 1.0 but can be used - * to validate against any schema language supported by your - * SchemaFactory implementation.</p> + * <p>This class provides support for validating schema definitions as + * well as instance documents. It defaults to the W3C XML Schema 1.0 + * but can be used to validate against any schema language supported + * by your SchemaFactory implementation.</p> */ public class Validator { private final String schemaLanguage; @@ -122,7 +122,20 @@ try { parseSchema(new CollectingErrorHandler(l)); } catch (SAXException e) { - // error has been recorded in our ErrorHandler anyway + // error should have been recorded in our ErrorHandler, at + // least that's what the Javadocs say "SchemaFactory is + // not allowed to throw SAXException without first + // reporting it to ErrorHandler.". + // + // Unfortunately not all implementations seem to follow + // this rule. In particular using the setup described in + // org.custommonkey.xmlunit.jaxp13.test_Validator#XtestGoodRelaxNGCompactSyntaxIsValid() + // an exception ("SAXParseException: Content is not + // allowed in prolog.") will be thrown that never enters + // our Errorhandler. + if (l.size() == 0) { + l.add(e); + } } return l; } @@ -169,7 +182,11 @@ try { v.validate(instance); } catch (SAXException e) { - // error has been recorded in our ErrorHandler anyway + // error should have been recorded in our ErrorHandler, + // but better double-check. + if (l.size() == 0) { + l.add(e); + } } catch (java.io.IOException i) { throw new XMLUnitRuntimeException("Error reading instance source", i); Added: trunk/xmlunit/tests/etc/Book.rng =================================================================== --- trunk/xmlunit/tests/etc/Book.rng (rev 0) +++ trunk/xmlunit/tests/etc/Book.rng 2008-03-07 11:51:51 UTC (rev 247) @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<element name="Book" ns="http://www.publishing.org" + xmlns="http://relaxng.org/ns/structure/1.0"> + <element name="Title"><text/></element> + <oneOrMore> + <element name="Author"><text/></element> + </oneOrMore> + <element name="Date"><text/></element> + <element name="ISBN"><text/></element> + <element name="Publisher"><text/></element> +</element> Property changes on: trunk/xmlunit/tests/etc/Book.rng ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/etc/Book.rngc =================================================================== --- trunk/xmlunit/tests/etc/Book.rngc (rev 0) +++ trunk/xmlunit/tests/etc/Book.rngc 2008-03-07 11:51:51 UTC (rev 247) @@ -0,0 +1,9 @@ +namespace b = "http://www.publishing.org" + +element b:Book { + element b:Title { text }, + element b:Author { text }+, + element b:Date { text }, + element b:ISBN { text }, + element b:Publisher { text } +} Property changes on: trunk/xmlunit/tests/etc/Book.rngc ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/xmlunit/tests/etc/invalidBook.xml =================================================================== --- trunk/xmlunit/tests/etc/invalidBook.xml 2008-03-07 04:56:39 UTC (rev 246) +++ trunk/xmlunit/tests/etc/invalidBook.xml 2008-03-07 11:51:51 UTC (rev 247) @@ -1,8 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <Book xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" - xmlns="http://www.publishing.org" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.publishing.org tests/etc/Book.xsd"> + xmlns="http://www.publishing.org"> <Title>Chicken Soup for the Soul</Title> <Author>Jack Canfield</Author> <Author>Mark Victor Hansen</Author> Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-07 04:56:39 UTC (rev 246) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-07 11:51:51 UTC (rev 247) @@ -154,4 +154,76 @@ assertTrue(e.getCause() instanceof IOException); } } + + /** + * fails unless you manage to setup JAXP 1.3 and RELAX NG support + * + * <p>The setup that worked for Stefan when he wrote this test: + * JDK 1.5.0_09, isorelax-jaxp-bridge-1.0, together with msv.jar, + * isorelax.jar, relaxngDatatype.jar and xsdlib.jar from msv's + * latest nightly build (2008-02-13, actually). The same jars do + * not work with Java6.</p> + * + * @see http://weblogs.java.net/blog/kohsuke/archive/2006/02/validate_xml_us.html + */ + public void XtestGoodRelaxNGSchemaIsValid() throws Exception { + Validator v = new Validator(javax.xml.XMLConstants.RELAXNG_NS_URI); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.rng"))); + assertTrue(v.isSchemaValid()); + } + + /** + * fails unless you manage to setup JAXP 1.3 and RELAX NG support + * @see #XtestGoodRelaxNGSchemaIsValid() + */ + public void XtestGoodInstanceIsValidRNG() throws Exception { + Validator v = new Validator(javax.xml.XMLConstants.RELAXNG_NS_URI); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.rng"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/BookXsdGeneratedNoSchema.xml")); + assertTrue(v.isInstanceValid(s)); + } + + /** + * fails unless you manage to setup JAXP 1.3 and RELAX NG support + * @see #XtestGoodRelaxNGSchemaIsValid() + */ + public void XtestBadInstanceIsInvalidRNG() throws Exception { + Validator v = new Validator(javax.xml.XMLConstants.RELAXNG_NS_URI); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.rng"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/invalidBook.xml")); + List l = v.getInstanceErrors(s); + for (Iterator i = l.iterator(); i.hasNext(); ) { + Object ex = i.next(); + assertTrue(ex instanceof SAXParseException); + /* + System.err.println(ex); + */ + } + assertTrue(l.size() > 0); + } + + /** + * fails even using the setup in XtestGoodRelaxNGSchemaIsValid() + * since a SAXParser is trying to read the compact syntax + * definition and chokes on it not being XML. + * @see #XtestGoodRelaxNGSchemaIsValid() + */ + public void XtestGoodRelaxNGCompactSyntaxIsValid() throws Exception { + Validator v = new Validator(javax.xml.XMLConstants.RELAXNG_NS_URI); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.rngc"))); + assertTrue(v.isSchemaValid()); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/BookXsdGeneratedNoSchema.xml")); + assertTrue(v.isInstanceValid(s)); + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: SourceForge.net <no...@so...> - 2008-03-07 05:00:10
|
Feature Requests item #1728598, was opened at 2007-05-30 23:19 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1728598&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: XMLUnit for Java Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: KingArgyle (kingargyle1) Assigned to: Nobody/Anonymous (nobody) Summary: XML Schema Validation Initial Comment: The following files add support for validating a W3C Schema to make sure it is a valid schema document. This is different than validating an XML instance against a Schema. ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-03-07 06:00 Message: Logged In: YES user_id=113148 Originator: NO I didn't use any of your code, but added a new validator class based on javax.xml.validation like you did. The class I committed can validate the schema definition as well as instances - and should, at least in theory, be able to validate other schema languages as well. Thank you for pointing me to the validation package in JAXP 1.3. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1728598&group_id=23187 |
From: <bo...@us...> - 2008-03-07 04:56:37
|
Revision: 246 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=246&view=rev Author: bodewig Date: 2008-03-06 20:56:39 -0800 (Thu, 06 Mar 2008) Log Message: ----------- Add instance validation and document new Validator class Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java trunk/xmlunit/src/user-guide/XMLUnit-Java.xml trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-06 08:49:51 UTC (rev 245) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-07 04:56:39 UTC (rev 246) @@ -42,6 +42,7 @@ import javax.xml.transform.Source; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -56,13 +57,14 @@ */ public class Validator { private final String schemaLanguage; + private final SchemaFactory factory; private final ArrayList sources = new ArrayList(); /** * validates using W3C XML Schema 1.0. */ public Validator() { - this(XMLConstants.W3C_XML_SCHEMA_NS_URI); + this(XMLConstants.W3C_XML_SCHEMA_NS_URI, null); } /** @@ -72,7 +74,27 @@ * javax.xml.validation.SchemaFactory SchemaFactory}. */ public Validator(String schemaLanguage) { + this(schemaLanguage, null); + } + + /** + * validates using the specified schema factory. + */ + public Validator(SchemaFactory factory) { + this(null, factory); + } + + /** + * validates using the specified schema language or factory. + * + * @param schemaLanguage the schema language to use - see {@link + * javax.xml.validation.SchemaFactory SchemaFactory}. + * @param schemaFactory the concrete factory to use. If this is + * non-null, the first argument will be ignored. + */ + protected Validator(String schemaLanguage, SchemaFactory factory) { this.schemaLanguage = schemaLanguage; + this.factory = factory; } /** @@ -97,28 +119,90 @@ */ public List/*<SAXParseException>*/ getSchemaErrors() { final ArrayList l = new ArrayList(); - ErrorHandler h = new ErrorHandler() { - public void error(SAXParseException e) { - l.add(e); - } - public void fatalError(SAXParseException e) { - l.add(e); - } - public void warning(SAXParseException e) { - l.add(e); - } - }; try { - parseSchema(h); + parseSchema(new CollectingErrorHandler(l)); } catch (SAXException e) { // error has been recorded in our ErrorHandler anyway } return l; } + /** + * Is the given schema instance valid according to the configured + * schema definition(s)? + * + * @throws XMLUnitRuntimeException if the schema definition is + * invalid or the Source is a SAXSource and the underlying + * XMLReader throws an IOException (see {@link + * javax.xml.validation.Validator#validate validate in + * Validator}). + */ + public boolean isInstanceValid(Source instance) + throws XMLUnitRuntimeException { + return getInstanceErrors(instance).size() == 0; + } + + /** + * Obtain a list of all errors in the given instance. + * + * <p>The list contains {@link org.xml.sax.SAXParseException + * SAXParseException}s.</p> + * + * @throws XMLUnitRuntimeException if the schema definition is + * invalid or the Source is a SAXSource and the underlying + * XMLReader throws an IOException (see {@link + * javax.xml.validation.Validator#validate validate in + * Validator}). + */ + public List/*<SAXParseException>*/ getInstanceErrors(Source instance) + throws XMLUnitRuntimeException { + Schema schema = null; + try { + schema = parseSchema(null); + } catch (SAXException e) { + throw new XMLUnitRuntimeException("Schema is invalid", e); + } + + final ArrayList l = new ArrayList(); + javax.xml.validation.Validator v = schema.newValidator(); + v.setErrorHandler(new CollectingErrorHandler(l)); + try { + v.validate(instance); + } catch (SAXException e) { + // error has been recorded in our ErrorHandler anyway + } catch (java.io.IOException i) { + throw new XMLUnitRuntimeException("Error reading instance source", + i); + } + return l; + } + private Schema parseSchema(ErrorHandler h) throws SAXException { - SchemaFactory fac = SchemaFactory.newInstance(schemaLanguage); + SchemaFactory fac = factory != null ? factory + : SchemaFactory.newInstance(schemaLanguage); fac.setErrorHandler(h); - return fac.newSchema((Source[]) sources.toArray(new Source[0])); + try { + return fac.newSchema((Source[]) + sources.toArray(new Source[sources.size()])); + } finally { + fac.setErrorHandler(null); + } } + + private static final class CollectingErrorHandler implements ErrorHandler { + private final List l; + + CollectingErrorHandler(List l) { + this.l = l; + } + public void error(SAXParseException e) { + l.add(e); + } + public void fatalError(SAXParseException e) { + l.add(e); + } + public void warning(SAXParseException e) { + l.add(e); + } + } } \ No newline at end of file Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-03-06 08:49:51 UTC (rev 245) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2008-03-07 04:56:39 UTC (rev 246) @@ -456,6 +456,14 @@ or more XML Schema definitions. See <xref linkend="XML Schema Validation"/> for details.</para> + <para>XMLUnit 1.2 introduces a new <literal>Validator</literal> + class that relies on JAXP + 1.3's <literal>javax.xml.validation</literal> package. This + Validator can validate against W3C XML Schema, but may support + different Schema languages like RELAX NG if your JAXP + implementation supports it. See + <xref linkend="JAXP 1.3 Validation"/> for details.</para> + </section> <section id="Xpath Tests"><title>Xpath Tests</title> @@ -2436,7 +2444,7 @@ the configured <literal>EntityResolver</literal> may still be used.</para> - <example> + <example id="schema-jaxp12"> <title>Validating Against a Local XML Schema</title> <programlisting language="Java"><![CDATA[ InputSource is = new InputSource(new FileInputStream(myXmlDocument)); @@ -2500,6 +2508,65 @@ linkend="XML Schema Validation"/>).</listitem> </itemizedlist> </section> + + <section id="JAXP 1.3 Validation"> + <title>JAXP 1.3 Validation</title> + + <para>JAXP 1.3 - shipping with Java5 or better and available as + a separate product for earlier Java VMs - introduces a new + package <ulink url="https://jaxp-sources.dev.java.net/nonav/docs/api/"><literal>javax.xml.validation</literal></ulink> + designed for validations of snippets of XML against different + schema languages. Any compliant implementation must support the + W3C XMl Schema language, but other languages + like <ulink url="http://www.relaxng.org/">RELAX NG</ulink> or + <ulink url="http://www.schematron.com/">Schematron</ulink> may + be supported as well.</para> + + <para>The + class <literal>org.custommonkey.xmlunit.jaxp13.Validator</literal> + can be used to validate a piece of XML against a schema + definition but also to validate the schema definition itself. + By default <literal>Validator</literal> will assume your + definition uses the W3C XML Schema language, but it provides a + constructor that can be used to specify a different language via + an URL supported by the <literal>SchemaFactory</literal> class. + Alternatively you can specify the schema factory itself.</para> + + <para>The schema definition itself can be given via + <literal>Source</literal> elements, just like the pices of XML + to validate are specified as <literal>Source</literal> as + well.</para> + + <para>The following example + uses <literal>org.custommonkey.xmlunit.jaxp13.Validator</literal> + to perform the same type of validation shown in + <xref linkend="schema-jaxp12"/>.</para> + + <example id="schema-jaxp13"> + <title>Validating Against a Local XML Schema</title> + <programlisting language="Java"><![CDATA[ +Validator v = new Validator(); +v.addSchemaSource(new StreamSource(new File(myXmlSchemaFile))); +StreamSource is = new StreamSource(new File(myXmlDocument)); +boolean isValid = v.isInstanceValid(is); +]]></programlisting></example> + + <para>Validating a schema definition is shown in the next + example.</para> + + <example> + <title>Validating a XML Schema Defintion</title> + <programlisting language="Java"><![CDATA[ +Validator v = new Validator(); +v.addSchemaSource(new StreamSource(new File(myXmlSchemaFile))); +boolean isValid = v.isSchemaValid(); +]]></programlisting></example> + + <para>There is no explicit JUnit 3 support + for <literal>org.custommonkey.xmlunit.jaxp13.Validator</literal>.</para> + + </section> + </section> <section id="XPath Tests"> @@ -3259,6 +3326,16 @@ by <literal>Validator</literal> can now be configured completely. <ulink href="https://sourceforge.net/tracker/index.php?func=detail&aid=1903928&group_id=23187&atid=377771">Issue 1903928</ulink>.</listitem> + + <listitem>A new + class <literal>org.custommonkey.xmlunit.jaxp13.Validator</literal> + can be used to validate schema definitions and schema + instances using the <literal>javax.xml.validation</literal> + package of JAXP 1.3. Depending on your JAXP implementation + this may allow you to validate documents against schema + definitions written in RELAX NG or other schema languages in + addition to W3C XML Schema. See + <xref linkend="JAXP 1.3 Validation"/> for details.</listitem> </itemizedlist> </section> Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-06 08:49:51 UTC (rev 245) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-07 04:56:39 UTC (rev 246) @@ -37,6 +37,7 @@ package org.custommonkey.xmlunit.jaxp13; import java.io.File; +import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.xml.transform.stream.StreamSource; @@ -44,6 +45,9 @@ import junit.framework.TestCase; import org.custommonkey.xmlunit.test_Constants; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; public class test_Validator extends TestCase { @@ -73,12 +77,81 @@ v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + "/tests/etc/broken.xsd"))); List l = v.getSchemaErrors(); - /* for (Iterator i = l.iterator(); i.hasNext(); ) { - System.err.println(i.next()); + Object ex = i.next(); + assertTrue(ex instanceof SAXParseException); + /* + System.err.println(ex); + */ } - */ assertTrue(l.size() > 0); } + public void testGoodInstanceIsValid() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/BookXsdGenerated.xml")); + assertTrue(v.isInstanceValid(s)); + } + + public void testBadInstanceIsInvalid() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/invalidBook.xml")); + assertFalse(v.isInstanceValid(s)); + } + + public void testBadInstanceHasErrors() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/invalidBook.xml")); + List l = v.getInstanceErrors(s); + for (Iterator i = l.iterator(); i.hasNext(); ) { + Object ex = i.next(); + assertTrue(ex instanceof SAXParseException); + /* + System.err.println(ex); + */ + } + assertTrue(l.size() > 0); + } + + public void testInstanceValidationOfBrokenSchema() { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/broken.xsd"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/BookXsdGenerated.xml")); + try { + v.isInstanceValid(s); + fail("expected exception because schema is invalid"); + } catch (XMLUnitRuntimeException e) { + assertTrue(e.getCause() instanceof SAXException); + } + } + + public void testInstanceValidationOfMissingFile() { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); + StreamSource s = + new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/not there.xml")); + try { + v.isInstanceValid(s); + fail("expected exception because instance doesn't exist"); + } catch (XMLUnitRuntimeException e) { + assertTrue(e.getCause() instanceof IOException); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-06 08:49:46
|
Revision: 245 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=245&view=rev Author: bodewig Date: 2008-03-06 00:49:51 -0800 (Thu, 06 Mar 2008) Log Message: ----------- simplify Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-05 16:42:35 UTC (rev 244) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-06 08:49:51 UTC (rev 245) @@ -37,7 +37,6 @@ package org.custommonkey.xmlunit.jaxp13; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import javax.xml.XMLConstants; import javax.xml.transform.Source; @@ -114,7 +113,7 @@ } catch (SAXException e) { // error has been recorded in our ErrorHandler anyway } - return Collections.unmodifiableList(l); + return l; } private Schema parseSchema(ErrorHandler h) throws SAXException { Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-05 16:42:35 UTC (rev 244) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-06 08:49:51 UTC (rev 245) @@ -36,7 +36,7 @@ package org.custommonkey.xmlunit.jaxp13; -import java.io.FileInputStream; +import java.io.File; import java.util.Iterator; import java.util.List; import javax.xml.transform.stream.StreamSource; @@ -49,41 +49,29 @@ public void testGoodSchemaIsValid() throws Exception { Validator v = new Validator(); - v.addSchemaSource(new StreamSource( - new FileInputStream(test_Constants.BASEDIR - + "/tests/etc/Book.xsd") - ) - ); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); assertTrue(v.isSchemaValid()); } public void testGoodSchemaHasNoErrors() throws Exception { Validator v = new Validator(); - v.addSchemaSource(new StreamSource( - new FileInputStream(test_Constants.BASEDIR - + "/tests/etc/Book.xsd") - ) - ); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/Book.xsd"))); assertEquals(0, v.getSchemaErrors().size()); } public void testBrokenSchemaIsInvalid() throws Exception { Validator v = new Validator(); - v.addSchemaSource(new StreamSource( - new FileInputStream(test_Constants.BASEDIR - + "/tests/etc/broken.xsd") - ) - ); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/broken.xsd"))); assertFalse(v.isSchemaValid()); } public void testBrokenSchemaHasErrors() throws Exception { Validator v = new Validator(); - v.addSchemaSource(new StreamSource( - new FileInputStream(test_Constants.BASEDIR - + "/tests/etc/broken.xsd") - ) - ); + v.addSchemaSource(new StreamSource(new File(test_Constants.BASEDIR + + "/tests/etc/broken.xsd"))); List l = v.getSchemaErrors(); /* for (Iterator i = l.iterator(); i.hasNext(); ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-05 16:42:34
|
Revision: 244 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=244&view=rev Author: bodewig Date: 2008-03-05 08:42:35 -0800 (Wed, 05 Mar 2008) Log Message: ----------- add Schema defintion validation based on javax.xml.validation Added Paths: ----------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java trunk/xmlunit/tests/etc/broken.xsd trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java Added: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java 2008-03-05 16:42:35 UTC (rev 244) @@ -0,0 +1,125 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.jaxp13; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.xml.XMLConstants; +import javax.xml.transform.Source; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/** + * Validator class based of {@link javax.xml.validation javax.xml.validation}. + * + * <p>This class currently only provides support for validating schema + * definitions. It defaults to the W3C XML Schema 1.0 but can be used + * to validate against any schema language supported by your + * SchemaFactory implementation.</p> + */ +public class Validator { + private final String schemaLanguage; + private final ArrayList sources = new ArrayList(); + + /** + * validates using W3C XML Schema 1.0. + */ + public Validator() { + this(XMLConstants.W3C_XML_SCHEMA_NS_URI); + } + + /** + * validates using the specified schema language. + * + * @param schemaLanguage the schema language to use - see {@link + * javax.xml.validation.SchemaFactory SchemaFactory}. + */ + public Validator(String schemaLanguage) { + this.schemaLanguage = schemaLanguage; + } + + /** + * Adds a source for the schema defintion. + */ + public void addSchemaSource(Source s) { + sources.add(s); + } + + /** + * Is the given schema definition valid? + */ + public boolean isSchemaValid() { + return getSchemaErrors().size() == 0; + } + + /** + * Obtain a list of all errors in the schema defintion. + * + * <p>The list contains {@link org.xml.sax.SAXParseException + * SAXParseException}s.</p> + */ + public List/*<SAXParseException>*/ getSchemaErrors() { + final ArrayList l = new ArrayList(); + ErrorHandler h = new ErrorHandler() { + public void error(SAXParseException e) { + l.add(e); + } + public void fatalError(SAXParseException e) { + l.add(e); + } + public void warning(SAXParseException e) { + l.add(e); + } + }; + try { + parseSchema(h); + } catch (SAXException e) { + // error has been recorded in our ErrorHandler anyway + } + return Collections.unmodifiableList(l); + } + + private Schema parseSchema(ErrorHandler h) throws SAXException { + SchemaFactory fac = SchemaFactory.newInstance(schemaLanguage); + fac.setErrorHandler(h); + return fac.newSchema((Source[]) sources.toArray(new Source[0])); + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Validator.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/etc/broken.xsd =================================================================== --- trunk/xmlunit/tests/etc/broken.xsd (rev 0) +++ trunk/xmlunit/tests/etc/broken.xsd 2008-03-05 16:42:35 UTC (rev 244) @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.publishing.org" + xmlns="http://www.publishing.org" + version="1.0" + elementFormDefault="qualified"> + + <xsd:element name="Book" type="BookType"/> + + <xsd:complexType name="BookType"> + <xsd:element name="Title" type="xsd:string" minOccurs="1" maxOccurs="1"/> + <xsd:element name="Author" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/> + <xsd:element name="Date" type="xsd:string" minOccurs="1" maxOccurs="1"/> + <xsd:element name="ISBN" type="xsd:string" minOccurs="1" maxOccurs="1"/> + </xsd:complexType> +</xsd:schema> + Property changes on: trunk/xmlunit/tests/etc/broken.xsd ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java 2008-03-05 16:42:35 UTC (rev 244) @@ -0,0 +1,96 @@ +/* +****************************************************************** +Copyright (c) 2008, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.jaxp13; + +import java.io.FileInputStream; +import java.util.Iterator; +import java.util.List; +import javax.xml.transform.stream.StreamSource; + +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.test_Constants; + +public class test_Validator extends TestCase { + + public void testGoodSchemaIsValid() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource( + new FileInputStream(test_Constants.BASEDIR + + "/tests/etc/Book.xsd") + ) + ); + assertTrue(v.isSchemaValid()); + } + + public void testGoodSchemaHasNoErrors() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource( + new FileInputStream(test_Constants.BASEDIR + + "/tests/etc/Book.xsd") + ) + ); + assertEquals(0, v.getSchemaErrors().size()); + } + + public void testBrokenSchemaIsInvalid() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource( + new FileInputStream(test_Constants.BASEDIR + + "/tests/etc/broken.xsd") + ) + ); + assertFalse(v.isSchemaValid()); + } + + public void testBrokenSchemaHasErrors() throws Exception { + Validator v = new Validator(); + v.addSchemaSource(new StreamSource( + new FileInputStream(test_Constants.BASEDIR + + "/tests/etc/broken.xsd") + ) + ); + List l = v.getSchemaErrors(); + /* + for (Iterator i = l.iterator(); i.hasNext(); ) { + System.err.println(i.next()); + } + */ + assertTrue(l.size() > 0); + } + +} \ No newline at end of file Property changes on: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Validator.java ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-04 09:27:36
|
Revision: 243 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=243&view=rev Author: bodewig Date: 2008-03-04 01:27:42 -0800 (Tue, 04 Mar 2008) Log Message: ----------- fix indentation Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2008-03-04 09:26:31 UTC (rev 242) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2008-03-04 09:27:42 UTC (rev 243) @@ -414,9 +414,10 @@ unmatchedTestNodes.remove(0); } if (nextTest != null) { - compareNode(nextControl, nextTest, listener, elementQualifier); - compare(new Integer(i), testIndex, - nextControl, nextTest, listener, CHILD_NODELIST_SEQUENCE); + compareNode(nextControl, nextTest, listener, elementQualifier); + compare(new Integer(i), testIndex, + nextControl, nextTest, listener, + CHILD_NODELIST_SEQUENCE); } else { missingNode(nextControl, null, listener); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-03-04 09:26:32
|
Revision: 242 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=242&view=rev Author: bodewig Date: 2008-03-04 01:26:31 -0800 (Tue, 04 Mar 2008) Log Message: ----------- control nodes are visited in document order, no need to prefill child list Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2008-03-03 16:26:08 UTC (rev 241) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2008-03-04 09:26:31 UTC (rev 242) @@ -356,7 +356,6 @@ int j = 0; final int lastTestNode = testChildren.size() - 1; - controlTracker.preloadChildList(controlChildren); testTracker.preloadChildList(testChildren); HashMap/*<Node, Node>*/ matchingNodes = new HashMap(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |