org.custommonkey.xmlunit

Class XMLAssert

public class XMLAssert extends Assert implements XSLTConstants

Collection of static methods so that XML assertion facilities are available in any class, not just test suites. Thanks to Andrew McCormick and others for suggesting this refactoring.
Available assertion methods are: All underlying similarity and difference testing is done using Diff instances which can be instantiated and evaluated independently of this class.

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

Constructor Summary
protected XMLAssert()
Method Summary
static voidassertNodeTestPasses(String xmlString, NodeTester tester, short nodeType)
Execute a NodeTest for a single node type and assert that it passes
static 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
static voidassertXMLEqual(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.
static voidassertXMLEqual(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not similar.
static voidassertXMLEqual(String control, String test)
Assert that two XML documents are similar
static voidassertXMLEqual(Document control, Document test)
Assert that two XML documents are similar
static voidassertXMLEqual(Reader control, Reader test)
Assert that two XML documents are similar
static voidassertXMLEqual(String err, String control, String test)
Assert that two XML documents are similar
static voidassertXMLEqual(String err, Document control, Document test)
Assert that two XML documents are similar
static voidassertXMLEqual(String err, Reader control, Reader test)
Assert that two XML documents are similar
static voidassertXMLIdentical(Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical
static voidassertXMLIdentical(Diff diff, boolean assertion, String msg)
Assert that the result of an XML comparison is or is not identical
static voidassertXMLIdentical(String msg, Diff diff, boolean assertion)
Assert that the result of an XML comparison is or is not identical
static voidassertXMLNotEqual(String control, String test)
Assert that two XML documents are NOT similar
static voidassertXMLNotEqual(String err, String control, String test)
Assert that two XML documents are NOT similar
static voidassertXMLNotEqual(Document control, Document test)
Assert that two XML documents are NOT similar
static voidassertXMLNotEqual(String err, Document control, Document test)
Assert that two XML documents are NOT similar
static voidassertXMLNotEqual(Reader control, Reader test)
Assert that two XML documents are NOT similar
static voidassertXMLNotEqual(String err, Reader control, Reader test)
Assert that two XML documents are NOT similar
static voidassertXMLValid(String xmlString)
Assert that a String containing XML contains valid XML: the String must contain a DOCTYPE declaration to be validated
static 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
static 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.
static voidassertXMLValid(Validator validator)
Assert that a Validator instance returns isValid() == true
static voidassertXpathEvaluatesTo(String expectedValue, String xpathExpression, String inXMLString)
Assert the value of an Xpath expression in an XML String
static voidassertXpathEvaluatesTo(String expectedValue, String xpathExpression, Document inDocument)
Assert the value of an Xpath expression in an DOM Document
static voidassertXpathExists(String xPathExpression, String inXMLString)
Assert that a specific XPath exists in some given XML
static voidassertXpathExists(String xPathExpression, Document inDocument)
Assert that a specific XPath exists in some given XML
static voidassertXpathNotExists(String xPathExpression, String inXMLString)
Assert that a specific XPath does NOT exist in some given XML
static voidassertXpathNotExists(String xPathExpression, Document inDocument)
Assert that a specific XPath does NOT exist in some given XML
static voidassertXpathsEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are equal
static voidassertXpathsEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are equal
static voidassertXpathsEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are equal
static voidassertXpathsEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are equal
static voidassertXpathsNotEqual(String controlXpath, String testXpath, Document document)
Assert that the node lists of two Xpaths in the same document are NOT equal
static voidassertXpathsNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the node lists of two Xpaths in the same XML string are NOT equal
static voidassertXpathsNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the node lists of two Xpaths in two XML strings are NOT equal
static voidassertXpathsNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the node lists of two Xpaths in two documents are NOT equal
static voidassertXpathValuesEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are equal
static voidassertXpathValuesEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are equal
static voidassertXpathValuesEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are equal
static voidassertXpathValuesEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are equal
static voidassertXpathValuesNotEqual(String controlXpath, String testXpath, String inXMLString)
Assert that the evaluation of two Xpaths in the same XML string are NOT equal
static voidassertXpathValuesNotEqual(String controlXpath, String testXpath, Document document)
Assert that the evaluation of two Xpaths in the same document are NOT equal
static voidassertXpathValuesNotEqual(String controlXpath, String inControlXMLString, String testXpath, String inTestXMLString)
Assert that the evaluation of two Xpaths in two XML strings are NOT equal
static voidassertXpathValuesNotEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument)
Assert that the evaluation of two Xpaths in two documents are NOT equal

Constructor Detail

XMLAssert

protected XMLAssert()

Method Detail

assertNodeTestPasses

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

assertXMLEqual

public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static 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 static void assertXMLValid(Validator validator)
Assert that a Validator instance returns isValid() == true

Parameters: validator

assertXpathEvaluatesTo

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