org.appng.testsupport.validation

## Class XPathDifferenceHandler

- java.lang.Object
- - org.appng.testsupport.validation.DifferenceHandler
  - - org.appng.testsupport.validation.XPathDifferenceHandler

- All Implemented Interfaces:
    org.custommonkey.xmlunit.DifferenceListener

      public class XPathDifferenceHandler
      extends DifferenceHandler

  A `DifferenceListener` which ignores the `Difference` if the XPath of the node was added to ignorable expressions using `ignoreDifference(String)`. Multiple XPath expressions can be added to the ignore list by calling `ignoreDifference(String)`. Note that these expressions must be the complete absolute XPath location starting from the document root.
  Author:
    Matthias Müller
  See Also:
    `Difference.getControlNodeDetail()`, `Difference.getTestNodeDetail()`, `NodeDetail.getXpathLocation()`

- - ### Field Summary

    - ### Fields inherited from interface org.custommonkey.xmlunit.DifferenceListener

      `RETURN_ACCEPT_DIFFERENCE, RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL, RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR, RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `XPathDifferenceHandler()` Delegates to `XPathDifferenceHandler(boolean)` with `stripPositions = true`.
    `XPathDifferenceHandler(boolean stripPositions)` Creates a new `XPathDifferenceHandler`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDifferenceListener(String xpath, org.custommonkey.xmlunit.DifferenceListener differenceListener)` Registers a custom `DifferenceListener` for the given XPath expression
    `int` | `differenceFound(org.custommonkey.xmlunit.Difference difference)`
    `void` | `ignoreDifference(String xpath)` Ignore the `Difference` with the given XPath expression

    - ### Methods inherited from class org.appng.testsupport.validation.DifferenceHandler

      `skippedComparison`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XPathDifferenceHandler

          public XPathDifferenceHandler(boolean stripPositions)

      Creates a new `XPathDifferenceHandler`.

      If there is a difference you want to ignore at the following XPath location

           /datasource/data/selection[2]/option[4]

      you can achieve this by either setting up your `XPathDifferenceHandler` like this

           DifferenceHandler differenceHandler = new XPathDifferenceHandler(true);
           differenceHandler.ignoreDifference("/datasource/data/selection/option");

      or this

           DifferenceHandler differenceHandler = new XPathDifferenceHandler(false);
           differenceHandler.ignoreDifference("/datasource/data/selection[2]/option[4]");

      In the first case, with `stripPositions = true`, you can omit the positions from the expression. As a side effect, every `Difference` with the (stripped) XPath of `/datasource/data/selection/option` will be ignored.
      In the second case, there needs to be an exact match between the registered XPath location and the one from the `Difference`.
      Parameters:
        `stripPositions` - whether or not to strip the positions from the actual XPath of the `Difference` before checking the registry for an appropriate `DifferenceListener`

    - #### XPathDifferenceHandler

          public XPathDifferenceHandler()

      Delegates to `XPathDifferenceHandler(boolean)` with `stripPositions = true`.
      See Also:
        `XPathDifferenceHandler(boolean)`

  - ### Method Detail

    - #### ignoreDifference

          public void ignoreDifference(String xpath)

      Ignore the `Difference` with the given XPath expression
      Parameters:
        `xpath` - the XPath expression. Note that this must be the complete absolute XPath location starting from the document root.

    - #### addDifferenceListener

          public void addDifferenceListener(String xpath,
                                            org.custommonkey.xmlunit.DifferenceListener differenceListener)

      Registers a custom `DifferenceListener` for the given XPath expression
      Parameters:
        `xpath` - the XPath expression. Note that this must be the complete absolute XPath location starting from the document root.
        `differenceListener` - the `DifferenceListener` to register

    - #### differenceFound

          public int differenceFound(org.custommonkey.xmlunit.Difference difference)

      Specified by:
        `differenceFound` in interface `org.custommonkey.xmlunit.DifferenceListener`
      Specified by:
        `differenceFound` in class `DifferenceHandler`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.