org.custommonkey.xmlunit

Class XMLTestCase

public class XMLTestCase extends TestCase implements XSLTConstants

JUnit TestCase subclass: extend this to add XML assertion facilities to your test suites. Available assertions are provided by static methods of the XMLAssert class. NB: All underlying similarity and difference testing is done using Diff instances which can be instantiated and evaluated independently of an XMLTestCase.

See Also: similar
Examples and more at
xmlunit.sourceforge.net

Constructor Summary
XMLTestCase()
Construct a new XML test case.
XMLTestCase(String name)
Construct a new test case.
Method Summary
voidassertNodeTestPasses(String xmlString, NodeTester tester, short nodeType)
Execute a NodeTest for a single node type and assert that it passes
voidassertNodeTestPasses(NodeTest test, NodeTester tester, short[] nodeTypes, boolean assertion)
Execute a NodeTest for multiple node types and make an assertion about it whether it is expected to pass
voidassertNotXpathExists(String xPathExpression, String inXMLString)
Assert that a specific XPath does NOT exist in some given XML
voidassertNotXpathExists(String xPathExpression, Document inDocument)
Assert that a specific XPath does NOT exist in some given XML
voidassertXMLEqual(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.
voidassertXMLEqual(Diff diff, boolean assertion, String msg)
Assert that the result of an XML comparison is or is not similar.
voidassertXMLEqual(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.
voidassertXMLEqual(String control, String test)
Assert that two XML documents are similar
voidassertXMLEqual(Document control, Document test)
Assert that two XML documents are similar
voidassertXMLEqual(Reader control, Reader test)
Assert that two XML documents are similar
voidassertXMLEqual(String err, String control, String test)
Assert that two XML documents are similar
voidassertXMLEqual(String err, Document control, Document test)
Assert that two XML documents are similar
voidassertXMLEqual(String err, Reader control, Reader test)
Assert that two XML documents are similar
voidassertXMLIdentical(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical
voidassertXMLIdentical(Diff diff, boolean assertion, String msg)
Assert that the result of an XML comparison is or is not identical
voidassertXMLIdentical(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical
voidassertXMLNotEqual(String control, String test)
Assert that two XML documents are NOT similar
voidassertXMLNotEqual(String err, String control, String test)
Assert that two XML documents are NOT similar
voidassertXMLNotEqual(Document control, Document test)
Assert that two XML documents are NOT similar
voidassertXMLNotEqual(String err, Document control, Document test)
Assert that two XML documents are NOT similar
voidassertXMLNotEqual(Reader control, Reader test)
Assert that two XML documents are NOT similar
voidassertXMLNotEqual(String err, Reader control, Reader test)
Assert that two XML documents are NOT similar
voidassertXMLValid(String xmlString)
Assert that a String containing XML contains valid XML: the String must contain a DOCTYPE declaration to be validated
voidassertXMLValid(String xmlString, String systemId)
Assert that a String containing XML contains valid XML: the String must contain a DOCTYPE to be validated, but the validation will use the systemId to obtain the DTD
voidassertXMLValid(String xmlString, String systemId, String doctype)
Assert that a String containing XML contains valid XML: the String will be given a DOCTYPE to be validated with the name and systemId specified regardless of whether it already contains a doctype declaration.
voidassertXMLValid(Validator validator)
Assert that a Validator instance returns isValid() == true
voidassertXpathEvaluatesTo(String expectedValue, String xpathExpression, String inXMLString)
Assert the value of an Xpath expression in an XML String
voidassertXpathEvaluatesTo(String expectedValue, String xpathExpression, Document inDocument)
Assert the value of an Xpath expression in an DOM Document
voidassertXpathExists(String xPathExpression, String inXMLString)
Assert that a specific XPath exists in some given XML
voidassertXpathExists(String xPathExpression, Document inDocument)
Assert that a specific XPath exists in some given XML
voidassertXpathNotExists(String xPathExpression, String inXMLString)
Assert that a specific XPath does NOT exist in some given XML
voidassertXpathNotExists(String xPathExpression, Document inDocument)
Assert that a specific XPath does NOT exist in some given XML
voidassertXpathsEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are equal
voidassertXpathsEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are equal
voidassertXpathsEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are equal
voidassertXpathsEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are equal
voidassertXpathsNotEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are NOT equal
voidassertXpathsNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are NOT equal
voidassertXpathsNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are NOT equal
voidassertXpathsNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are NOT equal
voidassertXpathValuesEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are equal
voidassertXpathValuesEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are equal
voidassertXpathValuesEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are equal
voidassertXpathValuesEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are equal
voidassertXpathValuesNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are NOT equal
voidassertXpathValuesNotEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are NOT equal
voidassertXpathValuesNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are NOT equal
voidassertXpathValuesNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are NOT equal
DiffcompareXML(Reader control, Reader test)
Compare XML documents provided by two Reader classes
DiffcompareXML(String control, Reader test)
Compare XML documents provided by two Reader classes
DiffcompareXML(Reader control, String test)
Compare XML documents provided by two Reader classes
DiffcompareXML(String control, String test)
Compare two XML documents provided as strings
DiffcompareXML(Document control, Document test)
Compare two XML documents provided as strings
voidsetControlParser(String parser)
Overide default sax parser used to parser documents
voidsetIgnoreWhitespace(boolean ignore)
Whether to ignore whitespace in attributes and elements
voidsetTestParser(String parser)
Overide default sax parser used to parse documents

Constructor Detail

XMLTestCase

public XMLTestCase()
Construct a new XML test case.

XMLTestCase

public XMLTestCase(String name)
Construct a new test case.

Parameters: name Name of test

Method Detail

assertNodeTestPasses

public void assertNodeTestPasses(String xmlString, NodeTester tester, short nodeType)
Execute a NodeTest for a single node type and assert that it passes

Parameters: xmlString XML to be tested tester The test strategy nodeType The node type to be tested: constants defined in Node org.w3c.dom.Node e.g. Node.ELEMENT_NODE

Throws: SAXException ParserConfigurationException IOException

See Also: AbstractNodeTester CountingNodeTester

assertNodeTestPasses

public void assertNodeTestPasses(NodeTest test, NodeTester tester, short[] nodeTypes, boolean assertion)
Execute a NodeTest for multiple node types and make an assertion about it whether it is expected to pass

Parameters: test a NodeTest instance containing the XML source to be tested tester The test strategy nodeTypes The node types to be tested: constants defined in Node org.w3c.dom.Node e.g. Node.ELEMENT_NODE assertion true if the test is expected to pass, false otherwise

See Also: AbstractNodeTester CountingNodeTester

assertNotXpathExists

public void assertNotXpathExists(String xPathExpression, String inXMLString)

Deprecated: Use assertXpathNotExists instead

Assert that a specific XPath does NOT exist in some given XML

Parameters: inXpathExpression inXMLString

assertNotXpathExists

public void assertNotXpathExists(String xPathExpression, Document inDocument)

Deprecated: Use assertXpathNotExists instead

Assert that a specific XPath does NOT exist in some given XML

Parameters: inXpathExpression inDocument

assertXMLEqual

public void assertXMLEqual(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.

Parameters: diff the result of an XML comparison assertion true if asserting that result is similar

assertXMLEqual

public void assertXMLEqual(Diff diff, boolean assertion, String msg)

Deprecated: Use XMLTestCase#assertXMLEqual(String, Diff, boolean) instead

Assert that the result of an XML comparison is or is not similar.

Parameters: diff the result of an XML comparison assertion true if asserting that result is similar msg additional message to display if assertion fails

assertXMLEqual

public void assertXMLEqual(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.

Parameters: msg additional message to display if assertion fails diff the result of an XML comparison assertion true if asserting that result is similar

assertXMLEqual

public void assertXMLEqual(String control, String test)
Assert that two XML documents are similar

Parameters: control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLEqual

public void assertXMLEqual(Document control, Document test)
Assert that two XML documents are similar

Parameters: control XML to be compared against test XML to be tested

assertXMLEqual

public void assertXMLEqual(Reader control, Reader test)
Assert that two XML documents are similar

Parameters: control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLEqual

public void assertXMLEqual(String err, String control, String test)
Assert that two XML documents are similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLEqual

public void assertXMLEqual(String err, Document control, Document test)
Assert that two XML documents are similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

assertXMLEqual

public void assertXMLEqual(String err, Reader control, Reader test)
Assert that two XML documents are similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLIdentical

public void assertXMLIdentical(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical

Parameters: diff the result of an XML comparison assertion true if asserting that result is identical

assertXMLIdentical

public void assertXMLIdentical(Diff diff, boolean assertion, String msg)

Deprecated: Use XMLTestCase#assertXMLIdentical(String, Diff, boolean) instead

Assert that the result of an XML comparison is or is not identical

Parameters: diff the result of an XML comparison assertion true if asserting that result is identical msg additional message to display if assertion fails

assertXMLIdentical

public void assertXMLIdentical(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical

Parameters: msg Message to display if assertion fails diff the result of an XML comparison assertion true if asserting that result is identical

assertXMLNotEqual

public void assertXMLNotEqual(String control, String test)
Assert that two XML documents are NOT similar

Parameters: control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLNotEqual

public void assertXMLNotEqual(String err, String control, String test)
Assert that two XML documents are NOT similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLNotEqual

public void assertXMLNotEqual(Document control, Document test)
Assert that two XML documents are NOT similar

Parameters: control XML to be compared against test XML to be tested

assertXMLNotEqual

public void assertXMLNotEqual(String err, Document control, Document test)
Assert that two XML documents are NOT similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

assertXMLNotEqual

public void assertXMLNotEqual(Reader control, Reader test)
Assert that two XML documents are NOT similar

Parameters: control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLNotEqual

public void assertXMLNotEqual(String err, Reader control, Reader test)
Assert that two XML documents are NOT similar

Parameters: err Message to be displayed on assertion failure control XML to be compared against test XML to be tested

Throws: SAXException IOException ParserConfigurationException

assertXMLValid

public void assertXMLValid(String xmlString)
Assert that a String containing XML contains valid XML: the String must contain a DOCTYPE declaration to be validated

Parameters: xmlString

Throws: SAXException ParserConfigurationException

See Also: Validator

assertXMLValid

public void assertXMLValid(String xmlString, String systemId)
Assert that a String containing XML contains valid XML: the String must contain a DOCTYPE to be validated, but the validation will use the systemId to obtain the DTD

Parameters: xmlString systemId

Throws: SAXException ParserConfigurationException

See Also: Validator

assertXMLValid

public void assertXMLValid(String xmlString, String systemId, String doctype)
Assert that a String containing XML contains valid XML: the String will be given a DOCTYPE to be validated with the name and systemId specified regardless of whether it already contains a doctype declaration.

Parameters: xmlString systemId doctype

Throws: SAXException ParserConfigurationException

See Also: Validator

assertXMLValid

public void assertXMLValid(Validator validator)
Assert that a Validator instance returns isValid() == true

Parameters: validator

assertXpathEvaluatesTo

public void assertXpathEvaluatesTo(String expectedValue, String xpathExpression, String inXMLString)
Assert the value of an Xpath expression in an XML String

Parameters: expectedValue xpathExpression inXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException TransformerConfigurationException

See Also: which provides the underlying evaluation mechanism

assertXpathEvaluatesTo

public void assertXpathEvaluatesTo(String expectedValue, String xpathExpression, Document inDocument)
Assert the value of an Xpath expression in an DOM Document

Parameters: expectedValue xpathExpression inDocument

Throws: TransformerException TransformerConfigurationException

See Also: which provides the underlying evaluation mechanism

assertXpathExists

public void assertXpathExists(String xPathExpression, String inXMLString)
Assert that a specific XPath exists in some given XML

Parameters: inXpathExpression inXMLString

See Also: which provides the underlying evaluation mechanism

assertXpathExists

public void assertXpathExists(String xPathExpression, Document inDocument)
Assert that a specific XPath exists in some given XML

Parameters: inXpathExpression inDocument

See Also: which provides the underlying evaluation mechanism

assertXpathNotExists

public void assertXpathNotExists(String xPathExpression, String inXMLString)
Assert that a specific XPath does NOT exist in some given XML

Parameters: inXpathExpression inXMLString

See Also: which provides the underlying evaluation mechanism

assertXpathNotExists

public void assertXpathNotExists(String xPathExpression, Document inDocument)
Assert that a specific XPath does NOT exist in some given XML

Parameters: inXpathExpression inDocument

See Also: which provides the underlying evaluation mechanism

assertXpathsEqual

public void assertXpathsEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException

See Also: SimpleXpathEngine

assertXpathsEqual

public void assertXpathsEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are equal

Parameters: xpathOne xpathTwo inXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException

assertXpathsEqual

public void assertXpathsEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are equal

Parameters: xpathOne inControlXMLString xpathTwo inTestXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException

assertXpathsEqual

public void assertXpathsEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException

See Also: SimpleXpathEngine

assertXpathsNotEqual

public void assertXpathsNotEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are NOT equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException

See Also: SimpleXpathEngine

assertXpathsNotEqual

public void assertXpathsNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are NOT equal

Parameters: xpathOne xpathTwo inXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException

assertXpathsNotEqual

public void assertXpathsNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are NOT equal

Parameters: xpathOne inControlXMLString xpathTwo inTestXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException

assertXpathsNotEqual

public void assertXpathsNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are NOT equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException

See Also: SimpleXpathEngine

assertXpathValuesEqual

public void assertXpathValuesEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException TransformerConfigurationException

See Also: SimpleXpathEngine

assertXpathValuesEqual

public void assertXpathValuesEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are equal

Parameters: xpathOne xpathTwo inXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException TransformerConfigurationException

assertXpathValuesEqual

public void assertXpathValuesEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are equal

Parameters: xpathOne inControlXMLString xpathTwo inTestXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException TransformerConfigurationException

assertXpathValuesEqual

public void assertXpathValuesEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException TransformerConfigurationException

See Also: SimpleXpathEngine

assertXpathValuesNotEqual

public void assertXpathValuesNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are NOT equal

Parameters: xpathOne xpathTwo inXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException TransformerConfigurationException

assertXpathValuesNotEqual

public void assertXpathValuesNotEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are NOT equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException TransformerConfigurationException

assertXpathValuesNotEqual

public void assertXpathValuesNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are NOT equal

Parameters: xpathOne inControlXMLString xpathTwo inTestXMLString

Throws: SAXException IOException ParserConfigurationException TransformerException TransformerConfigurationException

assertXpathValuesNotEqual

public void assertXpathValuesNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are NOT equal

Parameters: xpathOne xpathTwo document

Throws: TransformerException TransformerConfigurationException

compareXML

public 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 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 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 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 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

setControlParser

public void setControlParser(String parser)

Deprecated: this is a global setting and should be invoked on XMLUnit instead

Overide default sax parser used to parser documents

setIgnoreWhitespace

public void setIgnoreWhitespace(boolean ignore)

Deprecated: this is a global setting and should be invoked on XMLUnit instead

Whether to ignore whitespace in attributes and elements

Parameters: ignore

setTestParser

public void setTestParser(String parser)

Deprecated: this is a global setting and should be invoked on XMLUnit instead

Overide default sax parser used to parse documents