Class XMLTestCase

  • All Implemented Interfaces:
    junit.framework.Test, XMLConstants, XSLTConstants

    public abstract class XMLTestCase
    extends junit.framework.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:
    Diff.similar(), Diff.identical()
    • 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

      • compareXML

        public Diff compareXML​(InputSource control,
                               InputSource test)
                        throws SAXException,
                               IOException
        Compare XML documents provided by two InputSource classes
        Parameters:
        control - Control document
        test - Document to test
        Returns:
        Diff object describing differences in documents
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • compareXML

        public Diff compareXML​(Reader control,
                               Reader test)
                        throws SAXException,
                               IOException
        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 - if the parser says so
        IOException - on I/O errors
      • compareXML

        public Diff compareXML​(String control,
                               Reader test)
                        throws SAXException,
                               IOException
        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 - if the parser says so
        IOException - on I/O errors
      • compareXML

        public Diff compareXML​(Reader control,
                               String test)
                        throws SAXException,
                               IOException
        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 - if the parser says so
        IOException - on I/O errors
      • compareXML

        public Diff compareXML​(String control,
                               String test)
                        throws SAXException,
                               IOException
        Compare two XML documents provided as strings
        Parameters:
        control - Control document
        test - Document to test
        Returns:
        Diff object describing differences in documents
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • 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
      • 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​(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
      • 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​(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
      • assertXMLEqual

        public void assertXMLEqual​(String control,
                                   String test)
                            throws SAXException,
                                   IOException
        Assert that two XML documents are similar
        Parameters:
        control - XML to be compared against
        test - XML to be tested
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • 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)
                            throws SAXException,
                                   IOException
        Assert that two XML documents are similar
        Parameters:
        control - XML to be compared against
        test - XML to be tested
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • assertXMLEqual

        public void assertXMLEqual​(String err,
                                   String control,
                                   String test)
                            throws SAXException,
                                   IOException
        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 - if the parser says so
        IOException - on I/O errors
      • assertXMLEqual

        public void assertXMLEqual​(String err,
                                   InputSource control,
                                   InputSource test)
                            throws SAXException,
                                   IOException
        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 - if the parser says so
        IOException - on I/O errors
      • 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)
                            throws SAXException,
                                   IOException
        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 - if the parser says so
        IOException - on I/O errors
      • assertXMLNotEqual

        public void assertXMLNotEqual​(String control,
                                      String test)
                               throws SAXException,
                                      IOException
        Assert that two XML documents are NOT similar
        Parameters:
        control - XML to be compared against
        test - XML to be tested
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • 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​(Reader control,
                                      Reader test)
                               throws SAXException,
                                      IOException
        Assert that two XML documents are NOT similar
        Parameters:
        control - XML to be compared against
        test - XML to be tested
        Throws:
        SAXException - if the parser says so
        IOException - on I/O errors
      • assertXMLNotEqual

        public void assertXMLNotEqual​(String err,
                                      InputSource control,
                                      InputSource test)
                               throws SAXException,
                                      IOException
        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 - if the parser says so
        IOException - on I/O errors
      • assertXMLNotEqual

        public void assertXMLNotEqual​(String err,
                                      String control,
                                      String test)
                               throws SAXException,
                                      IOException
        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 - if the parser says so
        IOException - on I/O errors
      • 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​(String err,
                                      Reader control,
                                      Reader test)
                               throws SAXException,
                                      IOException
        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 - if the parser says so
        IOException - on I/O errors
      • assertXpathsEqual

        public void assertXpathsEqual​(String controlXpath,
                                      String testXpath,
                                      Document document)
                               throws XpathException
        Assert that the node lists of two Xpaths in the same document are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        document - document to apply XPaths to
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathsEqual

        public void assertXpathsEqual​(String controlXpath,
                                      String inControlXMLString,
                                      String testXpath,
                                      String inTestXMLString)
                               throws SAXException,
                                      IOException,
                                      XpathException
        Assert that the node lists of two Xpaths in two XML strings are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inControlXMLString - document for expected value
        inTestXMLString - document for actual value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathsEqual

        public void assertXpathsEqual​(String controlXpath,
                                      Document controlDocument,
                                      String testXpath,
                                      Document testDocument)
                               throws XpathException
        Assert that the node lists of two Xpaths in two documents are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        controlDocument - document for expected value
        testDocument - document for actual value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathsNotEqual

        public void assertXpathsNotEqual​(String controlXpath,
                                         String testXpath,
                                         Document document)
                                  throws XpathException
        Assert that the node lists of two Xpaths in the same document are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        document - document to apply XPaths to
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathsNotEqual

        public void assertXpathsNotEqual​(String controlXpath,
                                         String testXpath,
                                         String inXMLString)
                                  throws SAXException,
                                         IOException,
                                         XpathException
        Assert that the node lists of two Xpaths in the same XML string are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inXMLString - document to apply XPaths to
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathsNotEqual

        public void assertXpathsNotEqual​(String controlXpath,
                                         String inControlXMLString,
                                         String testXpath,
                                         String inTestXMLString)
                                  throws SAXException,
                                         IOException,
                                         XpathException
        Assert that the node lists of two Xpaths in two XML strings are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inControlXMLString - document for expected value
        inTestXMLString - document for actual value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathsNotEqual

        public void assertXpathsNotEqual​(String controlXpath,
                                         Document controlDocument,
                                         String testXpath,
                                         Document testDocument)
                                  throws XpathException
        Assert that the node lists of two Xpaths in two documents are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        controlDocument - document for expected value
        testDocument - document for actual value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathValuesEqual

        public void assertXpathValuesEqual​(String controlXpath,
                                           String testXpath,
                                           Document document)
                                    throws XpathException
        Assert that the evaluation of two Xpaths in the same document are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        document - document for expected value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathValuesEqual

        public void assertXpathValuesEqual​(String controlXpath,
                                           String testXpath,
                                           String inXMLString)
                                    throws SAXException,
                                           IOException,
                                           XpathException
        Assert that the evaluation of two Xpaths in the same XML string are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inXMLString - document for expected value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathValuesEqual

        public void assertXpathValuesEqual​(String controlXpath,
                                           String inControlXMLString,
                                           String testXpath,
                                           String inTestXMLString)
                                    throws SAXException,
                                           IOException,
                                           XpathException
        Assert that the evaluation of two Xpaths in two XML strings are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inControlXMLString - document for expected value
        inTestXMLString - document for actual value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathValuesEqual

        public void assertXpathValuesEqual​(String controlXpath,
                                           Document controlDocument,
                                           String testXpath,
                                           Document testDocument)
                                    throws XpathException
        Assert that the evaluation of two Xpaths in two documents are equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        controlDocument - document for expected value
        testDocument - document for actual value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathValuesNotEqual

        public void assertXpathValuesNotEqual​(String controlXpath,
                                              String testXpath,
                                              String inXMLString)
                                       throws SAXException,
                                              IOException,
                                              XpathException
        Assert that the evaluation of two Xpaths in the same XML string are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inXMLString - document for expected value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathValuesNotEqual

        public void assertXpathValuesNotEqual​(String controlXpath,
                                              String testXpath,
                                              Document document)
                                       throws XpathException
        Assert that the evaluation of two Xpaths in the same document are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        document - document for expected value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXpathValuesNotEqual

        public void assertXpathValuesNotEqual​(String controlXpath,
                                              String inControlXMLString,
                                              String testXpath,
                                              String inTestXMLString)
                                       throws SAXException,
                                              IOException,
                                              XpathException
        Assert that the evaluation of two Xpaths in two XML strings are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        inControlXMLString - document for expected value
        inTestXMLString - document for actual value
        Throws:
        XpathException - if XPath construction fails
        SAXException - if the parser says so
        IOException - on I/O errors
        See Also:
        XpathEngine
      • assertXpathValuesNotEqual

        public void assertXpathValuesNotEqual​(String controlXpath,
                                              Document controlDocument,
                                              String testXpath,
                                              Document testDocument)
                                       throws XpathException
        Assert that the evaluation of two Xpaths in two documents are NOT equal
        Parameters:
        controlXpath - XPath for expected value
        testXpath - XPath for actual value
        controlDocument - document for expected value
        testDocument - document for actual value
        Throws:
        XpathException - if XPath construction fails
        See Also:
        XpathEngine
      • assertXMLValid

        public void assertXMLValid​(InputSource xml,
                                   String systemId)
                            throws SAXException,
                                   ConfigurationException
        Assert that a piece of XML contains valid XML: the document must contain a DOCTYPE to be validated, but the validation will use the systemId to obtain the DTD
        Parameters:
        xml - the document to validate
        systemId - used to obtain the DTD
        Throws:
        SAXException - if the parser says so
        ConfigurationException - if validation could not be turned on
        See Also:
        Validator
      • assertXMLValid

        public void assertXMLValid​(String xmlString,
                                   String systemId)
                            throws SAXException,
                                   ConfigurationException
        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 - the document to validate
        systemId - used to obtain the DTD
        Throws:
        SAXException - if the parser says so
        ConfigurationException - if validation could not be turned on
        See Also:
        Validator
      • assertXMLValid

        public void assertXMLValid​(InputSource xml,
                                   String systemId,
                                   String doctype)
                            throws SAXException,
                                   ConfigurationException
        Assert that a piece of XML contains valid XML: the document will be given a DOCTYPE to be validated with the name and systemId specified regardless of whether it already contains a doctype declaration.
        Parameters:
        xml - the document to validate
        systemId - used to obtain the DTD
        doctype - DOCTYPE to use during validation
        Throws:
        SAXException - if the parser says so
        ConfigurationException - if validation could not be turned on
        See Also:
        Validator
      • assertXMLValid

        public void assertXMLValid​(String xmlString,
                                   String systemId,
                                   String doctype)
                            throws SAXException,
                                   ConfigurationException
        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 - the document to validate
        systemId - used to obtain the DTD
        doctype - DOCTYPE to use during validation
        Throws:
        SAXException - if the parser says so
        ConfigurationException - if validation could not be turned on
        See Also:
        Validator
      • assertXMLValid

        public void assertXMLValid​(Validator validator)
        Assert that a Validator instance returns isValid() == true
        Parameters:
        validator - validator
      • 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 e.g. Node.ELEMENT_NODE
        assertion - true if the test is expected to pass, false otherwise
        See Also:
        AbstractNodeTester, CountingNodeTester