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...)
|
||||
*/
|
||||
public void assertXmlEqual(String expected, String actual) throws Exception {
|
||||
Diff diffSimilar = DiffBuilder.compare(expected).withTest(actual)
|
||||
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
|
||||
.ignoreWhitespace().ignoreComments()
|
||||
.checkForSimilar()
|
||||
.build();
|
||||
if (diffSimilar.hasDifferences()) {
|
||||
AssertionErrors.fail("Body content " + diffSimilar.toString());
|
||||
XmlUnitDiff diff = new XmlUnitDiff(expected, actual);
|
||||
if (diff.hasDifferences()) {
|
||||
AssertionErrors.fail("Body content " + diff.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