Java Code Examples for org.custommonkey.xmlunit.DifferenceListener#RETURN_ACCEPT_DIFFERENCE

The following examples show how to use org.custommonkey.xmlunit.DifferenceListener#RETURN_ACCEPT_DIFFERENCE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public int differenceFound(Difference difference) {
  final String xpath = "/updated[1]/text()[1]";
  if(difference.getControlNodeDetail().getXpathLocation().endsWith(xpath)) {
    String controlValue = difference.getControlNodeDetail().getValue();
    String testValue = difference.getTestNodeDetail().getValue();
    // Allow a difference of up to 2 seconds.
    try {
      long controlTime = UPDATED_FORMAT.parse(controlValue).getTime();
      long testTime = UPDATED_FORMAT.parse(testValue).getTime();
      long diff = controlTime - testTime;
      if (diff < 0) {
        diff = diff * -1;
      }
      if (diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
        return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
      }
    } catch (ParseException e) {
      throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
    }
  }
  // Yes it is a difference so throw an exception.
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
Example 2
Source File: FloatingPointTolerantDifferenceListener.java    From xmlunit with Apache License 2.0 6 votes vote down vote up
protected int textualDifference(Difference d) {
    String control = d.getControlNodeDetail().getValue();
    String test = d.getTestNodeDetail().getValue();
    if (control != null && test != null) {
        try {
            double controlVal = Double.parseDouble(control);
            double testVal = Double.parseDouble(test);
            return Math.abs(controlVal - testVal) <= tolerance
                ? DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
                : DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
        } catch (NumberFormatException nfe) {
            // ignore, delegate to nested DifferenceListener
        }
    }
    // no numbers or null, delegate
    return super.textualDifference(d);
}
 
Example 3
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Override
public int differenceFound(Difference difference) {
  switch (difference.getId()) {
    case DifferenceConstants.NAMESPACE_URI_ID:
      return namespaceDifferenceFound(difference);
    case DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID:
    case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID:
      return attributeDifferenceFound(difference);
    default:
      return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
  }
}
 
Example 4
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Checks for logical equivalence of the qualified node names.
 */
private int namespaceDifferenceFound(Difference difference) {
  Node controlNode = difference.getControlNodeDetail().getNode();
  Node testNode = difference.getTestNodeDetail().getNode();
  String controlNs = getNamespaceURI(controlNode);
  String testNs = getNamespaceURI(testNode);
  if (Objects.equal(controlNs, testNs)) {
    if (Objects.equal(controlNode.getLocalName(), testNode.getLocalName())) {
      return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
    }
  }
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
Example 5
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Ignores differences that are only due to missing xsi:type.
 */
private int attributeDifferenceFound(Difference difference) {
  NamedNodeMap controlAttributes = difference.getControlNodeDetail().getNode().getAttributes();
  NamedNodeMap testAttributes = difference.getTestNodeDetail().getNode().getAttributes();
  Map<QName, Node> controlAttributesMap = createAttributesMapExcludingXsiType(controlAttributes);
  Map<QName, Node> testAttributesMap = createAttributesMapExcludingXsiType(testAttributes);
  if (controlAttributesMap.size() != testAttributesMap.size()) {
    return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
  }
  return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}