Update xmlunit library to version 2.1.0

xmlunit 2.1.0 is the latest release for xmlunit.
Most of the xmlunit functionality used within spring-framework
was done through the xmlunit 1.x helper class
`org.custommonkey.xmlunit.XMLAssert`.

As of xmlunit 2.0.0 most of the XML comparison methods are done
through hamcrest matchers exposed by the xmlunit-matchers
library. In some cases during the migration, the matchers
had to be customized with custom `NodeMatcher` or
`DifferenceEvaluator` instances in order to keep the assertions
correct (they were performed with xmlunit 1.x previously).

Issue: SPR-14043
This commit is contained in:
Marius Grama
2016-03-13 15:33:15 +01:00
committed by Brian Clozel
parent 9fb8a2eb2e
commit 3635c9dbfe
22 changed files with 345 additions and 284 deletions

View File

@@ -23,12 +23,12 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.hamcrest.Matcher;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;
import static org.hamcrest.MatcherAssert.*;
@@ -77,15 +77,12 @@ public class XmlExpectationsHelper {
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
*/
public void assertXmlEqual(String expected, String actual) throws Exception {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
Document control = XMLUnit.buildControlDocument(expected);
Document test = XMLUnit.buildTestDocument(actual);
Diff diff = new Diff(control, test);
if (!diff.similar()) {
AssertionErrors.fail("Body content " + diff.toString());
Diff diffSimilar = DiffBuilder.compare(expected).withTest(actual)
.ignoreWhitespace().ignoreComments()
.checkForSimilar()
.build();
if (diffSimilar.hasDifferences()) {
AssertionErrors.fail("Body content " + diffSimilar.toString());
}
}