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
(14) |
Sep
(8) |
Oct
(13) |
Nov
|
Dec
|
| 2026 |
Jan
(24) |
Feb
|
Mar
|
Apr
|
May
(18) |
Jun
(8) |
Jul
(33) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <bo...@us...> - 2007-03-23 19:57:41
|
Revision: 154
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=154&view=rev
Author: bodewig
Date: 2007-03-23 12:57:40 -0700 (Fri, 23 Mar 2007)
Log Message:
-----------
add test for forum thread 1691528
Modified Paths:
--------------
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
===================================================================
--- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-23 04:49:34 UTC (rev 153)
+++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-23 19:57:40 UTC (rev 154)
@@ -192,7 +192,35 @@
// sequence of nodes
assertEquals(3, l.size());
}
+
+ /**
+ * @see http://sourceforge.net/forum/forum.php?thread_id=1691528&forum_id=73274
+ */
+ public void testHelpForumThread1691528() throws Exception {
+ String control = "<table border=\"1\">"
+ + "<tr>"
+ + "<th>News</th>"
+ + "</tr>"
+ + "<tr>"
+ + "<td>Newsitem 1</td>"
+ + "</tr>"
+ + "</table>";
+ String test = "<table border=\"1\">"
+ + "<tr>"
+ + "<th>News</th>"
+ + "</tr>"
+ + "<tr>"
+ + "<td>Newsitem 2</td>"
+ + "<td>Newsitem 1</td>"
+ + "</tr>"
+ + "</table>";
+ DetailedDiff diff = new DetailedDiff(new Diff(control, test));
+ List changes = diff.getAllDifferences();
+ // number of children, text of first child
+ assertEquals(2, changes.size());
+ }
+
protected Diff buildDiff(Document control, Document test) {
return new DetailedDiff(super.buildDiff(control, test));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-03-23 04:49:35
|
Revision: 153
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=153&view=rev
Author: bodewig
Date: 2007-03-22 21:49:34 -0700 (Thu, 22 Mar 2007)
Log Message:
-----------
re-indent, only whitespace changes
Modified Paths:
--------------
trunk/xmlunit/src/site/XMLUnit-Java.xml
Modified: trunk/xmlunit/src/site/XMLUnit-Java.xml
===================================================================
--- trunk/xmlunit/src/site/XMLUnit-Java.xml 2007-03-23 04:40:11 UTC (rev 152)
+++ trunk/xmlunit/src/site/XMLUnit-Java.xml 2007-03-23 04:49:34 UTC (rev 153)
@@ -49,93 +49,100 @@
XMLUnit, but not the only one. XMLUnit's features can be fully
used without any dependency on JUnit at all.</para>
- <section><title>What is XMLUnit?</title>
+ <section><title>What is XMLUnit?</title>
- <para>XMLUnit enables JUnit-style assertions to be made about the
- content and structure of XML<footnote id="more on JUnit"><para>For
- more information on JUnit see <ulink
- url="http://www.junit.org">http://www.junit.org</ulink></para></footnote>. It
- is an open source project hosted at <ulink url="http://xmlunit.sourceforge.net/">http://xmlunit.sourceforge.net/</ulink>
- that grew out of a need to test a system that generated and
- received custom XML messages. The problem that we faced was how to
- verify that the system generated the correct message from a known
- set of inputs. Obviously we could use a DTD or a schema to
- validate the message output, but this approach wouldn't allow us
- to distinguish between valid XML with correct content (e.g.
- element <literal><![CDATA[<foo>bar</foo>]]></literal>) and valid
- XML with incorrect content (e.g. element
- <literal><![CDATA[<foo>baz</foo>]]></literal>). What we really
- wanted was an <literal>assertXMLEquals()</literal> method, so we
- could compare the message that we expected the system to generate
- and the message that the system actually generated. And that was
- the beginning of XMLUnit.</para>
- </section>
- <section><title>Quick tour</title>
+ <para>XMLUnit enables JUnit-style assertions to be made about
+ the content and structure of XML<footnote id="more on
+ JUnit"><para>For more information on JUnit see <ulink
+ url="http://www.junit.org">http://www.junit.org</ulink></para></footnote>. It
+ is an open source project hosted at <ulink
+ url="http://xmlunit.sourceforge.net/">http://xmlunit.sourceforge.net/</ulink>
+ that grew out of a need to test a system that generated and
+ received custom XML messages. The problem that we faced was how
+ to verify that the system generated the correct message from a
+ known set of inputs. Obviously we could use a DTD or a schema to
+ validate the message output, but this approach wouldn't allow us
+ to distinguish between valid XML with correct content (e.g.
+ element <literal><![CDATA[<foo>bar</foo>]]></literal>) and valid
+ XML with incorrect content (e.g. element
+ <literal><![CDATA[<foo>baz</foo>]]></literal>). What we really
+ wanted was an <literal>assertXMLEquals()</literal> method, so we
+ could compare the message that we expected the system to
+ generate and the message that the system actually generated. And
+ that was the beginning of XMLUnit.</para>
+ </section>
+ <section><title>Quick tour</title>
- <para>XMLUnit provides a single JUnit extension class,
- <literal>XMLTestCase</literal>, and a set of supporting classes
- that allow assertions to be made about:</para>
+ <para>XMLUnit provides a single JUnit extension class,
+ <literal>XMLTestCase</literal>, and a set of supporting classes
+ that allow assertions to be made about:</para>
- <itemizedlist>
- <listitem>The differences between two pieces of XML (via
- <literal>Diff</literal> and <literal>DetailedDiff</literal>
- classes)</listitem>
+ <itemizedlist>
+ <listitem>The differences between two pieces of XML (via
+ <literal>Diff</literal> and <literal>DetailedDiff</literal>
+ classes)</listitem>
- <listitem>The validity of a piece of XML (via
- <literal>Validator</literal> class)</listitem>
+ <listitem>The validity of a piece of XML (via
+ <literal>Validator</literal> class)</listitem>
- <listitem> The outcome of transforming a piece of XML using XSLT
- (via <literal>Transform</literal> class)</listitem>
+ <listitem> The outcome of transforming a piece of XML using
+ XSLT (via <literal>Transform</literal> class)</listitem>
- <listitem>The evaluation of an XPath expression on a piece of
- XML (via classes implementing the <literal>XpathEngine</literal> interface)</listitem>
+ <listitem>The evaluation of an XPath expression on a piece of
+ XML (via classes implementing the
+ <literal>XpathEngine</literal> interface)</listitem>
- <listitem>Individual nodes in a piece of XML that are exposed by
- DOM Traversal (via <literal>NodeTest</literal> class)</listitem>
- </itemizedlist>
+ <listitem>Individual nodes in a piece of XML that are exposed
+ by DOM Traversal (via <literal>NodeTest</literal>
+ class)</listitem>
+ </itemizedlist>
- <para>XMLUnit can also treat HTML content, even badly-formed HTML,
- as valid XML to allow these assertions to be made about web pages
- (via the <literal>HTMLDocumentBuilder</literal> class).</para>
- </section>
+ <para>XMLUnit can also treat HTML content, even badly-formed
+ HTML, as valid XML to allow these assertions to be made about
+ web pages (via the <literal>HTMLDocumentBuilder</literal>
+ class).</para>
+ </section>
- <section><title>Glossary</title>
+ <section><title>Glossary</title>
- <para>As with many projects some words in XMLUnit have particular
- meanings so here is a quick overview. A <emphasis>piece</emphasis>
- of XML is a DOM Document, a String containing marked-up content,
- or a Source or Reader that allows access to marked-up content
- within some resource. XMLUnit compares the expected
- <emphasis>control</emphasis> XML to some actual
- <emphasis>test</emphasis> XML. The comparison can reveal that two
- pieces of XML are <emphasis>identical</emphasis>,
- <emphasis>similar</emphasis> or
- <emphasis>different</emphasis>. The unit of measurement used by
- the comparison is a <emphasis>difference</emphasis>, and
- differences can be either <emphasis>recoverable</emphasis> or
- <emphasis>unrecoverable</emphasis>. Two pieces of XML are
- <emphasis>identical</emphasis> if there are <emphasis>no
- differences</emphasis> between them, <emphasis>similar</emphasis>
- if there are <emphasis>only recoverable differences</emphasis>
- between them, and <emphasis>different</emphasis> if there are
- <emphasis>any unrecoverable differences</emphasis> between
- them.</para>
- </section>
+ <para>As with many projects some words in XMLUnit have
+ particular meanings so here is a quick overview. A
+ <emphasis>piece</emphasis> of XML is a DOM Document, a String
+ containing marked-up content, or a Source or Reader that allows
+ access to marked-up content within some resource. XMLUnit
+ compares the expected <emphasis>control</emphasis> XML to some
+ actual <emphasis>test</emphasis> XML. The comparison can reveal
+ that two pieces of XML are <emphasis>identical</emphasis>,
+ <emphasis>similar</emphasis> or
+ <emphasis>different</emphasis>. The unit of measurement used by
+ the comparison is a <emphasis>difference</emphasis>, and
+ differences can be either <emphasis>recoverable</emphasis> or
+ <emphasis>unrecoverable</emphasis>. Two pieces of XML are
+ <emphasis>identical</emphasis> if there are <emphasis>no
+ differences</emphasis> between them,
+ <emphasis>similar</emphasis> if there are <emphasis>only
+ recoverable differences</emphasis> between them, and
+ <emphasis>different</emphasis> if there are <emphasis>any
+ unrecoverable differences</emphasis> between them.</para>
+ </section>
- <section><title>Configuring XMLUnit</title>
+ <section><title>Configuring XMLUnit</title>
- <para>There are many Java XML parsers available, and XMLUnit
- should work with any JAXP compliant parser library, such as Xerces-J
- <footnote id="xerces-link"><para><ulink url="http://xerces.apache.org/">http://xerces.apache.org/</ulink></para></footnote>
- from the Apache Software Foundation. To use the XSL and XPath features
- of XMLUnit a Trax (the XSLT portion of JAXP) compliant transformation engine is required,
- such as Xalan-J<footnote id="xalan-link"><para><ulink url="http://xalan.apache.org/">http://xalan.apache.org/</ulink></para></footnote>,
- from the Software Foundation. To configure
- XMLUnit to use a specific parser and transformation engine set three
- System properties before any tests are run, e.g.</para>
+ <para>There are many Java XML parsers available, and XMLUnit
+ should work with any JAXP compliant parser library, such as
+ Xerces-J <footnote id="xerces-link"><para><ulink
+ url="http://xerces.apache.org/">http://xerces.apache.org/</ulink></para></footnote>
+ from the Apache Software Foundation. To use the XSL and XPath
+ features of XMLUnit a Trax (the XSLT portion of JAXP) compliant
+ transformation engine is required, such as Xalan-J<footnote
+ id="xalan-link"><para><ulink
+ url="http://xalan.apache.org/">http://xalan.apache.org/</ulink></para></footnote>,
+ from the Software Foundation. To configure XMLUnit to use a
+ specific parser and transformation engine set three System
+ properties before any tests are run, e.g.</para>
- <example><title>Configuring JAXP via System Properties</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Configuring JAXP via System Properties</title>
+ <programlisting language="Java"><![CDATA[
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory",
@@ -143,7 +150,7 @@
System.setProperty("javax.xml.transform.TransformerFactory",
"org.apache.xalan.processor.TransformerFactoryImpl");
]]></programlisting>
- </example>
+ </example>
<para>If you are using a JDK 1.4 or later, your Java class
library already contain the required XML parsers and XSLT
@@ -155,36 +162,36 @@
Standards Override Mechanism</ulink> to use a different
parser/transformer than the one of your JDK.</para>
- <para>Alternatively there are static methods on the XMLUnit class
- that can be called directly. The advantage of this approach is
- that you can specify a different parser class for control and test
- XML and change the current parser class at any time in your tests,
- should you need to make assertions about the compatibility of
- different parsers.</para>
+ <para>Alternatively there are static methods on the XMLUnit
+ class that can be called directly. The advantage of this
+ approach is that you can specify a different parser class for
+ control and test XML and change the current parser class at any
+ time in your tests, should you need to make assertions about the
+ compatibility of different parsers.</para>
-<example><title>Configuring JAXP via XMLUnit class</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Configuring JAXP via XMLUnit class</title>
+ <programlisting language="Java"><![CDATA[
XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");
XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");
]]></programlisting>
- </example>
+ </example>
<para>The later approach should also work for JDK 1.4 and above,
even if you don't override the endorsed standards
libraries</para>
- </section>
+ </section>
- <section><title>Writing XML comparison tests</title>
+ <section><title>Writing XML comparison tests</title>
- <para>Let's say we have two pieces of XML that we wish to compare
- and assert that they are equal. We could write a simple test class
- like this:</para>
+ <para>Let's say we have two pieces of XML that we wish to
+ compare and assert that they are equal. We could write a simple
+ test class like this:</para>
- <example><title>A simple comparison test</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>A simple comparison test</title>
+ <programlisting language="Java"><![CDATA[
public class MyXMLTestCase extends XMLTestCase {
public MyXMLTestCase(String name) {
super(name);
@@ -198,36 +205,36 @@
}
}]]></programlisting></example>
- <para>The <literal>assertXMLEqual</literal> test will pass if the
- control and test XML are either similar or identical. Obviously in
- this case the pieces of XML are different and the test will
- fail. The failure message indicates both what the difference is
- and the Xpath locations of the nodes that were being
- compared:</para>
+ <para>The <literal>assertXMLEqual</literal> test will pass if
+ the control and test XML are either similar or
+ identical. Obviously in this case the pieces of XML are
+ different and the test will fail. The failure message indicates
+ both what the difference is and the Xpath locations of the nodes
+ that were being compared:</para>
- <programlisting><![CDATA[
+ <programlisting><![CDATA[
Comparing test xml to control xml
[different] Expected element tag name 'uuid' but was 'localId' - comparing <uuid...> at /msg[1]/uuid[1] to <localId...> at /msg[1]/localId[1]
]]></programlisting>
- <para>When comparing pieces of XML, the
- <literal>XMLTestCase</literal> actually creates an instance of the
- <literal>Diff</literal> class. The <literal>Diff</literal> class
- stores the result of an XML comparison and makes it available
- through the methods <literal>similar()</literal> and
- <literal>identical()</literal>. The
- <literal>assertXMLEquals()</literal> method tests the value of
- <literal>Diff.similar()</literal> and the
- <literal>assertXMLIdentical()</literal> method tests the value of
- <literal>Diff.identical()</literal>.</para>
+ <para>When comparing pieces of XML, the
+ <literal>XMLTestCase</literal> actually creates an instance of
+ the <literal>Diff</literal> class. The <literal>Diff</literal>
+ class stores the result of an XML comparison and makes it
+ available through the methods <literal>similar()</literal> and
+ <literal>identical()</literal>. The
+ <literal>assertXMLEquals()</literal> method tests the value of
+ <literal>Diff.similar()</literal> and the
+ <literal>assertXMLIdentical()</literal> method tests the value
+ of <literal>Diff.identical()</literal>.</para>
- <para>It is easy to create a <literal>Diff</literal> instance
- directly without using the <literal>XMLTestCase</literal> class as
- below:</para>
+ <para>It is easy to create a <literal>Diff</literal> instance
+ directly without using the <literal>XMLTestCase</literal> class
+ as below:</para>
- <example><title>Creating a <literal>Diff</literal>
- instance</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Creating a <literal>Diff</literal>
+ instance</title>
+ <programlisting language="Java"><![CDATA[
public void testXMLIdentical()throws Exception {
String myControlXML =
"<struct><int>3</int><boolean>false</boolean></struct>";
@@ -240,27 +247,27 @@
myDiff.identical());
}]]></programlisting></example>
- <para>This test fails as two pieces of XML are similar but not
- identical if their nodes occur in a different sequence. The
- failure message reported by JUnit from the call to
- <literal>myDiff.toString()</literal> looks like this:</para>
+ <para>This test fails as two pieces of XML are similar but not
+ identical if their nodes occur in a different sequence. The
+ failure message reported by JUnit from the call to
+ <literal>myDiff.toString()</literal> looks like this:</para>
- <programlisting><![CDATA[
+ <programlisting><![CDATA[
[not identical] Expected sequence of child nodes '0' but was '1' - comparing <int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1]
]]></programlisting>
- <para>For efficiency reasons a <literal>Diff</literal> stops the
- comparison process as soon as the first difference is found. To
- get all the differences between two pieces of XML an instance of
- the <literal>DetailedDiff</literal> class, a subclass of
- <literal>Diff</literal>, is required. Note that a
- <literal>DetailedDiff</literal> is constructed using an existing
- <literal>Diff</literal> instance.</para>
+ <para>For efficiency reasons a <literal>Diff</literal> stops the
+ comparison process as soon as the first difference is found. To
+ get all the differences between two pieces of XML an instance of
+ the <literal>DetailedDiff</literal> class, a subclass of
+ <literal>Diff</literal>, is required. Note that a
+ <literal>DetailedDiff</literal> is constructed using an existing
+ <literal>Diff</literal> instance.</para>
- <para>Consider this test that uses a DetailedDiff:</para>
+ <para>Consider this test that uses a DetailedDiff:</para>
- <example><title>Using <literal>DetailedDiff</literal></title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using <literal>DetailedDiff</literal></title>
+ <programlisting language="Java"><![CDATA[
public void testAllDifferences() throws Exception {
String myControlXML = "<news><item id=\"1\">War</item>"
+ "<item id=\"2\">Plague</item>"
@@ -273,47 +280,47 @@
assertEquals(myDiff.toString(), 2, allDifferences.size());
}]]></programlisting></example>
- <para>This test fails with the message below as each of the 3 news
- items differs between the control and test XML:</para>
+ <para>This test fails with the message below as each of the 3
+ news items differs between the control and test XML:</para>
- <programlisting><![CDATA[
+ <programlisting><![CDATA[
[different] Expected text value 'War' but was 'Peace' - comparing <item...>War</item> at /news[1]/item[1]/text()[1] to <item...>Peace</item> at /news[1]/item[1]/text()[1]
[different] Expected text value 'Plague' but was 'Health' - comparing <item...>Plague</item> at /news[1]/item[2]/text()[1] to <item...>Health</item> at /news[1]/item[2]/text()[1]
[different] Expected text value 'Famine' but was 'Plenty' - comparing <item...>Famine</item> at /news[1]/item[3]/text()[1] to <item...>Plenty</item> at /news[1]/item[3]/text()[1]
expected <2> but was <3>
]]></programlisting>
- <para>The List returned from the
- <literal>getAllDifferences()</literal> method contains
- <literal>Difference</literal> instances. These instances describe
- both the type<footnote id="DifferenceConstants"><para>A full set
- of prototype <literal>Difference</literal> instances - one for
- each type of difference - is defined using final static fields in
- the <literal>DifferenceConstants</literal>
- class.</para></footnote> of difference found between a control
- node and test node and the <literal>NodeDetail</literal> of those
- nodes (including the XPath location of each
- node). <literal>Difference</literal> instances are passed at
- runtime in notification events to a registered
- <literal>DifferenceListener</literal>, an interface whose default
- implementation is provided by the <literal>Diff</literal>
- class.</para>
+ <para>The List returned from the
+ <literal>getAllDifferences()</literal> method contains
+ <literal>Difference</literal> instances. These instances
+ describe both the type<footnote id="DifferenceConstants"><para>A
+ full set of prototype <literal>Difference</literal> instances -
+ one for each type of difference - is defined using final static
+ fields in the <literal>DifferenceConstants</literal>
+ class.</para></footnote> of difference found between a control
+ node and test node and the <literal>NodeDetail</literal> of
+ those nodes (including the XPath location of each
+ node). <literal>Difference</literal> instances are passed at
+ runtime in notification events to a registered
+ <literal>DifferenceListener</literal>, an interface whose
+ default implementation is provided by the
+ <literal>Diff</literal> class.</para>
- <para>However it is possible to override this default behaviour by
- implementing the interface in your own class. The
- <literal>IgnoreTextAndAttributeValuesDifferenceListener</literal>
- class is an example of how to implement a custom
- <literal>DifferenceListener</literal>. It allows an XML comparison
- to be made that ignores differences in the values of text and
- attribute nodes, for example when comparing a skeleton or outline
- piece of XML to some generated XML.</para>
+ <para>However it is possible to override this default behaviour
+ by implementing the interface in your own class. The
+ <literal>IgnoreTextAndAttributeValuesDifferenceListener</literal>
+ class is an example of how to implement a custom
+ <literal>DifferenceListener</literal>. It allows an XML
+ comparison to be made that ignores differences in the values of
+ text and attribute nodes, for example when comparing a skeleton
+ or outline piece of XML to some generated XML.</para>
- <para>The following test illustrates the use of a custom
- <literal>DifferenceListener</literal>:</para>
+ <para>The following test illustrates the use of a custom
+ <literal>DifferenceListener</literal>:</para>
- <example><title>Using a custom
- <literal>DifferenceListener</literal></title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using a custom
+ <literal>DifferenceListener</literal></title>
+ <programlisting language="Java"><![CDATA[
public void testCompareToSkeletonXML() throws Exception {
String myControlXML = "<location><street-address>22 any street</street-address><postcode>XY00 99Z</postcode></location>";
String myTestXML = "<location><street-address>20 east cheap</street-address><postcode>EC3M 1EB</postcode></location>";
@@ -324,41 +331,44 @@
myDiff.similar());
}]]></programlisting></example>
- <para>The <literal>DifferenceEngine</literal> class generates the
- events that are passed to a <literal>DifferenceListener</literal>
- implementation as two pieces of XML are compared. Using recursion
- it navigates through the nodes in the control XML DOM, and
- determines which node in the test XML DOM qualifies for comparison
- to the current control node. The qualifying test node will match
- the control node's node type, as well as the node name and
- namespace (if defined for the control node).</para>
+ <para>The <literal>DifferenceEngine</literal> class generates
+ the events that are passed to a
+ <literal>DifferenceListener</literal> implementation as two
+ pieces of XML are compared. Using recursion it navigates through
+ the nodes in the control XML DOM, and determines which node in
+ the test XML DOM qualifies for comparison to the current control
+ node. The qualifying test node will match the control node's
+ node type, as well as the node name and namespace (if defined
+ for the control node).</para>
- <para>However when the control node is an
- <literal>Element</literal>, it is less straightforward to
- determine which test <literal>Element</literal> qualifies for
- comparison as the parent node may contain repeated child
- <literal>Element</literal>s with the same name and namespace. So
- for <literal>Element</literal> nodes, an instance of the
- <literal>ElementQualifier</literal> interface is used determine
- whether a given test <literal>Element</literal> node qualifies for
- comparison with a control <literal>Element</literal> node. This
- separates the decision about whether two
- <literal>Elements</literal> should be compared from the decision
- about whether those two <literal>Elements</literal> are considered
- similar. By default an <literal>ElementNameQualifier</literal>
- class is used that compares the nth child
- <literal><![CDATA[<abc>]]></literal> test element to the nth child
- <literal><![CDATA[<abc>]]></literal> control element, i.e. the
- sequence of the child elements in the test XML is
- important. However this default behaviour can be overridden using
- an <literal>ElementNameAndTextQualifier</literal> or
- <literal>ElementNameAndAttributesQualifier</literal>.</para>
+ <para>However when the control node is an
+ <literal>Element</literal>, it is less straightforward to
+ determine which test <literal>Element</literal> qualifies for
+ comparison as the parent node may contain repeated child
+ <literal>Element</literal>s with the same name and namespace. So
+ for <literal>Element</literal> nodes, an instance of the
+ <literal>ElementQualifier</literal> interface is used determine
+ whether a given test <literal>Element</literal> node qualifies
+ for comparison with a control <literal>Element</literal>
+ node. This separates the decision about whether two
+ <literal>Elements</literal> should be compared from the decision
+ about whether those two <literal>Elements</literal> are
+ considered similar. By default an
+ <literal>ElementNameQualifier</literal> class is used that
+ compares the nth child <literal><![CDATA[<abc>]]></literal> test
+ element to the nth child <literal><![CDATA[<abc>]]></literal>
+ control element, i.e. the sequence of the child elements in the
+ test XML is important. However this default behaviour can be
+ overridden using an
+ <literal>ElementNameAndTextQualifier</literal> or
+ <literal>ElementNameAndAttributesQualifier</literal>.</para>
- <para>The test below demonstrates the use of a custom
- <literal>ElementQualifier</literal>:</para>
+ <para>The test below demonstrates the use of a custom
+ <literal>ElementQualifier</literal>:</para>
- <example><title>Using a custom <literal>ElementQualifier</literal></title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using a custom
+ <literal>ElementQualifier</literal></title>
+ <programlisting language="Java"><![CDATA[
public void testRepeatedChildElements() throws Exception {
String myControlXML = "<suite>"
+ "<test status=\"pass\">FirstTestCase</test>"
@@ -374,19 +384,19 @@
myDiff, true);
}]]></programlisting></example>
- </section>
+ </section>
- <section><title>Comparing XML Transformations</title>
+ <section><title>Comparing XML Transformations</title>
- <para>XMLUnit can test XSL transformations at a high level using
- the <literal>Transform</literal> class that wraps an
- <literal>javax.xml.transform.Transformer</literal>
- instance. Knowing the input XML, input stylesheet and expected
- output XML we can assert that the output of the transformation
- matches the expected output as follows:</para>
+ <para>XMLUnit can test XSL transformations at a high level using
+ the <literal>Transform</literal> class that wraps an
+ <literal>javax.xml.transform.Transformer</literal>
+ instance. Knowing the input XML, input stylesheet and expected
+ output XML we can assert that the output of the transformation
+ matches the expected output as follows:</para>
- <example><title>Testing the Result of a Transformation</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Testing the Result of a Transformation</title>
+ <programlisting language="Java"><![CDATA[
public void testXSLTransformation() throws Exception {
String myInputXML = "...";
File myStylesheetFile = new File("...");
@@ -396,14 +406,15 @@
assertTrue("XSL transformation worked as expected", myDiff.similar());
}]]></programlisting></example>
- <para>The <literal>getResultString()</literal> and
- <literal>getResultDocument()</literal> methods of the
- <literal>Transform</literal> class can be used to access the
- result of the XSL transformation programmatically if required, for
- example as below:</para>
+ <para>The <literal>getResultString()</literal> and
+ <literal>getResultDocument()</literal> methods of the
+ <literal>Transform</literal> class can be used to access the
+ result of the XSL transformation programmatically if required,
+ for example as below:</para>
- <example><title>Using <literal>Transform</literal> programmatically</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using <literal>Transform</literal>
+ programmatically</title>
+ <programlisting language="Java"><![CDATA[
public void testAnotherXSLTransformation() throws Exception {
File myInputXMLFile = new File("...");
File myStylesheetFile = new File("...");
@@ -418,21 +429,21 @@
assertTrue("XSL transformation worked as expected", myDiff.similar());
}]]></programlisting></example>
- </section>
+ </section>
- <section><title>Validation Tests</title>
+ <section><title>Validation Tests</title>
- <para>XML parsers that validate a piece of XML against a DTD are
- common, however they rely on a DTD reference being present in the
- XML, and they can only validate against a single DTD. When writing
- a system that exchanges XML messages with third parties there are
- times when you would like to validate the XML against a DTD that
- is not available to the recipient of the message and so cannot be
- referenced in the message itself. XMLUnit provides a
- <literal>Validator</literal> class for this purpose.</para>
+ <para>XML parsers that validate a piece of XML against a DTD are
+ common, however they rely on a DTD reference being present in
+ the XML, and they can only validate against a single DTD. When
+ writing a system that exchanges XML messages with third parties
+ there are times when you would like to validate the XML against
+ a DTD that is not available to the recipient of the message and
+ so cannot be referenced in the message itself. XMLUnit provides
+ a <literal>Validator</literal> class for this purpose.</para>
- <example><title>Validating Against a DTD</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Validating Against a DTD</title>
+ <programlisting language="Java"><![CDATA[
public void testValidation() throws Exception {
XMLUnit.getTestDocumentBuilderFactory().setValidating(true);
// As the document is parsed it is validated against its referenced DTD
@@ -450,18 +461,18 @@
or more XML Schema definitions. See <xref
linkend="validating-schema"/> for details.</para>
- </section>
+ </section>
- <section><title>Xpath Tests</title>
+ <section><title>Xpath Tests</title>
- <para>One of the strengths of XML is the ability to
- programmatically extract specific parts of a document using XPath
- expressions. The <literal>XMLTestCase</literal> class offers a
- number of XPath related assertion methods, as demonstrated in this
- test:</para>
+ <para>One of the strengths of XML is the ability to
+ programmatically extract specific parts of a document using
+ XPath expressions. The <literal>XMLTestCase</literal> class
+ offers a number of XPath related assertion methods, as
+ demonstrated in this test:</para>
- <example><title>Using Xpath Tests</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using Xpath Tests</title>
+ <programlisting language="Java"><![CDATA[
public void testXPaths() throws Exception {
String mySolarSystemXML = "<solar-system>"
+ "<planet name='Earth' position='3' supportsLife='yes'/>"
@@ -476,24 +487,24 @@
mySolarSystemXML);
}]]></programlisting></example>
- <para>When an XPath expression is evaluated against a piece of XML
- a <literal>NodeList</literal> is created that contains the
- matching <literal>Node</literal>s. The methods in the previous
- test <literal>assertXPathExists</literal>,
- <literal>assertNotXPathExists</literal>,
- <literal>assertXPathsEqual</literal>, and
- <literal>assertXPathsNotEqual</literal> use these
- <literal>NodeList</literal>s. However, the contents of a
- <literal>NodeList</literal> can be flattened (or
- <literal>String</literal>-ified) to a single value, and XMLUnit
- also allows assertions to be made about this single value, as in
- this test<footnote id="XpathEngine note"><para>Each of the
- <literal>assertXpath...()</literal> methods uses an implementation of the
- <literal>XpathEngine</literal> interface to evaluate an Xpath
- expression.</para></footnote>:</para>
+ <para>When an XPath expression is evaluated against a piece of
+ XML a <literal>NodeList</literal> is created that contains the
+ matching <literal>Node</literal>s. The methods in the previous
+ test <literal>assertXPathExists</literal>,
+ <literal>assertNotXPathExists</literal>,
+ <literal>assertXPathsEqual</literal>, and
+ <literal>assertXPathsNotEqual</literal> use these
+ <literal>NodeList</literal>s. However, the contents of a
+ <literal>NodeList</literal> can be flattened (or
+ <literal>String</literal>-ified) to a single value, and XMLUnit
+ also allows assertions to be made about this single value, as in
+ this test<footnote id="XpathEngine note"><para>Each of the
+ <literal>assertXpath...()</literal> methods uses an
+ implementation of the <literal>XpathEngine</literal> interface
+ to evaluate an Xpath expression.</para></footnote>:</para>
- <example><title>Testing Xpath Values</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Testing Xpath Values</title>
+ <programlisting language="Java"><![CDATA[
public void testXPathValues() throws Exception {
String myJavaFlavours = "<java-flavours>"
+ "<jvm current='some platforms'>1.1.x</jvm>"
@@ -508,27 +519,28 @@
"//jvm[3]/@current", myJavaFlavours);
}]]></programlisting></example>
- <para>Xpaths are especially useful where a document is made up
- largely of known, unchanging content with only a small amount of
- changing content created by the system. One of the main areas
- where constant "boilerplate" markup is combined with system
- generated markup is of course in web applications. The power of
- XPath expressions can make testing web page output quite trivial,
- and XMLUnit supplies a means of converting even very badly formed
- HTML into XML to aid this approach to testing.</para>
+ <para>Xpaths are especially useful where a document is made up
+ largely of known, unchanging content with only a small amount of
+ changing content created by the system. One of the main areas
+ where constant "boilerplate" markup is combined with system
+ generated markup is of course in web applications. The power of
+ XPath expressions can make testing web page output quite
+ trivial, and XMLUnit supplies a means of converting even very
+ badly formed HTML into XML to aid this approach to
+ testing.</para>
- <para>The <literal>HTMLDocumentBuilder</literal> class uses the
- Swing HTML parser to convert marked-up content to Sax events. The
- <literal>TolerantSaxDocumentBuilder</literal> class handles the
- Sax events to build up a DOM document in a tolerant fashion
- i.e. without mandating that opened elements are closed. (In a
- purely XML world this class would have no purpose as there are
- plenty of Sax event handlers that can build DOM documents from
- well formed content). The test below illustrates how the use of
- these classes:</para>
+ <para>The <literal>HTMLDocumentBuilder</literal> class uses the
+ Swing HTML parser to convert marked-up content to Sax
+ events. The <literal>TolerantSaxDocumentBuilder</literal> class
+ handles the Sax events to build up a DOM document in a tolerant
+ fashion i.e. without mandating that opened elements are
+ closed. (In a purely XML world this class would have no purpose
+ as there are plenty of Sax event handlers that can build DOM
+ documents from well formed content). The test below illustrates
+ how the use of these classes:</para>
- <example><title>Working with non well-formed HTML</title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Working with non well-formed HTML</title>
+ <programlisting language="Java"><![CDATA[
public void testXpathsInHTML() throws Exception {
String someBadlyFormedHTML = "<html><title>Ugh</title>"
+ "<body><h1>Heading<ul>"
@@ -543,36 +555,36 @@
wellFormedDocument);
}]]></programlisting></example>
- <para>One of the key points about using Xpaths with HTML content
- is that extracting values in tests requires the values to be
- identifiable. (This is just another way of saying that testing
- HTML is easier when it is written to be testable.) In the previous
- example id attributes were used to identify the list item values
- that needed to be testable, however class attributes or span and
- div tags can also be used to identify specific content for
- testing.</para>
+ <para>One of the key points about using Xpaths with HTML content
+ is that extracting values in tests requires the values to be
+ identifiable. (This is just another way of saying that testing
+ HTML is easier when it is written to be testable.) In the
+ previous example id attributes were used to identify the list
+ item values that needed to be testable, however class attributes
+ or span and div tags can also be used to identify specific
+ content for testing.</para>
- </section>
+ </section>
- <section><title>Testing by Tree Walking</title>
+ <section><title>Testing by Tree Walking</title>
- <para>The DOM specification allows a <literal>Document</literal>
- to optionally implement the <literal>DocumentTraversal</literal>
- interface. This interface allows an application to iterate over
- the <literal>Node</literal>s contained in a
- <literal>Document</literal>, or to "walk the DOM tree". The
- XMLUnit <literal>NodeTest</literal> class and
- <literal>NodeTester</literal> interface make use of
- <literal>DocumentTraversal</literal> to expose individual
- <literal>Node</literal>s in tests: the former handles the
- mechanics of iteration, and the latter allows custom test
- strategies to be implemented. A sample test strategy is supplied
- by the <literal>CountingNodeTester</literal> class that counts the
- nodes presented to it and compares the actual count to an expected
- count. The test below illustrates its use:</para>
+ <para>The DOM specification allows a <literal>Document</literal>
+ to optionally implement the <literal>DocumentTraversal</literal>
+ interface. This interface allows an application to iterate over
+ the <literal>Node</literal>s contained in a
+ <literal>Document</literal>, or to "walk the DOM tree". The
+ XMLUnit <literal>NodeTest</literal> class and
+ <literal>NodeTester</literal> interface make use of
+ <literal>DocumentTraversal</literal> to expose individual
+ <literal>Node</literal>s in tests: the former handles the
+ mechanics of iteration, and the latter allows custom test
+ strategies to be implemented. A sample test strategy is supplied
+ by the <literal>CountingNodeTester</literal> class that counts
+ the nodes presented to it and compares the actual count to an
+ expected count. The test below illustrates its use:</para>
- <example><title>Using <literal>CountingNodeTester</literal></title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using <literal>CountingNodeTester</literal></title>
+ <programlisting language="Java"><![CDATA[
public void testCountingNodeTester() throws Exception {
String testXML = "<fibonacci><val>1</val><val>2</val><val>3</val>"
+ "<val>5</val><val>9</val></fibonacci>";
@@ -580,34 +592,34 @@
assertNodeTestPasses(testXML, countingNodeTester, Node.TEXT_NODE);
}]]></programlisting></example>
- <para>This test fails as there are 5 text nodes, and JUnit
- supplies the following message:</para>
+ <para>This test fails as there are 5 text nodes, and JUnit
+ supplies the following message:</para>
- <programlisting>
+ <programlisting>
Expected node test to pass, but it failed! Counted 5 node(s) but
expected 4
- </programlisting>
+ </programlisting>
- <para>Note that if your DOM implementation does not support the
- <literal>DocumentTraversal</literal> interface then XMLUnit will
- throw an <literal>IllegalArgumentException</literal> informing you
- that you cannot use the <literal>NodeTest</literal> or
- <literal>NodeTester</literal> classes. Unfortunately even if your
- DOM implementation does support
- <literal>DocumentTraversal</literal>, attributes are not exposed
- by iteration: however they can be examined from the
- <literal>Element</literal> node that contains them.</para>
+ <para>Note that if your DOM implementation does not support the
+ <literal>DocumentTraversal</literal> interface then XMLUnit will
+ throw an <literal>IllegalArgumentException</literal> informing
+ you that you cannot use the <literal>NodeTest</literal> or
+ <literal>NodeTester</literal> classes. Unfortunately even if
+ your DOM implementation does support
+ <literal>DocumentTraversal</literal>, attributes are not exposed
+ by iteration: however they can be examined from the
+ <literal>Element</literal> node that contains them.</para>
- <para>While the previous test could have been easily performed
- using XPath, there are times when <literal>Node</literal>
- iteration is more powerful. In general, this is true when there
- are programmatic relationships between nodes that can be more
- easily tested iteratively. The following test uses a custom
- <literal>NodeTester</literal> class to illustrate the
- potential:</para>
+ <para>While the previous test could have been easily performed
+ using XPath, there are times when <literal>Node</literal>
+ iteration is more powerful. In general, this is true when there
+ are programmatic relationships between nodes that can be more
+ easily tested iteratively. The following test uses a custom
+ <literal>NodeTester</literal> class to illustrate the
+ potential:</para>
- <example><title>Using a Custom <literal>NodeTester</literal></title>
- <programlisting language="Java"><![CDATA[
+ <example><title>Using a Custom <literal>NodeTester</literal></title>
+ <programlisting language="Java"><![CDATA[
public void testCustomNodeTester() throws Exception {
String testXML = "<fibonacci><val>1</val><val>2</val><val>3</val>"
+ "<val>5</val><val>9</val></fibonacci>";
@@ -643,12 +655,12 @@
}
}]]></programlisting></example>
- <para>The test fails because the XML contains the wrong value for
- the last number in the sequence:</para>
+ <para>The test fails because the XML contains the wrong value
+ for the last number in the sequence:</para>
- <programlisting>
+ <programlisting>
Expected node test to pass, but it failed! Incorrect value [#text: 9]
- </programlisting>
+ </programlisting>
</section>
</section>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-03-23 04:40:11
|
Revision: 152
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=152&view=rev
Author: bodewig
Date: 2007-03-22 21:40:11 -0700 (Thu, 22 Mar 2007)
Log Message:
-----------
Add outline of planned doc
Modified Paths:
--------------
trunk/xmlunit/src/site/XMLUnit-Java.xml
Modified: trunk/xmlunit/src/site/XMLUnit-Java.xml
===================================================================
--- trunk/xmlunit/src/site/XMLUnit-Java.xml 2007-03-23 04:37:22 UTC (rev 151)
+++ trunk/xmlunit/src/site/XMLUnit-Java.xml 2007-03-23 04:40:11 UTC (rev 152)
@@ -2,7 +2,7 @@
<!DOCTYPE article PUBLIC "-//OASIS//DTD Simplified DocBook XML V1.1b1//EN" "http://docbook.org/xml/simple/1.1b1/sdocbook.dtd">
<article>
- <title>A Tour of XMLUnit
+ <title>XMLUnit Java User's Guide
<inlinemediaobject><imageobject>
<imagedata fileref="xmlunit.png" width="331" depth="100"
valign="middle" format="PNG"/>
@@ -15,6 +15,12 @@
<surname>Bacon</surname>
</author>
</authorgroup>
+ <authorgroup>
+ <author>
+ <firstname>Stefan</firstname>
+ <surname>Bodewig</surname>
+ </author>
+ </authorgroup>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
@@ -25,16 +31,31 @@
</author>
<revremark>Documentation for XMLUnit Java 1.0</revremark>
</revision>
+ <revision>
+ <revnumber>1.1</revnumber>
+ <date>... 2007</date>
+ <revremark>Documentation for XMLUnit Java 1.1</revremark>
+ </revision>
</revhistory>
</articleinfo>
+ <section><title>A Tour of XMLUnit</title>
+
+ <para>This first section contains a tour through XMLUnit's
+ features, the next sections will cover them in more detail.</para>
+
+ <para>Note that it has a strong focus on using the
+ <literal>XMLTestCase</literal> class which is one option to use
+ XMLUnit, but not the only one. XMLUnit's features can be fully
+ used without any dependency on JUnit at all.</para>
+
<section><title>What is XMLUnit?</title>
<para>XMLUnit enables JUnit-style assertions to be made about the
content and structure of XML<footnote id="more on JUnit"><para>For
more information on JUnit see <ulink
url="http://www.junit.org">http://www.junit.org</ulink></para></footnote>. It
- is an open source project hosted at http://xmlunit.sourceforge.net
+ is an open source project hosted at <ulink url="http://xmlunit.sourceforge.net/">http://xmlunit.sourceforge.net/</ulink>
that grew out of a need to test a system that generated and
received custom XML messages. The problem that we faced was how to
verify that the system generated the correct message from a known
@@ -67,7 +88,7 @@
(via <literal>Transform</literal> class)</listitem>
<listitem>The evaluation of an XPath expression on a piece of
- XML (via <literal>SimpleXpathEngine</literal> class)</listitem>
+ XML (via classes implementing the <literal>XpathEngine</literal> interface)</listitem>
<listitem>Individual nodes in a piece of XML that are exposed by
DOM Traversal (via <literal>NodeTest</literal> class)</listitem>
@@ -104,11 +125,13 @@
<section><title>Configuring XMLUnit</title>
<para>There are many Java XML parsers available, and XMLUnit
- should work with any JAXP compliant parser library, such as Xerces
- from the Apache Jakarta project. To use the XSL and XPath features
- of XMLUnit a Trax compliant transformation engine is required,
- such as Xalan, from the Apache Jakarta project. To configure
- XMLUnit to use your parser and transformation engine set three
+ should work with any JAXP compliant parser library, such as Xerces-J
+ <footnote id="xerces-link"><para><ulink url="http://xerces.apache.org/">http://xerces.apache.org/</ulink></para></footnote>
+ from the Apache Software Foundation. To use the XSL and XPath features
+ of XMLUnit a Trax (the XSLT portion of JAXP) compliant transformation engine is required,
+ such as Xalan-J<footnote id="xalan-link"><para><ulink url="http://xalan.apache.org/">http://xalan.apache.org/</ulink></para></footnote>,
+ from the Software Foundation. To configure
+ XMLUnit to use a specific parser and transformation engine set three
System properties before any tests are run, e.g.</para>
<example><title>Configuring JAXP via System Properties</title>
@@ -122,6 +145,16 @@
]]></programlisting>
</example>
+ <para>If you are using a JDK 1.4 or later, your Java class
+ library already contain the required XML parsers and XSLT
+ transformers. Still you may want to use a different
+ parser/transformer than the one of your JDK - in particular
+ since the versions shipping with some JDKs are known to contain
+ serious bugs. You may also want to review the <ulink
+ url="http://java.sun.com/j2se/1.4.2/docs/guide/standards/">Endorsed
+ Standards Override Mechanism</ulink> to use a different
+ parser/transformer than the one of your JDK.</para>
+
<para>Alternatively there are static methods on the XMLUnit class
that can be called directly. The advantage of this approach is
that you can specify a different parser class for control and test
@@ -137,6 +170,11 @@
XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");
]]></programlisting>
</example>
+
+ <para>The later approach should also work for JDK 1.4 and above,
+ even if you don't override the endorsed standards
+ libraries</para>
+
</section>
<section><title>Writing XML comparison tests</title>
@@ -407,6 +445,11 @@
myValidator.isValid());
}]]></programlisting></example>
+ <para>Starting with XMLUnit 1.1, the
+ <literal>Validator</literal> class can also validate against one
+ or more XML Schema definitions. See <xref
+ linkend="validating-schema"/> for details.</para>
+
</section>
<section><title>Xpath Tests</title>
@@ -444,9 +487,9 @@
<literal>NodeList</literal> can be flattened (or
<literal>String</literal>-ified) to a single value, and XMLUnit
also allows assertions to be made about this single value, as in
- this test<footnote id="SimpleXpathEngine note"><para>Each of the
- <literal>assertXpath...()</literal> methods uses the
- <literal>SimpleXpathEngine</literal> class to evaluate an Xpath
+ this test<footnote id="XpathEngine note"><para>Each of the
+ <literal>assertXpath...()</literal> methods uses an implementation of the
+ <literal>XpathEngine</literal> interface to evaluate an Xpath
expression.</para></footnote>:</para>
<example><title>Testing Xpath Values</title>
@@ -607,5 +650,112 @@
Expected node test to pass, but it failed! Incorrect value [#text: 9]
</programlisting>
+ </section>
</section>
+
+ <section id="Using"><title>Using XMLUnit</title>
+
+ <section id="using-plain">
+ <title>Basic Usage</title>
+
+ <section id="input-choices">
+ <title>Providing Input to XMLUnit</title>
+ </section>
+ </section>
+
+ <section id="junit3">
+ <title>Using XMLUnit With JUnit 3.x</title>
+ </section>
+ </section>
+
+ <section id="Comparing"><title>Comparing XML documents</title>
+
+ <section id="comparing-basics">
+ <title>The Difference Engine</title>
+ </section>
+
+ <section id="comparing-junit3">
+ <title>JUnit 3.x Convenience Methods</title>
+ </section>
+
+ <section id="comparing-config">
+ <title>Configuration Options</title>
+ </section>
+
+ <section id="ElementQualifier">
+ <title><literal>ElementQualifier</literal></title>
+ </section>
+
+ <section id="DifferenceListener">
+ <title><literal>DifferenceListener</literal></title>
+ </section>
+
+ <section id="ComparisonController">
+ <title><literal>ComparisonController</literal></title>
+ </section>
+ </section>
+
+ <section id="Validating"><title>Validating XML documents</title>
+
+ <section id="validating-basics">
+ <title>The <literal>Validator</literal> class</title>
+
+ <section id="validating-dtd">
+ <title>DTD Validation</title>
+ </section>
+
+ <section id="validating-schema">
+ <title>XML Schema Validation</title>
+ </section>
+ </section>
+
+ <section id="validation-junit3">
+ <title>JUnit 3.x Convenience Methods</title>
+ </section>
+
+ <section id="validation-config">
+ <title>Configuration Options</title>
+ </section>
+ </section>
+
+ <section id="XPath">
+ <title>XPath Tests</title>
+
+ <section id="xpath-engines">
+ <title>XPath Engines</title>
+ </section>
+
+ <section id="xpath-junit3">
+ <title>JUnit 3.x Convenience Methods</title>
+ </section>
+
+ <section id="xpath-config">
+ <title>Configuration Options</title>
+ </section>
+ </section>
+
+ <section id="NodeTest">
+ <title>DOM Tree Walking</title>
+ </section>
+
+ <appendix id="changes">
+ <title>Changes</title>
+
+ <section id="changes-1.1">
+ <title>Changes from XMLUnit 1.0 to 1.1</title>
+
+ <section id="breaking-changes-1.1">
+ <title>Breaking Changes</title>
+ </section>
+
+ <section id="features-1.1">
+ <title>New Features</title>
+ </section>
+
+ <section id="bugfixes-1.1">
+ <title>Bug Fixes</title>
+ </section>
+ </section>
+ </appendix>
+
</article>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-03-23 04:37:25
|
Revision: 151
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=151&view=rev
Author: bodewig
Date: 2007-03-22 21:37:22 -0700 (Thu, 22 Mar 2007)
Log Message:
-----------
fix issue 1683752
Modified Paths:
--------------
trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-03-22 17:11:11 UTC (rev 150)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-03-23 04:37:22 UTC (rev 151)
@@ -154,11 +154,7 @@
this.controlDoc = getManipulatedDocument(controlDoc);
this.testDoc = getManipulatedDocument(testDoc);
this.elementQualifierDelegate = elementQualifier;
- if (comparator == null) {
- this.differenceEngine = new DifferenceEngine(this);
- } else {
- this.differenceEngine = comparator;
- }
+ this.differenceEngine = comparator;
this.messages = new StringBuffer();
}
@@ -247,7 +243,8 @@
if (compared) {
return;
}
- differenceEngine.compare(controlDoc, testDoc, this, elementQualifierDelegate);
+ getDifferenceEngine().compare(controlDoc, testDoc, this,
+ elementQualifierDelegate);
compared = true;
}
@@ -401,4 +398,13 @@
this.elementQualifierDelegate = delegate;
}
+ /**
+ * Lazily initializes the difference engine if it hasn't been set
+ * via a constructor.
+ */
+ private DifferenceEngine getDifferenceEngine() {
+ return differenceEngine == null
+ ? new DifferenceEngine(this) : differenceEngine;
+ }
+
}
Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
===================================================================
--- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-22 17:11:11 UTC (rev 150)
+++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-23 04:37:22 UTC (rev 151)
@@ -179,7 +179,7 @@
assertEquals(3, l.size());
}
- public void XtestSeeAllDifferencesEvenIfDiffSaysHaltComparison() throws Exception {
+ public void testSeeAllDifferencesEvenIfDiffSaysHaltComparison() throws Exception {
String control = "<a><b/><c/></a>";
String test = "<a><c/></a>";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-03-22 17:11:12
|
Revision: 150
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=150&view=rev
Author: bodewig
Date: 2007-03-22 10:11:11 -0700 (Thu, 22 Mar 2007)
Log Message:
-----------
Test for issue 1683752
Modified Paths:
--------------
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
Modified: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
===================================================================
--- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-22 05:02:09 UTC (rev 149)
+++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java 2007-03-22 17:11:11 UTC (rev 150)
@@ -165,6 +165,33 @@
}
}
+
+ public void testSeeAllDifferencesEvenIfDiffWouldSayHaltComparison() throws Exception {
+ String control = "<a><b/><c/></a>";
+ String test = "<a><c/></a>";
+
+ Diff d = new Diff(control, test);
+ DetailedDiff dd = new DetailedDiff(d);
+
+ List l = dd.getAllDifferences();
+ // number of children is different, didn't find <b/>, wrong
+ // sequence of nodes
+ assertEquals(3, l.size());
+ }
+
+ public void XtestSeeAllDifferencesEvenIfDiffSaysHaltComparison() throws Exception {
+ String control = "<a><b/><c/></a>";
+ String test = "<a><c/></a>";
+
+ Diff d = new Diff(control, test);
+ d.similar();
+ DetailedDiff dd = new DetailedDiff(d);
+
+ List l = dd.getAllDifferences();
+ // number of children is different, didn't find <b/>, wrong
+ // sequence of nodes
+ assertEquals(3, l.size());
+ }
protected Diff buildDiff(Document control, Document test) {
return new DetailedDiff(super.buildDiff(control, test));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-03-22 05:02:14
|
Revision: 149
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=149&view=rev
Author: bodewig
Date: 2007-03-21 22:02:09 -0700 (Wed, 21 Mar 2007)
Log Message:
-----------
Add docbook version of user guide
Added Paths:
-----------
trunk/xmlunit/src/site/XMLUnit-Java.xml
Added: trunk/xmlunit/src/site/XMLUnit-Java.xml
===================================================================
--- trunk/xmlunit/src/site/XMLUnit-Java.xml (rev 0)
+++ trunk/xmlunit/src/site/XMLUnit-Java.xml 2007-03-22 05:02:09 UTC (rev 149)
@@ -0,0 +1,611 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD Simplified DocBook XML V1.1b1//EN" "http://docbook.org/xml/simple/1.1b1/sdocbook.dtd">
+
+<article>
+ <title>A Tour of XMLUnit
+ <inlinemediaobject><imageobject>
+ <imagedata fileref="xmlunit.png" width="331" depth="100"
+ valign="middle" format="PNG"/>
+ </imageobject></inlinemediaobject>
+ </title>
+ <articleinfo>
+ <authorgroup>
+ <author>
+ <firstname>Tim</firstname>
+ <surname>Bacon</surname>
+ </author>
+ </authorgroup>
+ <revhistory>
+ <revision>
+ <revnumber>1.0</revnumber>
+ <date>January 2003</date>
+ <author>
+ <firstname>Tim</firstname>
+ <surname>Bacon</surname>
+ </author>
+ <revremark>Documentation for XMLUnit Java 1.0</revremark>
+ </revision>
+ </revhistory>
+ </articleinfo>
+
+ <section><title>What is XMLUnit?</title>
+
+ <para>XMLUnit enables JUnit-style assertions to be made about the
+ content and structure of XML<footnote id="more on JUnit"><para>For
+ more information on JUnit see <ulink
+ url="http://www.junit.org">http://www.junit.org</ulink></para></footnote>. It
+ is an open source project hosted at http://xmlunit.sourceforge.net
+ that grew out of a need to test a system that generated and
+ received custom XML messages. The problem that we faced was how to
+ verify that the system generated the correct message from a known
+ set of inputs. Obviously we could use a DTD or a schema to
+ validate the message output, but this approach wouldn't allow us
+ to distinguish between valid XML with correct content (e.g.
+ element <literal><![CDATA[<foo>bar</foo>]]></literal>) and valid
+ XML with incorrect content (e.g. element
+ <literal><![CDATA[<foo>baz</foo>]]></literal>). What we really
+ wanted was an <literal>assertXMLEquals()</literal> method, so we
+ could compare the message that we expected the system to generate
+ and the message that the system actually generated. And that was
+ the beginning of XMLUnit.</para>
+ </section>
+ <section><title>Quick tour</title>
+
+ <para>XMLUnit provides a single JUnit extension class,
+ <literal>XMLTestCase</literal>, and a set of supporting classes
+ that allow assertions to be made about:</para>
+
+ <itemizedlist>
+ <listitem>The differences between two pieces of XML (via
+ <literal>Diff</literal> and <literal>DetailedDiff</literal>
+ classes)</listitem>
+
+ <listitem>The validity of a piece of XML (via
+ <literal>Validator</literal> class)</listitem>
+
+ <listitem> The outcome of transforming a piece of XML using XSLT
+ (via <literal>Transform</literal> class)</listitem>
+
+ <listitem>The evaluation of an XPath expression on a piece of
+ XML (via <literal>SimpleXpathEngine</literal> class)</listitem>
+
+ <listitem>Individual nodes in a piece of XML that are exposed by
+ DOM Traversal (via <literal>NodeTest</literal> class)</listitem>
+ </itemizedlist>
+
+ <para>XMLUnit can also treat HTML content, even badly-formed HTML,
+ as valid XML to allow these assertions to be made about web pages
+ (via the <literal>HTMLDocumentBuilder</literal> class).</para>
+ </section>
+
+ <section><title>Glossary</title>
+
+ <para>As with many projects some words in XMLUnit have particular
+ meanings so here is a quick overview. A <emphasis>piece</emphasis>
+ of XML is a DOM Document, a String containing marked-up content,
+ or a Source or Reader that allows access to marked-up content
+ within some resource. XMLUnit compares the expected
+ <emphasis>control</emphasis> XML to some actual
+ <emphasis>test</emphasis> XML. The comparison can reveal that two
+ pieces of XML are <emphasis>identical</emphasis>,
+ <emphasis>similar</emphasis> or
+ <emphasis>different</emphasis>. The unit of measurement used by
+ the comparison is a <emphasis>difference</emphasis>, and
+ differences can be either <emphasis>recoverable</emphasis> or
+ <emphasis>unrecoverable</emphasis>. Two pieces of XML are
+ <emphasis>identical</emphasis> if there are <emphasis>no
+ differences</emphasis> between them, <emphasis>similar</emphasis>
+ if there are <emphasis>only recoverable differences</emphasis>
+ between them, and <emphasis>different</emphasis> if there are
+ <emphasis>any unrecoverable differences</emphasis> between
+ them.</para>
+ </section>
+
+ <section><title>Configuring XMLUnit</title>
+
+ <para>There are many Java XML parsers available, and XMLUnit
+ should work with any JAXP compliant parser library, such as Xerces
+ from the Apache Jakarta project. To use the XSL and XPath features
+ of XMLUnit a Trax compliant transformation engine is required,
+ such as Xalan, from the Apache Jakarta project. To configure
+ XMLUnit to use your parser and transformation engine set three
+ System properties before any tests are run, e.g.</para>
+
+ <example><title>Configuring JAXP via System Properties</title>
+ <programlisting language="Java"><![CDATA[
+System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
+ "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+System.setProperty("javax.xml.parsers.SAXParserFactory",
+ "org.apache.xerces.jaxp.SAXParserFactoryImpl");
+System.setProperty("javax.xml.transform.TransformerFactory",
+ "org.apache.xalan.processor.TransformerFactoryImpl");
+]]></programlisting>
+ </example>
+
+ <para>Alternatively there are static methods on the XMLUnit class
+ that can be called directly. The advantage of this approach is
+ that you can specify a different parser class for control and test
+ XML and change the current parser class at any time in your tests,
+ should you need to make assertions about the compatibility of
+ different parsers.</para>
+
+<example><title>Configuring JAXP via XMLUnit class</title>
+ <programlisting language="Java"><![CDATA[
+XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");
+XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");
+]]></programlisting>
+ </example>
+ </section>
+
+ <section><title>Writing XML comparison tests</title>
+
+ <para>Let's say we have two pieces of XML that we wish to compare
+ and assert that they are equal. We could write a simple test class
+ like this:</para>
+
+ <example><title>A simple comparison test</title>
+ <programlisting language="Java"><![CDATA[
+public class MyXMLTestCase extends XMLTestCase {
+ public MyXMLTestCase(String name) {
+ super(name);
+ }
+
+ public void testForEquality() throws Exception {
+ String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>";
+ String myTestXML = "<msg><localId>2376</localId></msg>";
+ assertXMLEqual("Comparing test xml to control xml",
+ myControlXML, myTestXML);
+ }
+}]]></programlisting></example>
+
+ <para>The <literal>assertXMLEqual</literal> test will pass if the
+ control and test XML are either similar or identical. Obviously in
+ this case the pieces of XML are different and the test will
+ fail. The failure message indicates both what the difference is
+ and the Xpath locations of the nodes that were being
+ compared:</para>
+
+ <programlisting><![CDATA[
+Comparing test xml to control xml
+[different] Expected element tag name 'uuid' but was 'localId' - comparing <uuid...> at /msg[1]/uuid[1] to <localId...> at /msg[1]/localId[1]
+]]></programlisting>
+
+ <para>When comparing pieces of XML, the
+ <literal>XMLTestCase</literal> actually creates an instance of the
+ <literal>Diff</literal> class. The <literal>Diff</literal> class
+ stores the result of an XML comparison and makes it available
+ through the methods <literal>similar()</literal> and
+ <literal>identical()</literal>. The
+ <literal>assertXMLEquals()</literal> method tests the value of
+ <literal>Diff.similar()</literal> and the
+ <literal>assertXMLIdentical()</literal> method tests the value of
+ <literal>Diff.identical()</literal>.</para>
+
+ <para>It is easy to create a <literal>Diff</literal> instance
+ directly without using the <literal>XMLTestCase</literal> class as
+ below:</para>
+
+ <example><title>Creating a <literal>Diff</literal>
+ instance</title>
+ <programlisting language="Java"><![CDATA[
+public void testXMLIdentical()throws Exception {
+ String myControlXML =
+ "<struct><int>3</int><boolean>false</boolean></struct>";
+ String myTestXML =
+ "<struct><boolean>false</boolean><int>3</int></struct>";
+ Diff myDiff = new Diff(myControlXML, myTestXML);
+ assertTrue("XML similar " + myDiff.toString(),
+ myDiff.similar());
+ assertTrue("XML identical " + myDiff.toString(),
+ myDiff.identical());
+}]]></programlisting></example>
+
+ <para>This test fails as two pieces of XML are similar but not
+ identical if their nodes occur in a different sequence. The
+ failure message reported by JUnit from the call to
+ <literal>myDiff.toString()</literal> looks like this:</para>
+
+ <programlisting><![CDATA[
+[not identical] Expected sequence of child nodes '0' but was '1' - comparing <int...> at /struct[1]/int[1] to <int...> at /struct[1]/int[1]
+]]></programlisting>
+
+ <para>For efficiency reasons a <literal>Diff</literal> stops the
+ comparison process as soon as the first difference is found. To
+ get all the differences between two pieces of XML an instance of
+ the <literal>DetailedDiff</literal> class, a subclass of
+ <literal>Diff</literal>, is required. Note that a
+ <literal>DetailedDiff</literal> is constructed using an existing
+ <literal>Diff</literal> instance.</para>
+
+ <para>Consider this test that uses a DetailedDiff:</para>
+
+ <example><title>Using <literal>DetailedDiff</literal></title>
+ <programlisting language="Java"><![CDATA[
+public void testAllDifferences() throws Exception {
+ String myControlXML = "<news><item id=\"1\">War</item>"
+ + "<item id=\"2\">Plague</item>"
+ + "<item id=\"3\">Famine</item></news>";
+ String myTestXML = "<news><item id=\"1\">Peace</item>"
+ + "<item id=\"2\">Health</item>"
+ + "<item id=\"3\">Plenty</item></news>";
+ DetailedDiff myDiff = new DetailedDiff(new Diff(myControlXML, myTestXML));
+ List allDifferences = myDiff.getAllDifferences();
+ assertEquals(myDiff.toString(), 2, allDifferences.size());
+}]]></programlisting></example>
+
+ <para>This test fails with the message below as each of the 3 news
+ items differs between the control and test XML:</para>
+
+ <programlisting><![CDATA[
+[different] Expected text value 'War' but was 'Peace' - comparing <item...>War</item> at /news[1]/item[1]/text()[1] to <item...>Peace</item> at /news[1]/item[1]/text()[1]
+[different] Expected text value 'Plague' but was 'Health' - comparing <item...>Plague</item> at /news[1]/item[2]/text()[1] to <item...>Health</item> at /news[1]/item[2]/text()[1]
+[different] Expected text value 'Famine' but was 'Plenty' - comparing <item...>Famine</item> at /news[1]/item[3]/text()[1] to <item...>Plenty</item> at /news[1]/item[3]/text()[1]
+expected <2> but was <3>
+]]></programlisting>
+
+ <para>The List returned from the
+ <literal>getAllDifferences()</literal> method contains
+ <literal>Difference</literal> instances. These instances describe
+ both the type<footnote id="DifferenceConstants"><para>A full set
+ of prototype <literal>Difference</literal> instances - one for
+ each type of difference - is defined using final static fields in
+ the <literal>DifferenceConstants</literal>
+ class.</para></footnote> of difference found between a control
+ node and test node and the <literal>NodeDetail</literal> of those
+ nodes (including the XPath location of each
+ node). <literal>Difference</literal> instances are passed at
+ runtime in notification events to a registered
+ <literal>DifferenceListener</literal>, an interface whose default
+ implementation is provided by the <literal>Diff</literal>
+ class.</para>
+
+ <para>However it is possible to override this default behaviour by
+ implementing the interface in your own class. The
+ <literal>IgnoreTextAndAttributeValuesDifferenceListener</literal>
+ class is an example of how to implement a custom
+ <literal>DifferenceListener</literal>. It allows an XML comparison
+ to be made that ignores differences in the values of text and
+ attribute nodes, for example when comparing a skeleton or outline
+ piece of XML to some generated XML.</para>
+
+ <para>The following test illustrates the use of a custom
+ <literal>DifferenceListener</literal>:</para>
+
+ <example><title>Using a custom
+ <literal>DifferenceListener</literal></title>
+ <programlisting language="Java"><![CDATA[
+public void testCompareToSkeletonXML() throws Exception {
+ String myControlXML = "<location><street-address>22 any street</street-address><postcode>XY00 99Z</postcode></location>";
+ String myTestXML = "<location><street-address>20 east cheap</street-address><postcode>EC3M 1EB</postcode></location>";
+ DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
+ Diff myDiff = new Diff(myControlXML, myTestXML);
+ myDiff.overrideDifferenceListener(myDifferenceListener);
+ assertTrue("test XML matches control skeleton XML",
+ myDiff.similar());
+}]]></programlisting></example>
+
+ <para>The <literal>DifferenceEngine</literal> class generates the
+ events that are passed to a <literal>DifferenceListener</literal>
+ implementation as two pieces of XML are compared. Using recursion
+ it navigates through the nodes in the control XML DOM, and
+ determines which node in the test XML DOM qualifies for comparison
+ to the current control node. The qualifying test node will match
+ the control node's node type, as well as the node name and
+ namespace (if defined for the control node).</para>
+
+ <para>However when the control node is an
+ <literal>Element</literal>, it is less straightforward to
+ determine which test <literal>Element</literal> qualifies for
+ comparison as the parent node may contain repeated child
+ <literal>Element</literal>s with the same name and namespace. So
+ for <literal>Element</literal> nodes, an instance of the
+ <literal>ElementQualifier</literal> interface is used determine
+ whether a given test <literal>Element</literal> node qualifies for
+ comparison with a control <literal>Element</literal> node. This
+ separates the decision about whether two
+ <literal>Elements</literal> should be compared from the decision
+ about whether those two <literal>Elements</literal> are considered
+ similar. By default an <literal>ElementNameQualifier</literal>
+ class is used that compares the nth child
+ <literal><![CDATA[<abc>]]></literal> test element to the nth child
+ <literal><![CDATA[<abc>]]></literal> control element, i.e. the
+ sequence of the child elements in the test XML is
+ important. However this default behaviour can be overridden using
+ an <literal>ElementNameAndTextQualifier</literal> or
+ <literal>ElementNameAndAttributesQualifier</literal>.</para>
+
+ <para>The test below demonstrates the use of a custom
+ <literal>ElementQualifier</literal>:</para>
+
+ <example><title>Using a custom <literal>ElementQualifier</literal></title>
+ <programlisting language="Java"><![CDATA[
+public void testRepeatedChildElements() throws Exception {
+ String myControlXML = "<suite>"
+ + "<test status=\"pass\">FirstTestCase</test>"
+ + "<test status=\"pass\">SecondTestCase</test></suite>";
+ String myTestXML = "<suite>"
+ + "<test status=\"pass\">SecondTestCase</test>"
+ + "<test status=\"pass\">FirstTestCase</test></suite>";
+ assertXMLNotEqual("Repeated child elements in different sequence order are not equal by default",
+ myControlXML, myTestXML);
+ Diff myDiff = new Diff(myControlXML, myTestXML);
+ myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
+ assertXMLEqual("But they are equal when an ElementQualifier controls which test element is compared with each control element",
+ myDiff, true);
+}]]></programlisting></example>
+
+ </section>
+
+ <section><title>Comparing XML Transformations</title>
+
+ <para>XMLUnit can test XSL transformations at a high level using
+ the <literal>Transform</literal> class that wraps an
+ <literal>javax.xml.transform.Transformer</literal>
+ instance. Knowing the input XML, input stylesheet and expected
+ output XML we can assert that the output of the transformation
+ matches the expected output as follows:</para>
+
+ <example><title>Testing the Result of a Transformation</title>
+ <programlisting language="Java"><![CDATA[
+public void testXSLTransformation() throws Exception {
+ String myInputXML = "...";
+ File myStylesheetFile = new File("...");
+ Transform myTransform = new Transform(myInputXML, myStylesheetFile);
+ String myExpectedOutputXML = "...";
+ Diff myDiff = new Diff(myExpectedOutputXML, myTransform);
+ assertTrue("XSL transformation worked as expected", myDiff.similar());
+}]]></programlisting></example>
+
+ <para>The <literal>getResultString()</literal> and
+ <literal>getResultDocument()</literal> methods of the
+ <literal>Transform</literal> class can be used to access the
+ result of the XSL transformation programmatically if required, for
+ example as below:</para>
+
+ <example><title>Using <literal>Transform</literal> programmatically</title>
+ <programlisting language="Java"><![CDATA[
+public void testAnotherXSLTransformation() throws Exception {
+ File myInputXMLFile = new File("...");
+ File myStylesheetFile = new File("...");
+ Transform myTransform = new Transform(
+ new StreamSource(myInputXMLFile),
+ new StreamSource(myStylesheetFile));
+ Document myExpectedOutputXML =
+ XMLUnit.buildDocument(XMLUnit.getControlParser(),
+ new FileReader("..."));
+ Diff myDiff = new Diff(myExpectedOutputXML,
+ myTransform.getResultDocument());
+ assertTrue("XSL transformation worked as expected", myDiff.similar());
+}]]></programlisting></example>
+
+ </section>
+
+ <section><title>Validation Tests</title>
+
+ <para>XML parsers that validate a piece of XML against a DTD are
+ common, however they rely on a DTD reference being present in the
+ XML, and they can only validate against a single DTD. When writing
+ a system that exchanges XML messages with third parties there are
+ times when you would like to validate the XML against a DTD that
+ is not available to the recipient of the message and so cannot be
+ referenced in the message itself. XMLUnit provides a
+ <literal>Validator</literal> class for this purpose.</para>
+
+ <example><title>Validating Against a DTD</title>
+ <programlisting language="Java"><![CDATA[
+public void testValidation() throws Exception {
+ XMLUnit.getTestDocumentBuilderFactory().setValidating(true);
+ // As the document is parsed it is validated against its referenced DTD
+ Document myTestDocument = XMLUnit.buildTestDocument("...");
+ String mySystemId = "...";
+ String myDTDUrl = new File("...").toURL().toExternalForm();
+ Validator myValidator = new Validator(myTestDocument, mySystemId,
+ myDTDUrl);
+ assertTrue("test document validates against unreferenced DTD",
+ myValidator.isValid());
+}]]></programlisting></example>
+
+ </section>
+
+ <section><title>Xpath Tests</title>
+
+ <para>One of the strengths of XML is the ability to
+ programmatically extract specific parts of a document using XPath
+ expressions. The <literal>XMLTestCase</literal> class offers a
+ number of XPath related assertion methods, as demonstrated in this
+ test:</para>
+
+ <example><title>Using Xpath Tests</title>
+ <programlisting language="Java"><![CDATA[
+public void testXPaths() throws Exception {
+ String mySolarSystemXML = "<solar-system>"
+ + "<planet name='Earth' position='3' supportsLife='yes'/>"
+ + "<planet name='Venus' position='4'/></solar-system>";
+ assertXpathExists("//planet[@name='Earth']", mySolarSystemXML);
+ assertNotXpathExists("//star[@name='alpha centauri']",
+ mySolarSystemXML);
+ assertXpathsEqual("//planet[@name='Earth']",
+ "//planet[@position='3']", mySolarSystemXML);
+ assertXpathsNotEqual("//planet[@name='Venus']",
+ "//planet[@supportsLife='yes']",
+ mySolarSystemXML);
+}]]></programlisting></example>
+
+ <para>When an XPath expression is evaluated against a piece of XML
+ a <literal>NodeList</literal> is created that contains the
+ matching <literal>Node</literal>s. The methods in the previous
+ test <literal>assertXPathExists</literal>,
+ <literal>assertNotXPathExists</literal>,
+ <literal>assertXPathsEqual</literal>, and
+ <literal>assertXPathsNotEqual</literal> use these
+ <literal>NodeList</literal>s. However, the contents of a
+ <literal>NodeList</literal> can be flattened (or
+ <literal>String</literal>-ified) to a single value, and XMLUnit
+ also allows assertions to be made about this single value, as in
+ this test<footnote id="SimpleXpathEngine note"><para>Each of the
+ <literal>assertXpath...()</literal> methods uses the
+ <literal>SimpleXpathEngine</literal> class to evaluate an Xpath
+ expression.</para></footnote>:</para>
+
+ <example><title>Testing Xpath Values</title>
+ <programlisting language="Java"><![CDATA[
+public void testXPathValues() throws Exception {
+ String myJavaFlavours = "<java-flavours>"
+ + "<jvm current='some platforms'>1.1.x</jvm>"
+ + "<jvm current='no'>1.2.x</jvm>"
+ + "<jvm current='yes'>1.3.x</jvm>"
+ + "<jvm current='yes' latest='yes'>1.4.x</jvm></javaflavours>";
+ assertXpathEvaluatesTo("2", "count(//jvm[@current='yes'])",
+ myJavaFlavours);
+ assertXpathValuesEqual("//jvm[4]/@latest", "//jvm[4]/@current",
+ myJavaFlavours);
+ assertXpathValuesNotEqual("//jvm[2]/@current",
+ "//jvm[3]/@current", myJavaFlavours);
+}]]></programlisting></example>
+
+ <para>Xpaths are especially useful where a document is made up
+ largely of known, unchanging content with only a small amount of
+ changing content created by the system. One of the main areas
+ where constant "boilerplate" markup is combined with system
+ generated markup is of course in web applications. The power of
+ XPath expressions can make testing web page output quite trivial,
+ and XMLUnit supplies a means of converting even very badly formed
+ HTML into XML to aid this approach to testing.</para>
+
+ <para>The <literal>HTMLDocumentBuilder</literal> class uses the
+ Swing HTML parser to convert marked-up content to Sax events. The
+ <literal>TolerantSaxDocumentBuilder</literal> class handles the
+ Sax events to build up a DOM document in a tolerant fashion
+ i.e. without mandating that opened elements are closed. (In a
+ purely XML world this class would have no purpose as there are
+ plenty of Sax event handlers that can build DOM documents from
+ well formed content). The test below illustrates how the use of
+ these classes:</para>
+
+ <example><title>Working with non well-formed HTML</title>
+ <programlisting language="Java"><![CDATA[
+public void testXpathsInHTML() throws Exception {
+ String someBadlyFormedHTML = "<html><title>Ugh</title>"
+ + "<body><h1>Heading<ul>"
+ + "<li id='1'>Item One<li id='2'>Item Two";
+ TolerantSaxDocumentBuilder tolerantSaxDocumentBuilder =
+ new TolerantSaxDocumentBuilder(XMLUnit.getTestParser());
+ HTMLDocumentBuilder htmlDocumentBuilder =
+ new HTMLDocumentBuilder(tolerantSaxDocumentBuilder);
+ Document wellFormedDocument =
+ htmlDocumentBuilder.parse(someBadlyFormedHTML);
+ assertXpathEvaluatesTo("Item One", "/html/body//li[@id='1']",
+ wellFormedDocument);
+}]]></programlisting></example>
+
+ <para>One of the key points about using Xpaths with HTML content
+ is that extracting values in tests requires the values to be
+ identifiable. (This is just another way of saying that testing
+ HTML is easier when it is written to be testable.) In the previous
+ example id attributes were used to identify the list item values
+ that needed to be testable, however class attributes or span and
+ div tags can also be used to identify specific content for
+ testing.</para>
+
+ </section>
+
+ <section><title>Testing by Tree Walking</title>
+
+ <para>The DOM specification allows a <literal>Document</literal>
+ to optionally implement the <literal>DocumentTraversal</literal>
+ interface. This interface allows an application to iterate over
+ the <literal>Node</literal>s contained in a
+ <literal>Document</literal>, or to "walk the DOM tree". The
+ XMLUnit <literal>NodeTest</literal> class and
+ <literal>NodeTester</literal> interface make use of
+ <literal>DocumentTraversal</literal> to expose individual
+ <literal>Node</literal>s in tests: the former handles the
+ mechanics of iteration, and the latter allows custom test
+ strategies to be implemented. A sample test strategy is supplied
+ by the <literal>CountingNodeTester</literal> class that counts the
+ nodes presented to it and compares the actual count to an expected
+ count. The test below illustrates its use:</para>
+
+ <example><title>Using <literal>CountingNodeTester</literal></title>
+ <programlisting language="Java"><![CDATA[
+public void testCountingNodeTester() throws Exception {
+ String testXML = "<fibonacci><val>1</val><val>2</val><val>3</val>"
+ + "<val>5</val><val>9</val></fibonacci>";
+ CountingNodeTester countingNodeTester = new CountingNodeTester(4);
+ assertNodeTestPasses(testXML, countingNodeTester, Node.TEXT_NODE);
+}]]></programlisting></example>
+
+ <para>This test fails as there are 5 text nodes, and JUnit
+ supplies the following message:</para>
+
+ <programlisting>
+Expected node test to pass, but it failed! Counted 5 node(s) but
+expected 4
+ </programlisting>
+
+ <para>Note that if your DOM implementation does not support the
+ <literal>DocumentTraversal</literal> interface then XMLUnit will
+ throw an <literal>IllegalArgumentException</literal> informing you
+ that you cannot use the <literal>NodeTest</literal> or
+ <literal>NodeTester</literal> classes. Unfortunately even if your
+ DOM implementation does support
+ <literal>DocumentTraversal</literal>, attributes are not exposed
+ by iteration: however they can be examined from the
+ <literal>Element</literal> node that contains them.</para>
+
+ <para>While the previous test could have been easily performed
+ using XPath, there are times when <literal>Node</literal>
+ iteration is more powerful. In general, this is true when there
+ are programmatic relationships between nodes that can be more
+ easily tested iteratively. The following test uses a custom
+ <literal>NodeTester</literal> class to illustrate the
+ potential:</para>
+
+ <example><title>Using a Custom <literal>NodeTester</literal></title>
+ <programlisting language="Java"><![CDATA[
+public void testCustomNodeTester() throws Exception {
+ String testXML = "<fibonacci><val>1</val><val>2</val><val>3</val>"
+ + "<val>5</val><val>9</val></fibonacci>";
+ NodeTest nodeTest = new NodeTest(testXML);
+ assertNodeTestPasses(nodeTest, new FibonacciNodeTester(),
+ new short[] {Node.TEXT_NODE,
+ Node.ELEMENT_NODE},
+ true);
+}
+
+private class FibonacciNodeTester extends AbstractNodeTester {
+ private int nextVal = 1, lastVal = 1, priorVal = 0;
+
+ public void testText(Text text) throws NodeTestException {
+ int val = Integer.parseInt(text.getData());
+ if (nextVal != val) {
+ throw new NodeTestException("Incorrect value", text);
+ }
+ nextVal = val + lastVal;
+ priorVal = lastVal;
+ lastVal = val;
+ }
+
+ public void testElement(Element element) throws NodeTestException {
+ String name = element.getLocalName();
+ if ("fibonacci".equals(name) || "val".equals(name)) {
+ return;
+ }
+ throw new NodeTestException("Unexpected element", element);
+ }
+
+ public void noMoreNodes(NodeTest nodeTest) throws NodeTestException {
+ }
+}]]></programlisting></example>
+
+ <para>The test fails because the XML contains the wrong value for
+ the last number in the sequence:</para>
+
+ <programlisting>
+Expected node test to pass, but it failed! Incorrect value [#text: 9]
+ </programlisting>
+
+ </section>
+</article>
Property changes on: trunk/xmlunit/src/site/XMLUnit-Java.xml
___________________________________________________________________
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...> - 2007-02-22 05:17:14
|
Revision: 148
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=148&view=rev
Author: bodewig
Date: 2007-02-21 21:17:08 -0800 (Wed, 21 Feb 2007)
Log Message:
-----------
Make XMLTestCase abstract
Modified Paths:
--------------
trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2007-02-05 19:47:29 UTC (rev 147)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2007-02-22 05:17:08 UTC (rev 148)
@@ -60,7 +60,7 @@
* @see Diff#identical()
* <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a>
*/
-public class XMLTestCase extends TestCase implements XSLTConstants {
+public abstract class XMLTestCase extends TestCase implements XSLTConstants {
/**
* Construct a new XML test case.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bo...@us...> - 2007-02-05 19:47:45
|
Revision: 147
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=147&view=rev
Author: bodewig
Date: 2007-02-05 11:47:29 -0800 (Mon, 05 Feb 2007)
Log Message:
-----------
Fix indentation and remove tabs:
(defun fixup-file ()
(interactive)
(save-excursion
(let ((start (or (re-search-forward "package")
(point-min))))
(indent-region start (point-max) nil)
(untabify (point-min) (point-max)))))
Modified Paths:
--------------
trunk/xmlunit/src/java/org/custommonkey/xmlunit/AbstractNodeTester.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java
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/Difference.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceConstants.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndTextQualifier.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameQualifier.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementQualifier.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/HTMLDocumentBuilder.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/IgnoreTextAndAttributeValuesDifferenceListener.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDescriptor.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDetail.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeInputStream.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTestException.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/TolerantSaxDocumentBuilder.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLAssert.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java
trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/Replacement.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/SimpleSerializer.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_MultiLevelElementNameAndTextQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/jaxp13/test_Jaxp13XpathEngine.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_BugFixes.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Constants.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DetailedDiff.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Diff.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Difference.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DifferenceEngine.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_DoctypeReader.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_ElementNameAndAttributeQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_ElementNameAndTextQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_ElementNameQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_HTMLDocumentBuilder.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_JAXP_1_2_Schema_Validation.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_NodeDescriptor.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_NodeTest.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Replacement.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_SimpleXpathEngine.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_TolerantSaxDocumentBuilder.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Transform.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_Validator.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_XMLTestCase.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_XMLUnit.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_XpathNodeTracker.java
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/AbstractNodeTester.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/AbstractNodeTester.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/AbstractNodeTester.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -71,41 +71,41 @@
*/
public void testNode(Node aNode, NodeTest forTest) throws NodeTestException {
switch (aNode.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- // should not happen as attributes are not exposed by DOM traversal
- testAttribute((Attr)aNode);
- break;
- case Node.CDATA_SECTION_NODE:
- testCDATASection((CDATASection)aNode);
- break;
- case Node.COMMENT_NODE:
- testComment((Comment)aNode);
- break;
- case Node.DOCUMENT_TYPE_NODE:
- testDocumentType((DocumentType)aNode);
- break;
- case Node.ELEMENT_NODE:
- testElement((Element)aNode);
- break;
- case Node.ENTITY_NODE:
- testEntity((Entity)aNode);
- break;
- case Node.ENTITY_REFERENCE_NODE:
- testEntityReference((EntityReference)aNode);
- break;
- case Node.NOTATION_NODE:
- testNotation((Notation)aNode);
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- testProcessingInstruction(
- (ProcessingInstruction) aNode);
- break;
- case Node.TEXT_NODE:
- testText((Text)aNode);
- break;
- default:
- throw new NodeTestException("No delegate method for Node type",
- aNode);
+ case Node.ATTRIBUTE_NODE:
+ // should not happen as attributes are not exposed by DOM traversal
+ testAttribute((Attr)aNode);
+ break;
+ case Node.CDATA_SECTION_NODE:
+ testCDATASection((CDATASection)aNode);
+ break;
+ case Node.COMMENT_NODE:
+ testComment((Comment)aNode);
+ break;
+ case Node.DOCUMENT_TYPE_NODE:
+ testDocumentType((DocumentType)aNode);
+ break;
+ case Node.ELEMENT_NODE:
+ testElement((Element)aNode);
+ break;
+ case Node.ENTITY_NODE:
+ testEntity((Entity)aNode);
+ break;
+ case Node.ENTITY_REFERENCE_NODE:
+ testEntityReference((EntityReference)aNode);
+ break;
+ case Node.NOTATION_NODE:
+ testNotation((Notation)aNode);
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ testProcessingInstruction(
+ (ProcessingInstruction) aNode);
+ break;
+ case Node.TEXT_NODE:
+ testText((Text)aNode);
+ break;
+ default:
+ throw new NodeTestException("No delegate method for Node type",
+ aNode);
}
}
@@ -191,7 +191,7 @@
}
private void unhandled(Node aNode) throws NodeTestException {
- throw new NodeTestException("Test fails by default in AbstractNodeTester", aNode);
+ throw new NodeTestException("Test fails by default in AbstractNodeTester", aNode);
}
/**
@@ -201,7 +201,7 @@
* @exception NodeTestException if mode Nodes were expected
*/
public void noMoreNodes(NodeTest forTest) throws NodeTestException {
- //by default do nothing
+ //by default do nothing
}
}
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -74,7 +74,7 @@
resetCounter();
if (testedNodes != expectedNumNodes) {
throw new NodeTestException("Counted " + testedNodes
- + " node(s) but expected " + expectedNumNodes);
+ + " node(s) but expected " + expectedNumNodes);
}
}
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -75,13 +75,13 @@
final int returnValue = super.differenceFound(difference);
Difference localDifference = null;
switch (returnValue) {
- case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL:
- return returnValue;
- case RETURN_ACCEPT_DIFFERENCE:
- break;
- case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR:
- difference.setRecoverable(true);
- break;
+ case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL:
+ return returnValue;
+ case RETURN_ACCEPT_DIFFERENCE:
+ break;
+ case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR:
+ difference.setRecoverable(true);
+ break;
}
allDifferences.add(difference);
return returnValue;
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -72,7 +72,7 @@
* <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a>
*/
public class Diff
-implements DifferenceListener, ComparisonController {
+ implements DifferenceListener, ComparisonController {
private final Document controlDoc;
private final Document testDoc;
private boolean similar = true;
@@ -98,7 +98,7 @@
public Diff(Reader control, Reader test)
throws SAXException, IOException {
this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control),
- XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
+ XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
}
/**
@@ -115,17 +115,17 @@
public Diff(String control, Transform testTransform)
throws IOException, TransformerException, SAXException {
this(XMLUnit.buildControlDocument(control),
- testTransform.getResultDocument());
+ testTransform.getResultDocument());
}
- /**
- * Construct a Diff that compares the XML read from two JAXP InputSources
- */
+ /**
+ * Construct a Diff that compares the XML read from two JAXP InputSources
+ */
public Diff(InputSource control, InputSource test)
throws SAXException, IOException {
- this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control),
- XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
- }
+ this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control),
+ XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
+ }
/**
* Construct a Diff that compares the XML in two JAXP DOMSources
@@ -155,9 +155,9 @@
this.testDoc = getManipulatedDocument(testDoc);
this.elementQualifierDelegate = elementQualifier;
if (comparator == null) {
- this.differenceEngine = new DifferenceEngine(this);
+ this.differenceEngine = new DifferenceEngine(this);
} else {
- this.differenceEngine = comparator;
+ this.differenceEngine = comparator;
}
this.messages = new StringBuffer();
}
@@ -168,8 +168,8 @@
* @param prototype a prototypical instance
*/
protected Diff(Diff prototype) {
- this(prototype.controlDoc, prototype.testDoc, prototype.differenceEngine,
- prototype.elementQualifierDelegate);
+ this(prototype.controlDoc, prototype.testDoc, prototype.differenceEngine,
+ prototype.elementQualifierDelegate);
}
/**
@@ -186,7 +186,7 @@
}
try {
Transform whitespaceStripper = XMLUnit.getStripWhitespaceTransform(
- originalDoc);
+ originalDoc);
return whitespaceStripper.getResultDocument();
} catch (TransformerException e) {
throw new XMLUnitRuntimeException(e.getMessage(), e.getCause());
@@ -301,24 +301,24 @@
}
switch (returnValue) {
- case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL:
- return returnValue;
- case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR:
- identical = false;
+ case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL:
+ return returnValue;
+ case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR:
+ identical = false;
+ haltComparison = false;
+ break;
+ case RETURN_ACCEPT_DIFFERENCE:
+ identical = false;
+ if (difference.isRecoverable()) {
haltComparison = false;
- break;
- case RETURN_ACCEPT_DIFFERENCE:
- identical = false;
- if (difference.isRecoverable()) {
- haltComparison = false;
- } else {
- similar = false;
- haltComparison = true;
- }
- break;
- default:
- throw new IllegalArgumentException(returnValue
- + " is not a defined DifferenceListener.RETURN_... value");
+ } else {
+ similar = false;
+ haltComparison = true;
+ }
+ break;
+ default:
+ throw new IllegalArgumentException(returnValue
+ + " is not a defined DifferenceListener.RETURN_... value");
}
if (haltComparison) {
messages.append("\n[different]");
@@ -342,8 +342,8 @@
differenceListenerDelegate.skippedComparison(control, test);
} else {
System.err.println("DifferenceListener.skippedComparison: "
- + "unhandled control node type=" + control
- + ", unhandled test node type=" + test);
+ + "unhandled control node type=" + control
+ + ", unhandled test node type=" + test);
}
}
@@ -392,13 +392,13 @@
this.differenceListenerDelegate = delegate;
}
- /**
- * Override the <code>ElementQualifier</code> used to determine which
- * control and test nodes are comparable for this difference comparison.
- * @param delegate the ElementQualifier instance to delegate to.
- */
- public void overrideElementQualifier(ElementQualifier delegate) {
- this.elementQualifierDelegate = delegate;
- }
+ /**
+ * Override the <code>ElementQualifier</code> used to determine which
+ * control and test nodes are comparable for this difference comparison.
+ * @param delegate the ElementQualifier instance to delegate to.
+ */
+ public void overrideElementQualifier(ElementQualifier delegate) {
+ this.elementQualifierDelegate = delegate;
+ }
}
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -80,7 +80,7 @@
* encountered NodeDetails
*/
protected Difference(Difference prototype, NodeDetail controlNodeDetail,
- NodeDetail testNodeDetail) {
+ NodeDetail testNodeDetail) {
this(prototype.getId(), prototype.getDescription(), prototype.isRecoverable());
this.controlNodeDetail = controlNodeDetail;
this.testNodeDetail = testNodeDetail;
@@ -113,7 +113,7 @@
* a DetailedDiff.
*/
protected void setRecoverable(boolean overrideValue) {
- recoverable = overrideValue;
+ recoverable = overrideValue;
}
/**
@@ -121,7 +121,7 @@
* at the Node where this difference was encountered
*/
public NodeDetail getControlNodeDetail() {
- return controlNodeDetail;
+ return controlNodeDetail;
}
/**
@@ -129,7 +129,7 @@
* at the Node where this difference was encountered
*/
public NodeDetail getTestNodeDetail() {
- return testNodeDetail;
+ return testNodeDetail;
}
/**
@@ -153,22 +153,22 @@
* their details also
*/
public String toString() {
- StringBuffer buf = new StringBuffer();
- if (controlNodeDetail == null || testNodeDetail == null) {
- appendBasicRepresentation(buf);
- } else {
- appendDetailedRepresentation(buf);
- }
+ StringBuffer buf = new StringBuffer();
+ if (controlNodeDetail == null || testNodeDetail == null) {
+ appendBasicRepresentation(buf);
+ } else {
+ appendDetailedRepresentation(buf);
+ }
return buf.toString();
}
private void appendBasicRepresentation(StringBuffer buf) {
buf.append("Difference (#").append(id).
- append(") ").append(description);
+ append(") ").append(description);
}
private void appendDetailedRepresentation(StringBuffer buf) {
- buf.append("Expected ").append(getDescription())
+ buf.append("Expected ").append(getDescription())
.append(" '").append(controlNodeDetail.getValue())
.append("' but was '").append(testNodeDetail.getValue())
.append("' - comparing ");
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceConstants.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceConstants.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceConstants.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -42,53 +42,53 @@
* <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a>
*/
public interface DifferenceConstants {
- /** Comparing an implied attribute value against an explicit value */
- int ATTR_VALUE_EXPLICITLY_SPECIFIED_ID = 1;
- /** Comparing 2 elements and one has an attribute the other does not */
- int ATTR_NAME_NOT_FOUND_ID = 2;
- /** Comparing 2 attributes with the same name but different values */
- int ATTR_VALUE_ID = 3;
- /** Comparing 2 attribute lists with the same attributes in different sequence */
- int ATTR_SEQUENCE_ID = 4;
- /** Comparing 2 CDATA sections with different values */
- int CDATA_VALUE_ID = 5;
- /** Comparing 2 comments with different values */
- int COMMENT_VALUE_ID = 6;
- /** Comparing 2 document types with different names */
- int DOCTYPE_NAME_ID = 7;
- /** Comparing 2 document types with different public identifiers */
- int DOCTYPE_PUBLIC_ID_ID = 8;
- /** Comparing 2 document types with different system identifiers */
- int DOCTYPE_SYSTEM_ID_ID = 9;
- /** Comparing 2 elements with different tag names */
- int ELEMENT_TAG_NAME_ID = 10;
- /** Comparing 2 elements with different number of attributes */
- int ELEMENT_NUM_ATTRIBUTES_ID = 11;
- /** Comparing 2 processing instructions with different targets */
- int PROCESSING_INSTRUCTION_TARGET_ID = 12;
- /** Comparing 2 processing instructions with different instructions */
- int PROCESSING_INSTRUCTION_DATA_ID = 13;
- /** Comparing 2 different text values */
- int TEXT_VALUE_ID = 14;
- /** Comparing 2 nodes with different namespace prefixes */
- int NAMESPACE_PREFIX_ID = 15;
- /** Comparing 2 nodes with different namespace URIs */
- int NAMESPACE_URI_ID = 16;
- /** Comparing 2 nodes with different node types */
- int NODE_TYPE_ID = 17;
- /** Comparing 2 nodes but only one has any children*/
- int HAS_CHILD_NODES_ID = 18;
- /** Comparing 2 nodes with different numbers of children */
- int CHILD_NODELIST_LENGTH_ID = 19;
- /** Comparing 2 nodes with children whose nodes are in different sequence*/
- int CHILD_NODELIST_SEQUENCE_ID = 20;
- /** Comparing 2 Documents only one of which has a doctype */
- int HAS_DOCTYPE_DECLARATION_ID = 21;
-
/** Comparing an implied attribute value against an explicit value */
- public static final Difference ATTR_VALUE_EXPLICITLY_SPECIFIED =
+ int ATTR_VALUE_EXPLICITLY_SPECIFIED_ID = 1;
+ /** Comparing 2 elements and one has an attribute the other does not */
+ int ATTR_NAME_NOT_FOUND_ID = 2;
+ /** Comparing 2 attributes with the same name but different values */
+ int ATTR_VALUE_ID = 3;
+ /** Comparing 2 attribute lists with the same attributes in different sequence */
+ int ATTR_SEQUENCE_ID = 4;
+ /** Comparing 2 CDATA sections with different values */
+ int CDATA_VALUE_ID = 5;
+ /** Comparing 2 comments with different values */
+ int COMMENT_VALUE_ID = 6;
+ /** Comparing 2 document types with different names */
+ int DOCTYPE_NAME_ID = 7;
+ /** Comparing 2 document types with different public identifiers */
+ int DOCTYPE_PUBLIC_ID_ID = 8;
+ /** Comparing 2 document types with different system identifiers */
+ int DOCTYPE_SYSTEM_ID_ID = 9;
+ /** Comparing 2 elements with different tag names */
+ int ELEMENT_TAG_NAME_ID = 10;
+ /** Comparing 2 elements with different number of attributes */
+ int ELEMENT_NUM_ATTRIBUTES_ID = 11;
+ /** Comparing 2 processing instructions with different targets */
+ int PROCESSING_INSTRUCTION_TARGET_ID = 12;
+ /** Comparing 2 processing instructions with different instructions */
+ int PROCESSING_INSTRUCTION_DATA_ID = 13;
+ /** Comparing 2 different text values */
+ int TEXT_VALUE_ID = 14;
+ /** Comparing 2 nodes with different namespace prefixes */
+ int NAMESPACE_PREFIX_ID = 15;
+ /** Comparing 2 nodes with different namespace URIs */
+ int NAMESPACE_URI_ID = 16;
+ /** Comparing 2 nodes with different node types */
+ int NODE_TYPE_ID = 17;
+ /** Comparing 2 nodes but only one has any children*/
+ int HAS_CHILD_NODES_ID = 18;
+ /** Comparing 2 nodes with different numbers of children */
+ int CHILD_NODELIST_LENGTH_ID = 19;
+ /** Comparing 2 nodes with children whose nodes are in different sequence*/
+ int CHILD_NODELIST_SEQUENCE_ID = 20;
+ /** Comparing 2 Documents only one of which has a doctype */
+ int HAS_DOCTYPE_DECLARATION_ID = 21;
+
+ /** Comparing an implied attribute value against an explicit value */
+ public static final Difference ATTR_VALUE_EXPLICITLY_SPECIFIED =
new Difference(ATTR_VALUE_EXPLICITLY_SPECIFIED_ID,
- "attribute value explicitly specified", true);
+ "attribute value explicitly specified", true);
/** Comparing 2 elements and one has an attribute the other does not */
public static final Difference ATTR_NAME_NOT_FOUND =
@@ -133,12 +133,12 @@
/** Comparing 2 processing instructions with different targets */
public static final Difference PROCESSING_INSTRUCTION_TARGET =
new Difference(PROCESSING_INSTRUCTION_TARGET_ID,
- "processing instruction target");
+ "processing instruction target");
/** Comparing 2 processing instructions with different instructions */
public static final Difference PROCESSING_INSTRUCTION_DATA =
new Difference(PROCESSING_INSTRUCTION_DATA_ID,
- "processing instruction data");
+ "processing instruction data");
/** Comparing 2 different text values */
public static final Difference TEXT_VALUE =
@@ -167,10 +167,10 @@
/** Comparing 2 nodes with children whose nodes are in different sequence*/
public static final Difference CHILD_NODELIST_SEQUENCE =
new Difference(CHILD_NODELIST_SEQUENCE_ID,
- "sequence of child nodes", true);
+ "sequence of child nodes", true);
/** Comparing 2 Documents only one of which has a doctype */
public static final Difference HAS_DOCTYPE_DECLARATION =
new Difference(HAS_DOCTYPE_DECLARATION_ID,
- "presence of doctype declaration", true);
+ "presence of doctype declaration", true);
}
\ No newline at end of file
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -77,9 +77,9 @@
* @see ComparisonController#haltComparison(Difference)
*/
public DifferenceEngine(ComparisonController controller) {
- this.controller = controller;
- this.controlTracker = new XpathNodeTracker();
- this.testTracker = new XpathNodeTracker();
+ this.controller = controller;
+ this.controlTracker = new XpathNodeTracker();
+ this.testTracker = new XpathNodeTracker();
}
/**
@@ -93,21 +93,21 @@
* in any sequence and that sequence is not considered important.
*/
public void compare(Node control, Node test, DifferenceListener listener,
- ElementQualifier elementQualifier) {
- controlTracker.reset();
- testTracker.reset();
+ ElementQualifier elementQualifier) {
+ controlTracker.reset();
+ testTracker.reset();
try {
compare(getNullOrNotNull(control), getNullOrNotNull(test),
- control, test, listener, NODE_TYPE);
+ control, test, listener, NODE_TYPE);
if (control!=null) {
compareNode(control, test, listener, elementQualifier);
}
} catch (DifferenceFoundException e) {
// thrown by the protected compare() method to terminate the
// comparison and unwind the call stack back to here
- }
+ }
}
-
+
private String getNullOrNotNull(Node aNode) {
return aNode==null ? NULL_NODE : NOT_NULL_NODE;
}
@@ -122,41 +122,41 @@
* @throws DifferenceFoundException
*/
protected void compareNode(Node control, Node test,
- DifferenceListener listener, ElementQualifier elementQualifier)
- throws DifferenceFoundException {
+ DifferenceListener listener, ElementQualifier elementQualifier)
+ throws DifferenceFoundException {
boolean comparable = compareNodeBasics(control, test, listener);
boolean isDocumentNode = false;
- if (comparable) {
- switch (control.getNodeType()) {
- case Node.ELEMENT_NODE:
- compareElement((Element)control, (Element)test, listener);
- break;
- case Node.CDATA_SECTION_NODE:
- case Node.TEXT_NODE:
- compareText((CharacterData) control,
- (CharacterData) test, listener);
- break;
- case Node.COMMENT_NODE:
- compareComment((Comment)control, (Comment)test, listener);
- break;
- case Node.DOCUMENT_TYPE_NODE:
- compareDocumentType((DocumentType)control,
- (DocumentType)test, listener);
- break;
- case Node.PROCESSING_INSTRUCTION_NODE:
- compareProcessingInstruction((ProcessingInstruction)control,
- (ProcessingInstruction)test, listener);
- break;
- case Node.DOCUMENT_NODE:
- isDocumentNode = true;
- compareDocument((Document)control, (Document) test,
- listener, elementQualifier);
- break;
- default:
- listener.skippedComparison(control, test);
- }
- }
+ if (comparable) {
+ switch (control.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ compareElement((Element)control, (Element)test, listener);
+ break;
+ case Node.CDATA_SECTION_NODE:
+ case Node.TEXT_NODE:
+ compareText((CharacterData) control,
+ (CharacterData) test, listener);
+ break;
+ case Node.COMMENT_NODE:
+ compareComment((Comment)control, (Comment)test, listener);
+ break;
+ case Node.DOCUMENT_TYPE_NODE:
+ compareDocumentType((DocumentType)control,
+ (DocumentType)test, listener);
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ compareProcessingInstruction((ProcessingInstruction)control,
+ (ProcessingInstruction)test, listener);
+ break;
+ case Node.DOCUMENT_NODE:
+ isDocumentNode = true;
+ compareDocument((Document)control, (Document) test,
+ listener, elementQualifier);
+ break;
+ default:
+ listener.skippedComparison(control, test);
+ }
+ }
compareHasChildNodes(control, test, listener);
if (isDocumentNode) {
@@ -166,8 +166,8 @@
compareNode(controlElement, testElement, listener, elementQualifier);
}
} else {
- controlTracker.indent();
- testTracker.indent();
+ controlTracker.indent();
+ testTracker.indent();
compareNodeChildren(control, test, listener, elementQualifier);
controlTracker.outdent();
testTracker.outdent();
@@ -183,14 +183,14 @@
* @throws DifferenceFoundException
*/
protected void compareDocument(Document control, Document test,
- DifferenceListener listener, ElementQualifier elementQualifier)
- throws DifferenceFoundException {
+ DifferenceListener listener, ElementQualifier elementQualifier)
+ throws DifferenceFoundException {
DocumentType controlDoctype = control.getDoctype();
DocumentType testDoctype = test.getDoctype();
compare(getNullOrNotNull(controlDoctype),
- getNullOrNotNull(testDoctype),
- controlDoctype, testDoctype, listener,
- HAS_DOCTYPE_DECLARATION);
+ getNullOrNotNull(testDoctype),
+ controlDoctype, testDoctype, listener,
+ HAS_DOCTYPE_DECLARATION);
if (controlDoctype!=null && testDoctype!=null) {
compareNode(controlDoctype, testDoctype, listener, elementQualifier);
}
@@ -206,7 +206,7 @@
* @throws DifferenceFoundException
*/
protected boolean compareNodeBasics(Node control, Node test,
- DifferenceListener listener) throws DifferenceFoundException {
+ DifferenceListener listener) throws DifferenceFoundException {
controlTracker.visited(control);
testTracker.visited(test);
@@ -220,9 +220,9 @@
NODE_TYPE);
}
compare(control.getNamespaceURI(), test.getNamespaceURI(),
- control, test, listener, NAMESPACE_URI);
+ control, test, listener, NAMESPACE_URI);
compare(control.getPrefix(), test.getPrefix(),
- control, test, listener, NAMESPACE_PREFIX);
+ control, test, listener, NAMESPACE_PREFIX);
return textAndCDATA || controlType.equals(testType);
}
@@ -245,13 +245,13 @@
* @throws DifferenceFoundException
*/
protected void compareHasChildNodes(Node control, Node test,
- DifferenceListener listener) throws DifferenceFoundException {
+ DifferenceListener listener) throws DifferenceFoundException {
Boolean controlHasChildren = control.hasChildNodes()
? Boolean.TRUE : Boolean.FALSE;
Boolean testHasChildren = test.hasChildNodes()
? Boolean.TRUE : Boolean.FALSE;
compare(controlHasChildren, testHasChildren, control, test,
- listener, HAS_CHILD_NODES);
+ listener, HAS_CHILD_NODES);
}
/**
@@ -264,8 +264,8 @@
* @throws DifferenceFoundException
*/
protected void compareNodeChildren(Node control, Node test,
- DifferenceListener listener, ElementQualifier elementQualifier)
- throws DifferenceFoundException {
+ DifferenceListener listener, ElementQualifier elementQualifier)
+ throws DifferenceFoundException {
if (control.hasChildNodes() && test.hasChildNodes()) {
NodeList controlChildren = control.getChildNodes();
NodeList testChildren = test.getChildNodes();
@@ -273,9 +273,9 @@
Integer controlLength = new Integer(controlChildren.getLength());
Integer testLength = new Integer(testChildren.getLength());
compare(controlLength, testLength, control, test, listener,
- CHILD_NODELIST_LENGTH);
+ CHILD_NODELIST_LENGTH);
compareNodeList(controlChildren, testChildren,
- controlLength.intValue(), listener, elementQualifier);
+ controlLength.intValue(), listener, elementQualifier);
}
}
@@ -397,80 +397,80 @@
* @throws DifferenceFoundException
*/
protected void compareElement(Element control, Element test,
- DifferenceListener listener) throws DifferenceFoundException {
- compare(getUnNamespacedNodeName(control), getUnNamespacedNodeName(test),
- control, test, listener, ELEMENT_TAG_NAME);
+ DifferenceListener listener) throws DifferenceFoundException {
+ compare(getUnNamespacedNodeName(control), getUnNamespacedNodeName(test),
+ control, test, listener, ELEMENT_TAG_NAME);
NamedNodeMap controlAttr = control.getAttributes();
- Integer controlNonXmlnsAttrLength = getNonXmlnsAttrLength(controlAttr);
+ Integer controlNonXmlnsAttrLength = getNonXmlnsAttrLength(controlAttr);
NamedNodeMap testAttr = test.getAttributes();
Integer testNonXmlnsAttrLength = getNonXmlnsAttrLength(testAttr);
compare(controlNonXmlnsAttrLength, testNonXmlnsAttrLength,
- control, test, listener, ELEMENT_NUM_ATTRIBUTES);
+ control, test, listener, ELEMENT_NUM_ATTRIBUTES);
compareElementAttributes(control, test, controlAttr, testAttr,
- listener);
+ listener);
}
- private Integer getNonXmlnsAttrLength(NamedNodeMap attributes) {
- int length = 0, maxLength = attributes.getLength();
- for (int i = 0; i < maxLength; ++i) {
- if (!isXMLNSAttribute((Attr) attributes.item(i))) {
- ++length;
- }
- }
- return new Integer(length);
- }
+ private Integer getNonXmlnsAttrLength(NamedNodeMap attributes) {
+ int length = 0, maxLength = attributes.getLength();
+ for (int i = 0; i < maxLength; ++i) {
+ if (!isXMLNSAttribute((Attr) attributes.item(i))) {
+ ++length;
+ }
+ }
+ return new Integer(length);
+ }
private void compareElementAttributes(Element control, Element test,
- NamedNodeMap controlAttr, NamedNodeMap testAttr,
- DifferenceListener listener) throws DifferenceFoundException {
+ NamedNodeMap controlAttr, NamedNodeMap testAttr,
+ DifferenceListener listener) throws DifferenceFoundException {
for (int i=0; i < controlAttr.getLength(); ++i) {
Attr nextAttr = (Attr) controlAttr.item(i);
- if (isXMLNSAttribute(nextAttr)) {
- // xml namespacing is handled in compareNodeBasics
- } else {
- boolean isNamespacedAttr = isNamespaced(nextAttr);
- String attrName = getUnNamespacedNodeName(nextAttr, isNamespacedAttr);
- Attr compareTo = null;
-
- if (isNamespacedAttr) {
- compareTo = (Attr) testAttr.getNamedItemNS(
- nextAttr.getNamespaceURI(), attrName);
- } else {
- compareTo = (Attr) testAttr.getNamedItem(attrName);
- }
-
- if (compareTo != null) {
- compareAttribute(nextAttr, compareTo, listener);
-
- Attr attributeItem = (Attr) testAttr.item(i);
- String testAttrName = "[attribute absent]";
- if (attributeItem != null) {
- testAttrName = getUnNamespacedNodeName(attributeItem);
- }
- compare(attrName, testAttrName,
- nextAttr, compareTo, listener, ATTR_SEQUENCE);
- } else {
- compare(attrName, null, control, test, listener,
- ATTR_NAME_NOT_FOUND);
- }
- }
+ if (isXMLNSAttribute(nextAttr)) {
+ // xml namespacing is handled in compareNodeBasics
+ } else {
+ boolean isNamespacedAttr = isNamespaced(nextAttr);
+ String attrName = getUnNamespacedNodeName(nextAttr, isNamespacedAttr);
+ Attr compareTo = null;
+
+ if (isNamespacedAttr) {
+ compareTo = (Attr) testAttr.getNamedItemNS(
+ nextAttr.getNamespaceURI(), attrName);
+ } else {
+ compareTo = (Attr) testAttr.getNamedItem(attrName);
+ }
+
+ if (compareTo != null) {
+ compareAttribute(nextAttr, compareTo, listener);
+
+ Attr attributeItem = (Attr) testAttr.item(i);
+ String testAttrName = "[attribute absent]";
+ if (attributeItem != null) {
+ testAttrName = getUnNamespacedNodeName(attributeItem);
+ }
+ compare(attrName, testAttrName,
+ nextAttr, compareTo, listener, ATTR_SEQUENCE);
+ } else {
+ compare(attrName, null, control, test, listener,
+ ATTR_NAME_NOT_FOUND);
+ }
+ }
}
controlTracker.clearTrackedAttribute();
testTracker.clearTrackedAttribute();
}
private String getUnNamespacedNodeName(Node aNode) {
- return getUnNamespacedNodeName(aNode, isNamespaced(aNode));
+ return getUnNamespacedNodeName(aNode, isNamespaced(aNode));
}
- private String getUnNamespacedNodeName(Node aNode, boolean isNamespacedNode) {
- if (isNamespacedNode) {
- return aNode.getLocalName();
- }
- return aNode.getNodeName();
- }
+ private String getUnNamespacedNodeName(Node aNode, boolean isNamespacedNode) {
+ if (isNamespacedNode) {
+ return aNode.getLocalName();
+ }
+ return aNode.getNodeName();
+ }
/**
@@ -490,19 +490,19 @@
* @throws DifferenceFoundException
*/
protected void compareAttribute(Attr control, Attr test,
- DifferenceListener listener) throws DifferenceFoundException {
- controlTracker.visited(control);
- testTracker.visited(test);
-
- compare(control.getPrefix(), test.getPrefix(), control, test,
- listener, NAMESPACE_PREFIX);
-
+ DifferenceListener listener) throws DifferenceFoundException {
+ controlTracker.visited(control);
+ testTracker.visited(test);
+
+ compare(control.getPrefix(), test.getPrefix(), control, test,
+ listener, NAMESPACE_PREFIX);
+
compare(control.getValue(), test.getValue(), control, test,
- listener, ATTR_VALUE);
+ listener, ATTR_VALUE);
compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
- test.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
- control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED);
+ test.getSpecified() ? Boolean.TRUE : Boolean.FALSE,
+ control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED);
}
/**
@@ -513,7 +513,7 @@
* @throws DifferenceFoundException
*/
protected void compareCDataSection(CDATASection control, CDATASection test,
- DifferenceListener listener) throws DifferenceFoundException {
+ DifferenceListener listener) throws DifferenceFoundException {
compareText(control, test, listener);
}
@@ -525,7 +525,7 @@
* @throws DifferenceFoundException
*/
protected void compareComment(Comment control, Comment test,
- DifferenceListener listener) throws DifferenceFoundException {
+ DifferenceListener listener) throws DifferenceFoundException {
compareCharacterData(control, test, listener, COMMENT_VALUE);
}
@@ -537,14 +537,14 @@
* @throws DifferenceFoundException
*/
protected void compareDocumentType(DocumentType control, DocumentType test,
- DifferenceListener listener) throws DifferenceFoundException {
+ DifferenceListener listener) throws DifferenceFoundException {
compare(control.getName(), test.getName(), control, test, listener,
- DOCTYPE_NAME);
+ DOCTYPE_NAME);
compare(control.getPublicId(), test.getPublicId(), control, test, listener,
- DOCTYPE_PUBLIC_ID);
+ DOCTYPE_PUBLIC_ID);
compare(control.getSystemId(), test.getSystemId(),
- control, test, listener, DOCTYPE_SYSTEM_ID);
+ control, test, listener, DOCTYPE_SYSTEM_ID);
}
/**
@@ -555,12 +555,12 @@
* @throws DifferenceFoundException
*/
protected void compareProcessingInstruction(ProcessingInstruction control,
- ProcessingInstruction test, DifferenceListener listener)
- throws DifferenceFoundException {
+ ProcessingInstruction test, DifferenceListener listener)
+ throws DifferenceFoundException {
compare(control.getTarget(), test.getTarget(), control, test, listener,
- PROCESSING_INSTRUCTION_TARGET);
+ PROCESSING_INSTRUCTION_TARGET);
compare(control.getData(), test.getData(), control, test, listener,
- PROCESSING_INSTRUCTION_DATA);
+ PROCESSING_INSTRUCTION_DATA);
}
/**
@@ -599,10 +599,10 @@
* @throws DifferenceFoundException
*/
private void compareCharacterData(CharacterData control, CharacterData test,
- DifferenceListener listener, Difference difference)
- throws DifferenceFoundException {
+ DifferenceListener listener, Difference difference)
+ throws DifferenceFoundException {
compare(control.getData(), test.getData(), control, test, listener,
- difference);
+ difference);
}
/**
@@ -617,15 +617,15 @@
* @throws DifferenceFoundException
*/
protected void compare(Object expected, Object actual,
- Node control, Node test, DifferenceListener listener, Difference difference)
- throws DifferenceFoundException {
+ Node control, Node test, DifferenceListener listener, Difference difference)
+ throws DifferenceFoundException {
if (unequal(expected, actual)) {
- NodeDetail controlDetail = new NodeDetail(String.valueOf(expected),
- control, controlTracker.toXpathString());
- NodeDetail testDetail = new NodeDetail(String.valueOf(actual),
- test, testTracker.toXpathString());
- Difference differenceInstance = new Difference(difference,
- controlDetail, testDetail);
+ NodeDetail controlDetail = new NodeDetail(String.valueOf(expected),
+ control, controlTracker.toXpathString());
+ NodeDetail testDetail = new NodeDetail(String.valueOf(actual),
+ test, testTracker.toXpathString());
+ Difference differenceInstance = new Difference(difference,
+ controlDetail, testDetail);
listener.differenceFound(differenceInstance);
if (controller.haltComparison(differenceInstance)) {
throw flowControlException;
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -72,7 +72,7 @@
* @param systemID
*/
public DoctypeReader(Reader originalSource, String doctypeName,
- String systemID) {
+ String systemID) {
this.originalSource = originalSource;
this.doctypeName = doctypeName;
this.systemId = systemID;
@@ -132,13 +132,13 @@
curChar = withinContent.charAt(i);
if (curChar == '<') {
switch (withinContent.charAt(i + 1)) {
- case '?':
- case '!':
- case '-':
- canInsert = false;
- break;
- default:
- startAt = i;
+ case '?':
+ case '!':
+ case '-':
+ canInsert = false;
+ break;
+ default:
+ startAt = i;
}
} else if (curChar == '>') {
canInsert = true;
@@ -157,7 +157,7 @@
* @return the content, after DOCTYPE amendment / addition
*/
public String replaceDoctype(StringBuffer withinContent,
- String doctypeName, String systemId) {
+ String doctypeName, String systemId) {
String content = withinContent.toString();
int startDoctype = content.indexOf(DOCTYPE);
boolean noCurrentDoctype = false;
@@ -206,7 +206,7 @@
private Reader getReplacementReader() throws IOException {
StringBuffer originalContent = getContent(originalSource);
String replacedContent = replaceDoctype(originalContent,
- doctypeName, systemId);
+ doctypeName, systemId);
return new StringReader(replacedContent);
}
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -7,16 +7,16 @@
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.
+ * 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
@@ -49,105 +49,105 @@
* @see Diff#overrideElementQualifier(ElementQualifier)
*/
public class ElementNameAndAttributeQualifier extends ElementNameQualifier {
- public static final String[] ALL_ATTRIBUTES = {"*"};
-
- private final String[] qualifyingAttrNames;
-
- /**
- * No-args constructor: use all attributes from all elements to determine
- * whether elements qualify for comparability
- */
- public ElementNameAndAttributeQualifier() {
- this(ALL_ATTRIBUTES);
- }
-
- /**
- * Simple constructor for a single qualifying attribute name
- * @param attrName the value to use to qualify whether two elements can be
- * compared further for differences
- */
- public ElementNameAndAttributeQualifier(String attrName) {
- this(new String[] {attrName});
- }
+ public static final String[] ALL_ATTRIBUTES = {"*"};
+
+ private final String[] qualifyingAttrNames;
+
+ /**
+ * No-args constructor: use all attributes from all elements to determine
+ * whether elements qualify for comparability
+ */
+ public ElementNameAndAttributeQualifier() {
+ this(ALL_ATTRIBUTES);
+ }
+
+ /**
+ * Simple constructor for a single qualifying attribute name
+ * @param attrName the value to use to qualify whether two elements can be
+ * compared further for differences
+ */
+ public ElementNameAndAttributeQualifier(String attrName) {
+ this(new String[] {attrName});
+ }
- /**
- * Extended constructor for multiple qualifying attribute names
- * @param attrNames the array of values to use to qualify whether two
- * elements can be compared further for differences
- */
- public ElementNameAndAttributeQualifier(String[] attrNames) {
- this.qualifyingAttrNames = attrNames;
- }
+ /**
+ * Extended constructor for multiple qualifying attribute names
+ * @param attrNames the array of values to use to qualify whether two
+ * elements can be compared further for differences
+ */
+ public ElementNameAndAttributeQualifier(String[] attrNames) {
+ this.qualifyingAttrNames = attrNames;
+ }
- /**
- * Determine whether two elements qualify for further Difference comparison.
- * @param differenceEngine the DifferenceEngine instance wanting to
- * determine if the elements are comparable
- * @param control
- * @param test
- * @return true if the two elements qualify for further comparison based on
- * both the superclass qualification (namespace URI and non- namespaced tag
- * name), and the presence of qualifying attributes with the same values;
- * false otherwise
- */
- public boolean qualifyForComparison(Element control, Element test) {
- if (super.qualifyForComparison(control, test)) {
- return areAttributesComparable(control, test);
- }
- return false;
- }
-
- /**
- * Determine whether the qualifying attributes are present in both elements
- * and if so whether their values are the same
- * @param control
- * @param test
- * @return true if all qualifying attributes are present with the same
- * values, false otherwise
- */
- protected boolean areAttributesComparable(Element control, Element test) {
- String controlValue, testValue;
- Attr[] qualifyingAttributes;
- NamedNodeMap namedNodeMap = control.getAttributes();
- if (qualifyingAttrNames == ALL_ATTRIBUTES) {
- qualifyingAttributes = new Attr[namedNodeMap.getLength()];
- for (int n=0; n < qualifyingAttributes.length; ++n) {
- qualifyingAttributes[n] = (Attr) namedNodeMap.item(n);
- }
- } else {
- qualifyingAttributes = new Attr[qualifyingAttrNames.length];
- for (int n=0; n < qualifyingAttrNames.length; ++n) {
- qualifyingAttributes[n] = (Attr) namedNodeMap.getNamedItem(qualifyingAttrNames[n]);
- }
- }
-
- String nsURI, name;
- for (int i=0; i < qualifyingAttributes.length; ++i) {
- if (qualifyingAttributes[i] != null) {
- nsURI = qualifyingAttributes[i].getNamespaceURI();
- controlValue = qualifyingAttributes[i].getNodeValue();
- name = qualifyingAttributes[i].getName();
- } else {
- // cannot be "*" case
- nsURI = controlValue = "";
- name = qualifyingAttrNames[i];
- }
- if (nsURI == null || nsURI.length() == 0) {
- testValue = test.getAttribute(name);
- } else {
- testValue = test.getAttributeNS(nsURI, qualifyingAttributes[i].getLocalName());
- }
- if (controlValue == null) {
- if (testValue != null) {
- return false;
- }
- } else {
- if (!controlValue.equals(testValue)) {
- return false;
- }
- }
- }
- return true;
- }
+ /**
+ * Determine whether two elements qualify for further Difference comparison.
+ * @param differenceEngine the DifferenceEngine instance wanting to
+ * determine if the elements are comparable
+ * @param control
+ * @param test
+ * @return true if the two elements qualify for further comparison based on
+ * both the superclass qualification (namespace URI and non- namespaced tag
+ * name), and the presence of qualifying attributes with the same values;
+ * false otherwise
+ */
+ public boolean qualifyForComparison(Element control, Element test) {
+ if (super.qualifyForComparison(control, test)) {
+ return areAttributesComparable(control, test);
+ }
+ return false;
+ }
+
+ /**
+ * Determine whether the qualifying attributes are present in both elements
+ * and if so whether their values are the same
+ * @param control
+ * @param test
+ * @return true if all qualifying attributes are present with the same
+ * values, false otherwise
+ */
+ protected boolean areAttributesComparable(Element control, Element test) {
+ String controlValue, testValue;
+ Attr[] qualifyingAttributes;
+ NamedNodeMap namedNodeMap = control.getAttributes();
+ if (qualifyingAttrNames == ALL_ATTRIBUTES) {
+ qualifyingAttributes = new Attr[namedNodeMap.getLength()];
+ for (int n=0; n < qualifyingAttributes.length; ++n) {
+ qualifyingAttributes[n] = (Attr) namedNodeMap.item(n);
+ }
+ } else {
+ qualifyingAttributes = new Attr[qualifyingAttrNames.length];
+ for (int n=0; n < qualifyingAttrNames.length; ++n) {
+ qualifyingAttributes[n] = (Attr) namedNodeMap.getNamedItem(qualifyingAttrNames[n]);
+ }
+ }
+
+ String nsURI, name;
+ for (int i=0; i < qualifyingAttributes.length; ++i) {
+ if (qualifyingAttributes[i] != null) {
+ nsURI = qualifyingAttributes[i].getNamespaceURI();
+ controlValue = qualifyingAttributes[i].getNodeValue();
+ name = qualifyingAttributes[i].getName();
+ } else {
+ // cannot be "*" case
+ nsURI = controlValue = "";
+ name = qualifyingAttrNames[i];
+ }
+ if (nsURI == null || nsURI.length() == 0) {
+ testValue = test.getAttribute(name);
+ } else {
+ testValue = test.getAttributeNS(nsURI, qualifyingAttributes[i].getLocalName());
+ }
+ if (controlValue == null) {
+ if (testValue != null) {
+ return false;
+ }
+ } else {
+ if (!controlValue.equals(testValue)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndTextQualifier.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndTextQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndTextQualifier.java 2007-02-05 19:47:29 UTC (rev 147)
@@ -7,16 +7,16 @@
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.
+ * 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
@@ -50,53 +50,53 @@
* @see Diff#overrideElementQualifier(ElementQualifier)
*/
public class ElementNameAndTextQualifier extends ElementNameQualifier {
- /**
- * Determine whether two elements qualify for further Difference comparison.
- * @param control
- * @param test
- * @return true if the two elements qualify for further comparison based on
- * both the superclass qualification (namespace URI and non- namespaced tag
- * name), and the qualification of the text nodes contained within the
- * elements; false otherwise
- */
- public bo...
[truncated message content] |
|
From: <bo...@us...> - 2007-02-02 21:36:25
|
Revision: 146
http://xmlunit.svn.sourceforge.net/xmlunit/?rev=146&view=rev
Author: bodewig
Date: 2007-02-02 13:36:23 -0800 (Fri, 02 Feb 2007)
Log Message:
-----------
Move MultiLevelElementNameAndTextQualifier to examples package
Added Paths:
-----------
trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_MultiLevelElementNameAndTextQualifier.java
Removed Paths:
-------------
trunk/xmlunit/src/java/org/custommonkey/xmlunit/MultiLevelElementNameAndTextQualifier.java
trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_MultiLevelElementNameAndTextQualifier.java
Deleted: trunk/xmlunit/src/java/org/custommonkey/xmlunit/MultiLevelElementNameAndTextQualifier.java
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/MultiLevelElementNameAndTextQualifier.java 2007-02-02 20:44:21 UTC (rev 145)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/MultiLevelElementNameAndTextQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
@@ -1,117 +0,0 @@
-/*
-******************************************************************
-Copyright (c) 2001, 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;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-/**
- * Per popular request an interface implementation that uses element
- * names and the text node containes in the n'th child node to compare
- * elements.
- *
- * <p>This means {@link ElementNameAndTextQualifier
- * ElementNameQualifier} and MultiLevelElementNameQualifier(1) should
- * lead to the same results.</p>
- *
- * <p>Any attribute values ar completely ignored. Only works on
- * elements with exactly one child element at each level.</p>
- *
- * <p>This class mostly exists as an example for custom ElementQualifiers.</p>
- */
-public class MultiLevelElementNameAndTextQualifier
- implements ElementQualifier {
-
- private final int levels;
-
- private static final ElementNameQualifier NAME_QUALIFIER =
- new ElementNameQualifier();
- private static final ElementNameAndTextQualifier NAME_AND_TEXT_QUALIFIER =
- new ElementNameAndTextQualifier();
-
- /**
- * Uses element names and the text nested <code>levels</code>
- * child elements deeper into the element to compare elements.
- */
- public MultiLevelElementNameAndTextQualifier(int levels) {
- if (levels < 1) {
- throw new IllegalArgumentException("levels must be equal or"
- + " greater than one");
- }
- this.levels = levels;
- }
-
- public boolean qualifyForComparison(Element control, Element test) {
- boolean stillSimilar = true;
- Element currentControl = control;
- Element currentTest = test;
-
- // match on element names only for leading levels
- for (int currentLevel = 0; stillSimilar && currentLevel <= levels - 2;
- currentLevel++) {
- stillSimilar = NAME_QUALIFIER.qualifyForComparison(currentControl,
- currentTest);
- if (stillSimilar) {
- if (currentControl.hasChildNodes()
- && currentTest.hasChildNodes()) {
- Node n1 = currentControl.getFirstChild();
- Node n2 = currentTest.getFirstChild();
- if (n1.getNodeType() == Node.ELEMENT_NODE
- && n2.getNodeType() == Node.ELEMENT_NODE) {
- currentControl = (Element) n1;
- currentTest = (Element) n2;
- } else {
- stillSimilar = false;
- }
- } else {
- stillSimilar = false;
- }
- }
- }
-
- // finally compare the level containing the text child node
- if (stillSimilar) {
- stillSimilar = NAME_AND_TEXT_QUALIFIER
- .qualifyForComparison(currentControl, currentTest);
- }
-
- return stillSimilar;
- }
-
-}
Copied: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java (from rev 144, trunk/xmlunit/src/java/org/custommonkey/xmlunit/MultiLevelElementNameAndTextQualifier.java)
===================================================================
--- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java (rev 0)
+++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
@@ -0,0 +1,121 @@
+/*
+******************************************************************
+Copyright (c) 2001, 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.w3c.dom.Text;
+
+import org.custommonkey.xmlunit.ElementNameAndTextQualifier;
+import org.custommonkey.xmlunit.ElementNameQualifier;
+import org.custommonkey.xmlunit.ElementQualifier;
+
+/**
+ * Per popular request an interface implementation that uses element
+ * names and the text node containes in the n'th child node to compare
+ * elements.
+ *
+ * <p>This means {@link ElementNameAndTextQualifier
+ * ElementNameQualifier} and MultiLevelElementNameQualifier(1) should
+ * lead to the same results.</p>
+ *
+ * <p>Any attribute values ar completely ignored. Only works on
+ * elements with exactly one child element at each level.</p>
+ *
+ * <p>This class mostly exists as an example for custom ElementQualifiers.</p>
+ */
+public class MultiLevelElementNameAndTextQualifier
+ implements ElementQualifier {
+
+ private final int levels;
+
+ private static final ElementNameQualifier NAME_QUALIFIER =
+ new ElementNameQualifier();
+ private static final ElementNameAndTextQualifier NAME_AND_TEXT_QUALIFIER =
+ new ElementNameAndTextQualifier();
+
+ /**
+ * Uses element names and the text nested <code>levels</code>
+ * child elements deeper into the element to compare elements.
+ */
+ public MultiLevelElementNameAndTextQualifier(int levels) {
+ if (levels < 1) {
+ throw new IllegalArgumentException("levels must be equal or"
+ + " greater than one");
+ }
+ this.levels = levels;
+ }
+
+ public boolean qualifyForComparison(Element control, Element test) {
+ boolean stillSimilar = true;
+ Element currentControl = control;
+ Element currentTest = test;
+
+ // match on element names only for leading levels
+ for (int currentLevel = 0; stillSimilar && currentLevel <= levels - 2;
+ currentLevel++) {
+ stillSimilar = NAME_QUALIFIER.qualifyForComparison(currentControl,
+ currentTest);
+ if (stillSimilar) {
+ if (currentControl.hasChildNodes()
+ && currentTest.hasChildNodes()) {
+ Node n1 = currentControl.getFirstChild();
+ Node n2 = currentTest.getFirstChild();
+ if (n1.getNodeType() == Node.ELEMENT_NODE
+ && n2.getNodeType() == Node.ELEMENT_NODE) {
+ currentControl = (Element) n1;
+ currentTest = (Element) n2;
+ } else {
+ stillSimilar = false;
+ }
+ } else {
+ stillSimilar = false;
+ }
+ }
+ }
+
+ // finally compare the level containing the text child node
+ if (stillSimilar) {
+ stillSimilar = NAME_AND_TEXT_QUALIFIER
+ .qualifyForComparison(currentControl, currentTest);
+ }
+
+ return stillSimilar;
+ }
+
+}
Copied: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_MultiLevelElementNameAndTextQualifier.java (from rev 144, trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_MultiLevelElementNameAndTextQualifier.java)
===================================================================
--- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_MultiLevelElementNameAndTextQualifier.java (rev 0)
+++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_MultiLevelElementNameAndTextQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
@@ -0,0 +1,147 @@
+/*
+******************************************************************
+Copyright (c) 2001, 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 MultiLevelElementNameAndTextQualifier
+ * @see test_Diff#testRepeatedElementNamesWithTextQualification()
+ */
+public class test_MultiLevelElementNameAndTextQualifier 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 MultiLevelElementNameAndTextQualifier(1);
+
+ 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 MultiLevelElementNameAndTextQualifier(1);
+
+ 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 MultiLevelElementNameAndTextQualifier(3);
+
+ 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 MultiLevelElementNameAndTextQualifier(2));
+ assertTrue(d.similar());
+
+ }
+
+ public void setUp() throws Exception {
+ document = XMLUnit.newControlParser().newDocument();
+ }
+
+}
Deleted: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_MultiLevelElementNameAndTextQualifier.java
===================================================================
--- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_MultiLevelElementNameAndTextQualifier.java 2007-02-02 20:44:21 UTC (rev 145)
+++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_MultiLevelElementNameAndTextQualifier.java 2007-02-02 21:36:23 UTC (rev 146)
@@ -1,142 +0,0 @@
-/*
-******************************************************************
-Copyright (c) 2001, 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;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * JUnit testcase for MultiLevelElementNameAndTextQualifier
- * @see test_Diff#testRepeatedElementNamesWithTextQualification()
- */
-public class test_MultiLevelElementNameAndTextQualifier 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 MultiLevelElementNameAndTextQualifier(1);
-
- 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 MultiLevelElementNameAndTextQualifier(1);
-
- 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 MultiLevelElementNameAndTextQualifier(3);
-
- 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 MultiLevelElementNameAndTextQualifier(2));
- assertTrue(d.similar());
-
- }
-
- public void setUp() throws Exception {
- document = XMLUnit.newControlParser().newDocument();
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|