public class IgnoreNamedElementsDifferenceListener implements DifferenceListener { private Set<String> blackList = new HashSet<String>(); public IgnoreNamedElementsDifferenceListener(String ... elementNames) { for (String name : elementNames) { blackList.add(name); } } public int differenceFound(Difference difference) { if (difference.getId() == DifferenceConstants.TEXT_VALUE_ID) { if (blackList.contains(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) { return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } } return DifferenceListener.RETURN_ACCEPT_DIFFERENCE; } public void skippedComparison(Node node, Node node1) { } }
public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if( sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID ) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } logger.info( "! {}", diff.getTestNodeDetail().getNode().getNodeName()); return RETURN_ACCEPT_DIFFERENCE; }
private boolean isIgnoredDifference(Difference difference) { int differenceId = difference.getId(); for (int i=0; i < IGNORE_VALUES.length; ++i) { if (differenceId == IGNORE_VALUES[i]) { return true; } } return false; }
public class DifferenceListenerImpl implements DifferenceListener { @Override public int differenceFound(Difference d) { if (d.getId() == DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID) { return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR; } // handle other difference types here } @Override public void skippedComparison(Node control, Node test) { // not needed } }
private boolean isIgnoredDifference(Difference difference) { int differenceId = difference.getId(); for (int i=0; i < IGNORE_VALUES.length; ++i) { if (differenceId == IGNORE_VALUES[i]) { return true; } } return false; }
public int differenceFound(Difference difference) { return difference.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL : RETURN_ACCEPT_DIFFERENCE; }
detDiff.overrideDifferenceListener(new DifferenceListener() { @Override public int differenceFound(Difference difference) { return difference.getId() == DifferenceConstants.CHILD_NODELIST_LENGTH_ID ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL : RETURN_ACCEPT_DIFFERENCE; } @Override public void skippedComparison(Node control, Node test) { } });
/** * Now that Differences can be constructed from prototypes * we need to be able to compare them to those in DifferenceConstants */ public boolean equals(Object other) { if (other == null) { return false; } else if (other instanceof Difference) { Difference otherDifference = (Difference) other; return id == otherDifference.getId(); } else { return false; } }
/** * Now that Differences can be constructed from prototypes * we need to be able to compare them to those in DifferenceConstants */ public boolean equals(Object other) { if (other == null) { return false; } else if (other instanceof Difference) { Difference otherDifference = (Difference) other; return id == otherDifference.getId(); } else { return false; } }
@Override public int differenceFound(Difference difference) { if (difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } else { return super.differenceFound(difference); } } };
Diff xmlDiff = new Diff(s1, s2); xmlDiff.overrideElementQualifier(new ElementNameQualifier() { @Override protected boolean equalsNamespace(Node control, Node test) { return true; } }); xmlDiff.overrideDifferenceListener(new DifferenceListener() { @Override public int differenceFound(Difference diff) { if (diff.getId() == DifferenceConstants.NAMESPACE_URI_ID) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } return RETURN_ACCEPT_DIFFERENCE; } @Override public void skippedComparison(Node arg0, Node arg1) { } });
public int differenceFound(Difference difference) { if (DifferenceConstants.TEXT_VALUE_ID == difference.getId() && !"script".equalsIgnoreCase(difference.getTestNodeDetail().getNode().getLocalName())) { return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR; } return RETURN_ACCEPT_DIFFERENCE; }
/** * Copy constructor using prototype Difference and * encountered NodeDetails */ protected Difference(Difference prototype, NodeDetail controlNodeDetail, NodeDetail testNodeDetail) { this(prototype.getId(), prototype.getDescription(), prototype.isRecoverable()); this.controlNodeDetail = controlNodeDetail; this.testNodeDetail = testNodeDetail; }
/** * Copy constructor using prototype Difference and * encountered NodeDetails */ protected Difference(Difference prototype, NodeDetail controlNodeDetail, NodeDetail testNodeDetail) { this(prototype.getId(), prototype.getDescription(), prototype.isRecoverable()); this.controlNodeDetail = controlNodeDetail; this.testNodeDetail = testNodeDetail; }
@Override public int differenceFound(Difference diff) { if (diff.getId() == DifferenceConstants.SCHEMA_LOCATION_ID || diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } if (diff.getId() == DifferenceConstants.TEXT_VALUE_ID) { for (NodeDetail detail : ImmutableSet.of(diff.getControlNodeDetail(), diff.getTestNodeDetail())) { if (detail.getNode().getParentNode().getChildNodes().getLength() < 2 || !detail.getValue().trim().isEmpty()) { return RETURN_ACCEPT_DIFFERENCE; } } return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } return RETURN_ACCEPT_DIFFERENCE; }
@Override public int differenceFound(Difference diff) { if (diff.getId() == DifferenceConstants.SCHEMA_LOCATION_ID || diff.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } if (diff.getId() == DifferenceConstants.TEXT_VALUE_ID) { for (NodeDetail detail : ImmutableSet.of(diff.getControlNodeDetail(), diff.getTestNodeDetail())) { if (detail.getNode().getParentNode().getChildNodes().getLength() < 2 || !detail.getValue().trim().isEmpty()) { return RETURN_ACCEPT_DIFFERENCE; } } return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } return RETURN_ACCEPT_DIFFERENCE; }
public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if( sequenceDoesNotMatter.contains(nodeName) && diff.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID ) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } logger.info( "! {}", diff.getTestNodeDetail().getNode().getNodeName()); return RETURN_ACCEPT_DIFFERENCE; }
@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; } }
/** * Delegates to the nested DifferenceListener unless the * Difference is of type {@link DifferenceConstants#ATTR_VALUE_ID * ATTR_VALUE_ID}, {@link DifferenceConstants#CDATA_VALUE_ID * CDATA_VALUE_ID}, {@link DifferenceConstants#COMMENT_VALUE_ID * COMMENT_VALUE_ID} or {@link DifferenceConstants#TEXT_VALUE_ID * TEXT_VALUE_ID} - for those special differences {@link * #attributeDifference attributeDifference}, {@link * #cdataDifference cdataDifference}, {@link #commentDifference * commentDifference} or {@link #textDifference textDifference} * are invoked respectively. */ public int differenceFound(Difference difference) { switch (difference.getId()) { case DifferenceConstants.ATTR_VALUE_ID: return attributeDifference(difference); case DifferenceConstants.CDATA_VALUE_ID: return cdataDifference(difference); case DifferenceConstants.COMMENT_VALUE_ID: return commentDifference(difference); case DifferenceConstants.TEXT_VALUE_ID: return textDifference(difference); } return delegateTo.differenceFound(difference); }
/** * Delegates to the nested DifferenceListener unless the * Difference is of type {@link DifferenceConstants#ATTR_VALUE_ID * ATTR_VALUE_ID}, {@link DifferenceConstants#CDATA_VALUE_ID * CDATA_VALUE_ID}, {@link DifferenceConstants#COMMENT_VALUE_ID * COMMENT_VALUE_ID} or {@link DifferenceConstants#TEXT_VALUE_ID * TEXT_VALUE_ID} - for those special differences {@link * #attributeDifference attributeDifference}, {@link * #cdataDifference cdataDifference}, {@link #commentDifference * commentDifference} or {@link #textDifference textDifference} * are invoked respectively. */ public int differenceFound(Difference difference) { switch (difference.getId()) { case DifferenceConstants.ATTR_VALUE_ID: return attributeDifference(difference); case DifferenceConstants.CDATA_VALUE_ID: return cdataDifference(difference); case DifferenceConstants.COMMENT_VALUE_ID: return commentDifference(difference); case DifferenceConstants.TEXT_VALUE_ID: return textDifference(difference); } return delegateTo.differenceFound(difference); }