Remove XmlExpectationsHelper hard XML Unit requirement
Update XmlExpectationsHelper to use an inner class for XML Unit calls so that the XML Unit dependency remains optional. Issue: SPR-15156
This commit is contained in:
parent
f380ab9d90
commit
656e7f801e
|
@ -79,14 +79,39 @@ public class XmlExpectationsHelper {
|
||||||
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
|
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
|
||||||
*/
|
*/
|
||||||
public void assertXmlEqual(String expected, String actual) throws Exception {
|
public void assertXmlEqual(String expected, String actual) throws Exception {
|
||||||
Diff diffSimilar = DiffBuilder.compare(expected).withTest(actual)
|
XmlUnitDiff diff = new XmlUnitDiff(expected, actual);
|
||||||
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
|
if (diff.hasDifferences()) {
|
||||||
.ignoreWhitespace().ignoreComments()
|
AssertionErrors.fail("Body content " + diff.toString());
|
||||||
.checkForSimilar()
|
|
||||||
.build();
|
|
||||||
if (diffSimilar.hasDifferences()) {
|
|
||||||
AssertionErrors.fail("Body content " + diffSimilar.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inner class to prevent hard dependency on XML Unit.
|
||||||
|
*/
|
||||||
|
private static class XmlUnitDiff {
|
||||||
|
|
||||||
|
private final Diff diff;
|
||||||
|
|
||||||
|
|
||||||
|
XmlUnitDiff(String expected, String actual) {
|
||||||
|
this.diff = DiffBuilder.compare(expected).withTest(actual)
|
||||||
|
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
|
||||||
|
.ignoreWhitespace().ignoreComments()
|
||||||
|
.checkForSimilar()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean hasDifferences() {
|
||||||
|
return diff.hasDifferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return diff.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue