org.custommonkey.xmlunit
Class XMLUnit

java.lang.Object
  |
  +--org.custommonkey.xmlunit.XMLUnit

public final class XMLUnit
extends java.lang.Object

Allows access to project control parameters such as which Parser to use and provides some convenience methods for building Documents from Strings etc.
Examples and more at xmlunit.sourceforge.net


Method Summary
static org.w3c.dom.Document buildControlDocument(org.xml.sax.InputSource fromSource)
          Utility method to build a Document using the control DocumentBuilder and the specified InputSource
static org.w3c.dom.Document buildControlDocument(java.lang.String fromXML)
          Utility method to build a Document using the control DocumentBuilder to parse the specified String.
static org.w3c.dom.Document buildDocument(javax.xml.parsers.DocumentBuilder withBuilder, org.xml.sax.InputSource fromSource)
          Utility method to build a Document using a specific DocumentBuilder and a specific InputSource
static org.w3c.dom.Document buildDocument(javax.xml.parsers.DocumentBuilder withBuilder, java.io.Reader fromReader)
          Utility method to build a Document using a specific DocumentBuilder and reading characters from a specific Reader.
static org.w3c.dom.Document buildTestDocument(org.xml.sax.InputSource fromSource)
          Utility method to build a Document using the test DocumentBuilder and the specified InputSource
static org.w3c.dom.Document buildTestDocument(java.lang.String fromXML)
          Utility method to build a Document using the test DocumentBuilder to parse the specified String.
static org.custommonkey.xmlunit.Diff compare(org.xml.sax.InputSource control, org.xml.sax.InputSource test)
          Deprecated. use Diff constructor directly
static org.custommonkey.xmlunit.Diff compare(java.io.Reader control, java.io.Reader test)
          Deprecated. use Diff constructor directly
static org.custommonkey.xmlunit.Diff compare(java.io.Reader control, java.lang.String test)
          Deprecated. use Diff constructor directly
static org.custommonkey.xmlunit.Diff compare(java.lang.String control, java.io.Reader test)
          Deprecated. use Diff constructor directly
static org.custommonkey.xmlunit.Diff compare(java.lang.String control, java.lang.String test)
          Deprecated. use Diff constructor directly
static org.custommonkey.xmlunit.Diff compareXML(org.w3c.dom.Document control, org.w3c.dom.Document test)
          Compare two XML documents provided as strings
static org.custommonkey.xmlunit.Diff compareXML(java.io.Reader control, java.io.Reader test)
          Compare XML documents provided by two Reader classes
static org.custommonkey.xmlunit.Diff compareXML(java.io.Reader control, java.lang.String test)
          Compare XML documents provided by two Reader classes
static org.custommonkey.xmlunit.Diff compareXML(java.lang.String control, java.io.Reader test)
          Compare XML documents provided by two Reader classes
static org.custommonkey.xmlunit.Diff compareXML(java.lang.String control, java.lang.String test)
          Compare two XML documents provided as strings
static javax.xml.parsers.DocumentBuilderFactory getControlDocumentBuilderFactory()
          Get the DocumentBuilderFactory instance used to instantiate parsers for the control XML in an XMLTestCase.
static javax.xml.parsers.DocumentBuilder getControlParser()
          Get the DocumentBuilder instance used to parse the control XML in an XMLTestCase.
static boolean getIgnoreWhitespace()
          Whether to ignore whitespace when comparing node values.
static javax.xml.parsers.SAXParserFactory getSAXParserFactory()
          Get the SAX parser to use in tests.
static org.custommonkey.xmlunit.Transform getStripWhitespaceTransform(org.w3c.dom.Document forDocument)
          Obtain the transformation that will strip whitespace from a DOM containing empty Text nodes
static javax.xml.parsers.DocumentBuilderFactory getTestDocumentBuilderFactory()
          Get the DocumentBuilderFactory instance used to instantiate parsers for the test XML in an XMLTestCase.
static javax.xml.parsers.DocumentBuilder getTestParser()
          Get the DocumentBuilder instance used to parse the test XML in an XMLTestCase.
static javax.xml.transform.TransformerFactory getTransformerFactory()
          Get the transformer to use for XSLT transformations (and by implication serialization and XPaths).
static java.lang.String getVersion()
          Place holder for current version info.
static void setControlDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
          Override the DocumentBuilderFactory used to instantiate parsers for the control XML in an XMLTestCase.
static void setControlParser(java.lang.String className)
          Overide the DocumentBuilder to use to parse control documents.
static void setIgnoreWhitespace(boolean ignore)
          Whether to ignore whitespace when comparing node values.
static void setSAXParserFactory(java.lang.String className)
          Override the SAX parser to use in tests.
static void setTestDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
          Override the DocumentBuilderFactory used to instantiate parsers for the test XML in an XMLTestCase.
static void setTestParser(java.lang.String className)
          Overide the DocumentBuilder to use to parser test documents.
static void setTransformerFactory(java.lang.String className)
          Overide the transformer to use for XSLT transformations (and by implication serialization and XPaths).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setControlParser

public static void setControlParser(java.lang.String className)
                             throws javax.xml.parsers.FactoryConfigurationError
Overide the DocumentBuilder to use to parse control documents. This is useful when comparing the output of two different parsers. Note: setting the control parser before any test cases are run will affect the test parser as well.

javax.xml.parsers.FactoryConfigurationError

getControlParser

public static javax.xml.parsers.DocumentBuilder getControlParser()
                                                          throws javax.xml.parsers.ParserConfigurationException
Get the DocumentBuilder instance used to parse the control XML in an XMLTestCase.

Returns:
parser for control values
Throws:
javax.xml.parsers.ParserConfigurationException

getControlDocumentBuilderFactory

public static javax.xml.parsers.DocumentBuilderFactory getControlDocumentBuilderFactory()
Get the DocumentBuilderFactory instance used to instantiate parsers for the control XML in an XMLTestCase.

Returns:
factory for control parsers

setControlDocumentBuilderFactory

public static void setControlDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
Override the DocumentBuilderFactory used to instantiate parsers for the control XML in an XMLTestCase.


setTestParser

public static void setTestParser(java.lang.String className)
                          throws javax.xml.parsers.FactoryConfigurationError
Overide the DocumentBuilder to use to parser test documents. This is useful when comparing the output of two different parsers. Note: setting the test parser before any test cases are run will affect the control parser as well.

javax.xml.parsers.FactoryConfigurationError

getTestParser

public static javax.xml.parsers.DocumentBuilder getTestParser()
                                                       throws javax.xml.parsers.ParserConfigurationException
Get the DocumentBuilder instance used to parse the test XML in an XMLTestCase.

Returns:
parser for test values
Throws:
javax.xml.parsers.ParserConfigurationException

getTestDocumentBuilderFactory

public static javax.xml.parsers.DocumentBuilderFactory getTestDocumentBuilderFactory()
Get the DocumentBuilderFactory instance used to instantiate parsers for the test XML in an XMLTestCase.

Returns:
factory for test parsers

setTestDocumentBuilderFactory

public static void setTestDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
Override the DocumentBuilderFactory used to instantiate parsers for the test XML in an XMLTestCase.


setIgnoreWhitespace

public static void setIgnoreWhitespace(boolean ignore)
Whether to ignore whitespace when comparing node values. This method also invokes setIgnoringElementContentWhitespace() on the underlying control AND test document builder factories.


getIgnoreWhitespace

public static boolean getIgnoreWhitespace()
Whether to ignore whitespace when comparing node values.

Returns:
true if whitespace should be ignored when comparing nodes, false otherwise

compare

public static org.custommonkey.xmlunit.Diff compare(java.io.Reader control,
                                                    java.io.Reader test)
                                             throws org.xml.sax.SAXException,
                                                    java.io.IOException,
                                                    javax.xml.parsers.ParserConfigurationException
Deprecated. use Diff constructor directly

Compare XML documents provided by two Reader classes.

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compare

public static org.custommonkey.xmlunit.Diff compare(org.xml.sax.InputSource control,
                                                    org.xml.sax.InputSource test)
                                             throws org.xml.sax.SAXException,
                                                    java.io.IOException,
                                                    javax.xml.parsers.ParserConfigurationException
Deprecated. use Diff constructor directly

Compare two XML documents provided by SAX InputSources

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compare

public static org.custommonkey.xmlunit.Diff compare(java.lang.String control,
                                                    java.io.Reader test)
                                             throws org.xml.sax.SAXException,
                                                    java.io.IOException,
                                                    javax.xml.parsers.ParserConfigurationException
Deprecated. use Diff constructor directly

Compare two XML documents provided by a string and a Reader.

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compare

public static org.custommonkey.xmlunit.Diff compare(java.io.Reader control,
                                                    java.lang.String test)
                                             throws org.xml.sax.SAXException,
                                                    java.io.IOException,
                                                    javax.xml.parsers.ParserConfigurationException
Deprecated. use Diff constructor directly

Compare two XML documents provided by a Reader and a string.

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compare

public static org.custommonkey.xmlunit.Diff compare(java.lang.String control,
                                                    java.lang.String test)
                                             throws org.xml.sax.SAXException,
                                                    java.io.IOException,
                                                    javax.xml.parsers.ParserConfigurationException
Deprecated. use Diff constructor directly

Compare two XML documents provided as strings.

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

buildControlDocument

public static org.w3c.dom.Document buildControlDocument(java.lang.String fromXML)
                                                 throws org.xml.sax.SAXException,
                                                        java.io.IOException,
                                                        javax.xml.parsers.ParserConfigurationException
Utility method to build a Document using the control DocumentBuilder to parse the specified String.

Parameters:
fromXML -
Returns:
Document representation of the String content
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

buildControlDocument

public static org.w3c.dom.Document buildControlDocument(org.xml.sax.InputSource fromSource)
                                                 throws java.io.IOException,
                                                        org.xml.sax.SAXException,
                                                        javax.xml.parsers.ParserConfigurationException
Utility method to build a Document using the control DocumentBuilder and the specified InputSource

Parameters:
fromSource -
Returns:
Document representation of the String content
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

buildTestDocument

public static org.w3c.dom.Document buildTestDocument(java.lang.String fromXML)
                                              throws org.xml.sax.SAXException,
                                                     java.io.IOException,
                                                     javax.xml.parsers.ParserConfigurationException
Utility method to build a Document using the test DocumentBuilder to parse the specified String.

Parameters:
fromXML -
Returns:
Document representation of the String content
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

buildTestDocument

public static org.w3c.dom.Document buildTestDocument(org.xml.sax.InputSource fromSource)
                                              throws java.io.IOException,
                                                     org.xml.sax.SAXException,
                                                     javax.xml.parsers.ParserConfigurationException
Utility method to build a Document using the test DocumentBuilder and the specified InputSource

Parameters:
fromSource -
Returns:
Document representation of the String content
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

buildDocument

public static org.w3c.dom.Document buildDocument(javax.xml.parsers.DocumentBuilder withBuilder,
                                                 java.io.Reader fromReader)
                                          throws org.xml.sax.SAXException,
                                                 java.io.IOException
Utility method to build a Document using a specific DocumentBuilder and reading characters from a specific Reader.

Parameters:
withBuilder -
fromReader -
Returns:
Document built
Throws:
org.xml.sax.SAXException
java.io.IOException

buildDocument

public static org.w3c.dom.Document buildDocument(javax.xml.parsers.DocumentBuilder withBuilder,
                                                 org.xml.sax.InputSource fromSource)
                                          throws java.io.IOException,
                                                 org.xml.sax.SAXException
Utility method to build a Document using a specific DocumentBuilder and a specific InputSource

Parameters:
withBuilder -
fromSource -
Returns:
Document built
Throws:
org.xml.sax.SAXException
java.io.IOException

setTransformerFactory

public static void setTransformerFactory(java.lang.String className)
                                  throws javax.xml.transform.TransformerFactoryConfigurationError
Overide the transformer to use for XSLT transformations (and by implication serialization and XPaths). This is useful when comparing transformer implementations.

Throws:
javax.xml.transform.TransformerFactoryConfigurationError

getTransformerFactory

public static javax.xml.transform.TransformerFactory getTransformerFactory()
                                                                    throws javax.xml.transform.TransformerFactoryConfigurationError
Get the transformer to use for XSLT transformations (and by implication serialization and XPaths).

Returns:
the current transformer factory in use
Throws:
javax.xml.transform.TransformerFactoryConfigurationError - if unable to construct a new instance of the default transformer factory
javax.xml.transform.TransformerFactoryConfigurationError

setSAXParserFactory

public static void setSAXParserFactory(java.lang.String className)
Override the SAX parser to use in tests. Currently only used by Validator class

Parameters:
className -

getSAXParserFactory

public static javax.xml.parsers.SAXParserFactory getSAXParserFactory()
Get the SAX parser to use in tests.

Returns:
the SAXParserFactory instance used by the Validator to perform DTD validation

getStripWhitespaceTransform

public static org.custommonkey.xmlunit.Transform getStripWhitespaceTransform(org.w3c.dom.Document forDocument)
                                                                      throws javax.xml.transform.TransformerConfigurationException
Obtain the transformation that will strip whitespace from a DOM containing empty Text nodes

Parameters:
forDocument -
Returns:
a Transform to do the whitespace stripping
Throws:
javax.xml.transform.TransformerConfigurationException

getVersion

public static java.lang.String getVersion()
Place holder for current version info.

Returns:
current version

compareXML

public static org.custommonkey.xmlunit.Diff compareXML(java.io.Reader control,
                                                       java.io.Reader test)
                                                throws org.xml.sax.SAXException,
                                                       java.io.IOException,
                                                       javax.xml.parsers.ParserConfigurationException
Compare XML documents provided by two Reader classes

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compareXML

public static org.custommonkey.xmlunit.Diff compareXML(java.lang.String control,
                                                       java.io.Reader test)
                                                throws org.xml.sax.SAXException,
                                                       java.io.IOException,
                                                       javax.xml.parsers.ParserConfigurationException
Compare XML documents provided by two Reader classes

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compareXML

public static org.custommonkey.xmlunit.Diff compareXML(java.io.Reader control,
                                                       java.lang.String test)
                                                throws org.xml.sax.SAXException,
                                                       java.io.IOException,
                                                       javax.xml.parsers.ParserConfigurationException
Compare XML documents provided by two Reader classes

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compareXML

public static org.custommonkey.xmlunit.Diff compareXML(java.lang.String control,
                                                       java.lang.String test)
                                                throws org.xml.sax.SAXException,
                                                       java.io.IOException,
                                                       javax.xml.parsers.ParserConfigurationException
Compare two XML documents provided as strings

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents
Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

compareXML

public static org.custommonkey.xmlunit.Diff compareXML(org.w3c.dom.Document control,
                                                       org.w3c.dom.Document test)
Compare two XML documents provided as strings

Parameters:
control - Control document
test - Document to test
Returns:
Diff object describing differences in documents

XMLUnit is hosted by sourceforge.net