From dff3b6af37023b54e6f5f5b6e0c52f53064713c4 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 6 Mar 2012 11:53:11 +0000 Subject: [PATCH] Adjusting XMLUnit code to ignore whitespace between elements, making sure it still verifies that the amount of space in a leaf ( ) is still checked correctly --- .../jclouds/rest/BaseRestClientExpectTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java index 2a06138f36..803bdab2aa 100644 --- a/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java +++ b/core/src/test/java/org/jclouds/rest/BaseRestClientExpectTest.java @@ -378,12 +378,21 @@ public abstract class BaseRestClientExpectTest { Diff diff = XMLUnit.compareXML(Strings2.toStringAndClose(a.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() { @Override - public int differenceFound(Difference difference) { - if (difference.getId() == DifferenceConstants.SCHEMA_LOCATION_ID || - difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { + 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;