org.custommonkey.xmlunit

Class XMLUnit

public final class XMLUnit extends 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 DocumentbuildControlDocument(String fromXML)
Utility method to build a Document using the control DocumentBuilder to parse the specified String.
static DocumentbuildControlDocument(InputSource fromSource)
Utility method to build a Document using the control DocumentBuilder and the specified InputSource
static DocumentbuildDocument(DocumentBuilder withBuilder, Reader fromReader)
Utility method to build a Document using a specific DocumentBuilder and reading characters from a specific Reader.
static DocumentbuildDocument(DocumentBuilder withBuilder, InputSource fromSource)
Utility method to build a Document using a specific DocumentBuilder and a specific InputSource
static DocumentbuildTestDocument(String fromXML)
Utility method to build a Document using the test DocumentBuilder to parse the specified String.
static DocumentbuildTestDocument(InputSource fromSource)
Utility method to build a Document using the test DocumentBuilder and the specified InputSource
static Diffcompare(Reader control, Reader test)
Compare XML documents provided by two Reader classes.
static Diffcompare(InputSource control, InputSource test)
Compare two XML documents provided by SAX InputSources
static Diffcompare(String control, Reader test)
Compare two XML documents provided by a string and a Reader.
static Diffcompare(Reader control, String test)
Compare two XML documents provided by a Reader and a string.
static Diffcompare(String control, String test)
Compare two XML documents provided as strings.
static DiffcompareXML(Reader control, Reader test)
Compare XML documents provided by two Reader classes
static DiffcompareXML(String control, Reader test)
Compare XML documents provided by two Reader classes
static DiffcompareXML(Reader control, String test)
Compare XML documents provided by two Reader classes
static DiffcompareXML(String control, String test)
Compare two XML documents provided as strings
static DiffcompareXML(Document control, Document test)
Compare two XML documents provided as strings
static DocumentBuilderFactorygetControlDocumentBuilderFactory()
Get the DocumentBuilderFactory instance used to instantiate parsers for the control XML in an XMLTestCase.
static DocumentBuildergetControlParser()
Get the DocumentBuilder instance used to parse the control XML in an XMLTestCase.
static booleangetIgnoreWhitespace()
Whether to ignore whitespace when comparing node values.
static SAXParserFactorygetSAXParserFactory()
Get the SAX parser to use in tests.
static TransformgetStripWhitespaceTransform(Document forDocument)
Obtain the transformation that will strip whitespace from a DOM containing empty Text nodes
static DocumentBuilderFactorygetTestDocumentBuilderFactory()
Get the DocumentBuilderFactory instance used to instantiate parsers for the test XML in an XMLTestCase.
static DocumentBuildergetTestParser()
Get the DocumentBuilder instance used to parse the test XML in an XMLTestCase.
static TransformerFactorygetTransformerFactory()
Get the transformer to use for XSLT transformations (and by implication serialization and XPaths).
static StringgetVersion()
Place holder for current version info.
static voidsetControlDocumentBuilderFactory(DocumentBuilderFactory factory)
Override the DocumentBuilderFactory used to instantiate parsers for the control XML in an XMLTestCase.
static voidsetControlParser(String className)
Overide the DocumentBuilder to use to parse control documents.
static voidsetIgnoreWhitespace(boolean ignore)
Whether to ignore whitespace when comparing node values.
static voidsetSAXParserFactory(String className)
Override the SAX parser to use in tests.
static voidsetTestDocumentBuilderFactory(DocumentBuilderFactory factory)
Override the DocumentBuilderFactory used to instantiate parsers for the test XML in an XMLTestCase.
static voidsetTestParser(String className)
Overide the DocumentBuilder to use to parser test documents.
static voidsetTransformerFactory(String className)
Overide the transformer to use for XSLT transformations (and by implication serialization and XPaths).

Method Detail

buildControlDocument

public static Document buildControlDocument(String fromXML)
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: SAXException IOException ParserConfigurationException

buildControlDocument

public static Document buildControlDocument(InputSource fromSource)
Utility method to build a Document using the control DocumentBuilder and the specified InputSource

Parameters: fromSource

Returns: Document representation of the String content

Throws: SAXException IOException ParserConfigurationException

buildDocument

public static Document buildDocument(DocumentBuilder withBuilder, Reader fromReader)
Utility method to build a Document using a specific DocumentBuilder and reading characters from a specific Reader.

Parameters: withBuilder fromReader

Returns: Document built

Throws: SAXException IOException

buildDocument

public static Document buildDocument(DocumentBuilder withBuilder, InputSource fromSource)
Utility method to build a Document using a specific DocumentBuilder and a specific InputSource

Parameters: withBuilder fromSource

Returns: Document built

Throws: SAXException IOException

buildTestDocument

public static Document buildTestDocument(String fromXML)
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: SAXException IOException ParserConfigurationException

buildTestDocument

public static Document buildTestDocument(InputSource fromSource)
Utility method to build a Document using the test DocumentBuilder and the specified InputSource

Parameters: fromSource

Returns: Document representation of the String content

Throws: SAXException IOException ParserConfigurationException

compare

public static Diff compare(Reader control, Reader test)

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: SAXException IOException ParserConfigurationException

compare

public static Diff compare(InputSource control, InputSource test)

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: SAXException IOException ParserConfigurationException

compare

public static Diff compare(String control, Reader test)

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: SAXException IOException ParserConfigurationException

compare

public static Diff compare(Reader control, String test)

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: SAXException IOException ParserConfigurationException

compare

public static Diff compare(String control, String test)

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: SAXException IOException ParserConfigurationException

compareXML

public static Diff compareXML(Reader control, Reader test)
Compare XML documents provided by two Reader classes

Parameters: control Control document test Document to test

Returns: Diff object describing differences in documents

Throws: SAXException IOException ParserConfigurationException

compareXML

public static Diff compareXML(String control, Reader test)
Compare XML documents provided by two Reader classes

Parameters: control Control document test Document to test

Returns: Diff object describing differences in documents

Throws: SAXException IOException ParserConfigurationException

compareXML

public static Diff compareXML(Reader control, String test)
Compare XML documents provided by two Reader classes

Parameters: control Control document test Document to test

Returns: Diff object describing differences in documents

Throws: SAXException IOException ParserConfigurationException

compareXML

public static Diff compareXML(String control, String test)
Compare two XML documents provided as strings

Parameters: control Control document test Document to test

Returns: Diff object describing differences in documents

Throws: SAXException IOException ParserConfigurationException

compareXML

public static Diff compareXML(Document control, Document test)
Compare two XML documents provided as strings

Parameters: control Control document test Document to test

Returns: Diff object describing differences in documents

getControlDocumentBuilderFactory

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

Returns: factory for control parsers

getControlParser

public static DocumentBuilder getControlParser()
Get the DocumentBuilder instance used to parse the control XML in an XMLTestCase.

Returns: parser for control values

Throws: ParserConfigurationException

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

getSAXParserFactory

public static 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 Transform getStripWhitespaceTransform(Document forDocument)
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: TransformerConfigurationException

getTestDocumentBuilderFactory

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

Returns: factory for test parsers

getTestParser

public static DocumentBuilder getTestParser()
Get the DocumentBuilder instance used to parse the test XML in an XMLTestCase.

Returns: parser for test values

Throws: ParserConfigurationException

getTransformerFactory

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

Returns: the current transformer factory in use

Throws: TransformerFactoryConfigurationError if unable to construct a new instance of the default transformer factory TransformerFactoryConfigurationError

getVersion

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

Returns: current version

setControlDocumentBuilderFactory

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

setControlParser

public static void setControlParser(String className)
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.

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.

setSAXParserFactory

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

Parameters: className

setTestDocumentBuilderFactory

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

setTestParser

public static void setTestParser(String className)
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.

setTransformerFactory

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

Throws: TransformerFactoryConfigurationError