Class DifferenceEngine

    • Method Detail

      • compare

        public void compare​(org.w3c.dom.Node control,
                            org.w3c.dom.Node test,
                            DifferenceListener listener,
                            ElementQualifier elementQualifier)
        Entry point for Node comparison testing.
        Specified by:
        compare in interface DifferenceEngineContract
        Parameters:
        control - Control XML to compare
        test - Test XML to compare
        listener - Notified of any differences detected during node comparison testing
        elementQualifier - Used to determine which elements qualify for comparison e.g. when a node has repeated child elements that may occur in any sequence and that sequence is not considered important.
      • getNullOrNotNull

        private static java.lang.String getNullOrNotNull​(org.w3c.dom.Node aNode)
      • compareNodeBasics

        protected boolean compareNodeBasics​(org.w3c.dom.Node control,
                                            org.w3c.dom.Node test,
                                            DifferenceListener listener)
                                     throws DifferenceEngine.DifferenceFoundException
        Compares node type and node namespace characteristics: basically determines if nodes are comparable further
        Parameters:
        control - control node
        test - test node
        listener - difference listener
        Returns:
        true if the nodes are comparable further, false otherwise
        Throws:
        DifferenceEngine.DifferenceFoundException - if a difference has been found
      • comparingTextAndCDATA

        private boolean comparingTextAndCDATA​(short controlType,
                                              short testType)
      • hasChildNodes

        private java.lang.Boolean hasChildNodes​(org.w3c.dom.Node n)
        Tests whether a Node has children, taking ignoreComments setting into account.
      • nodeList2List

        static java.util.List<org.w3c.dom.Node> nodeList2List​(org.w3c.dom.NodeList nl)
        Returns the NodeList's Nodes as List, taking ignoreComments into account.
      • compareNodeList

        protected void compareNodeList​(java.util.List<org.w3c.dom.Node> controlChildren,
                                       java.util.List<org.w3c.dom.Node> testChildren,
                                       int numNodes,
                                       DifferenceListener listener,
                                       ElementQualifier elementQualifier)
                                throws DifferenceEngine.DifferenceFoundException
        Compare the contents of two node list one by one, assuming that order of children is NOT important: matching begins at same position in test list as control list.
        Parameters:
        controlChildren - children of the control node
        testChildren - children of the test node
        numNodes - convenience parameter because the calling method should know the value already
        listener - difference listener
        elementQualifier - used to determine which of the child elements in the test NodeList should be compared to the current child element in the control NodeList.
        Throws:
        DifferenceEngine.DifferenceFoundException - if a difference has been found
      • isNamespaced

        private static boolean isNamespaced​(org.w3c.dom.Node aNode)
        Parameters:
        aNode -
        Returns:
        true if the node has a namespace
      • getNonSpecialAttrLength

        private java.lang.Integer getNonSpecialAttrLength​(org.w3c.dom.NamedNodeMap attributes)
        The number of attributes not related to namespace declarations and/or Schema location.
      • getUnNamespacedNodeName

        private java.lang.String getUnNamespacedNodeName​(org.w3c.dom.Node aNode)
      • getUnNamespacedNodeName

        private static java.lang.String getUnNamespacedNodeName​(org.w3c.dom.Node aNode,
                                                                boolean isNamespacedNode)
      • getQName

        private java.lang.String getQName​(org.w3c.dom.Node aNode)
      • getQName

        private static java.lang.String getQName​(org.w3c.dom.Node aNode,
                                                 boolean isNamespacedNode)
      • isXMLNSAttribute

        private boolean isXMLNSAttribute​(org.w3c.dom.Attr attribute)
        Parameters:
        attribute -
        Returns:
        true if the attribute represents a namespace declaration
      • isRecognizedXMLSchemaInstanceAttribute

        private boolean isRecognizedXMLSchemaInstanceAttribute​(org.w3c.dom.Attr attr)
        Parameters:
        attr -
        Returns:
        true if the attribute is an XML Schema Instance namespace attribute XMLUnit treats in a special way.
      • compare

        protected void compare​(java.lang.Object expected,
                               java.lang.Object actual,
                               org.w3c.dom.Node control,
                               org.w3c.dom.Node test,
                               DifferenceListener listener,
                               Difference difference)
                        throws DifferenceEngine.DifferenceFoundException
        If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.
        Parameters:
        expected - expected value
        actual - value
        control - control node
        test - test node
        listener - difference listener
        difference - difference type
        Throws:
        DifferenceEngine.DifferenceFoundException - if a difference has been found
      • compare

        protected void compare​(java.lang.Object expected,
                               java.lang.Object actual,
                               org.w3c.dom.Node control,
                               org.w3c.dom.Node test,
                               DifferenceListener listener,
                               Difference difference,
                               XpathNodeTracker controlLoc,
                               XpathNodeTracker testLoc)
                        throws DifferenceEngine.DifferenceFoundException
        If the expected and actual values are unequal then inform the listener of a difference and throw a DifferenceFoundException.
        Parameters:
        expected - expected value
        actual - value
        control - control node
        controlLoc - XPath location of control node
        test - test node
        testLoc - XPath location of test node
        listener - difference listener
        difference - difference type
        Throws:
        DifferenceEngine.DifferenceFoundException - if a difference has been found
      • unequal

        private boolean unequal​(java.lang.Object expected,
                                java.lang.Object actual)
        Test two possibly null values for inequality
        Parameters:
        expected -
        actual -
        Returns:
        TRUE if the values are neither both null, nor equals() equal
      • unequalNotNull

        private boolean unequalNotNull​(java.lang.Object expected,
                                       java.lang.Object actual)
        Test two non-null values for inequality
        Parameters:
        expected -
        actual -
        Returns:
        TRUE if the values are not equals() equal (taking whitespace into account if necessary)
      • normalizeWhitespace

        static final java.lang.String normalizeWhitespace​(java.lang.String orig)
        Replace all whitespace characters with SPACE and collapse consecutive whitespace chars to a single SPACE.