Adjusting XMLUnit code to ignore whitespace between elements, making sure it still verifies that the amount of space in a leaf (<a> </a>) is still checked correctly

This commit is contained in:
Adam Lowe 2012-03-06 11:53:11 +00:00
parent 14ce89aab2
commit dff3b6af37
1 changed files with 13 additions and 4 deletions

View File

@ -378,12 +378,21 @@ public abstract class BaseRestClientExpectTest<S> {
Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.getPayload().getInput()), Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.getPayload().getInput()),
Strings2.toStringAndClose(b.getPayload().getInput())); Strings2.toStringAndClose(b.getPayload().getInput()));
// Ignoring xsi:schemaLocation and differences in namespace prefixes // Ignoring whitespace in elements that have other children, xsi:schemaLocation and differences in namespace prefixes
diff.overrideDifferenceListener(new DifferenceListener() { diff.overrideDifferenceListener(new DifferenceListener() {
@Override @Override
public int differenceFound(Difference difference) { public int differenceFound(Difference diff) {
if (difference.getId() == DifferenceConstants.SCHEMA_LOCATION_ID || if (diff.getId() == DifferenceConstants.SCHEMA_LOCATION_ID ||
difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_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_IGNORE_DIFFERENCE_NODES_IDENTICAL;
} }
return RETURN_ACCEPT_DIFFERENCE; return RETURN_ACCEPT_DIFFERENCE;