Ejemplo n.º 1
0
  /**
   * Get differences between doms.
   *
   * @param controlDom The control dom.
   * @param testDom The test dom.
   * @param ignoreAttributes The list of attributes to ignore.
   * @return The differences.
   */
  @SuppressWarnings("unchecked")
  public static List<Difference> getDifferences(
      String controlDom, String testDom, final List<String> ignoreAttributes) {
    try {
      Diff d = new Diff(Helper.getDocument(controlDom), Helper.getDocument(testDom));
      DetailedDiff dd = new DetailedDiff(d);
      dd.overrideDifferenceListener(
          new DifferenceListener() {

            @Override
            public void skippedComparison(Node control, Node test) {}

            @Override
            public int differenceFound(Difference difference) {
              if (difference.getControlNodeDetail() == null
                  || difference.getControlNodeDetail().getNode() == null
                  || difference.getTestNodeDetail() == null
                  || difference.getTestNodeDetail().getNode() == null) {
                return RETURN_ACCEPT_DIFFERENCE;
              }
              if (ignoreAttributes.contains(difference.getTestNodeDetail().getNode().getNodeName())
                  || ignoreAttributes.contains(
                      difference.getControlNodeDetail().getNode().getNodeName())) {
                return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
              }
              return RETURN_ACCEPT_DIFFERENCE;
            }
          });

      return dd.getAllDifferences();
    } catch (Exception e) {
      LOGGER.error("Error with getDifferences: " + e.getMessage(), e);
    }
    return null;
  }