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:
committed by
Brian Clozel
parent
9fb8a2eb2e
commit
3635c9dbfe
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.Socket;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -26,17 +30,13 @@ import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -77,7 +77,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
||||
|
||||
xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
|
||||
|
||||
assertXMLEqual(COMPLEX_XML, stringWriter.toString());
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML));
|
||||
}
|
||||
|
||||
private static boolean wwwSpringframeworkOrgIsAccessible() {
|
||||
@@ -104,7 +104,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
||||
|
||||
xmlReader.parse(new InputSource(new StringReader(COMPLEX_XML)));
|
||||
|
||||
assertXMLEqual(COMPLEX_XML, stringWriter.toString());
|
||||
assertThat(stringWriter.toString(), isSimilarTo(COMPLEX_XML));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +126,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
||||
|
||||
xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML)));
|
||||
|
||||
assertXMLEqual(expected, result);
|
||||
assertThat(result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,7 +148,7 @@ public abstract class AbstractStaxHandlerTestCase {
|
||||
|
||||
xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML)));
|
||||
|
||||
assertXMLEqual(expected, result);
|
||||
assertThat(expected, isSimilarTo(result));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.StringReader;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -28,7 +24,13 @@ import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.StringReader;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DomContentHandler}.
|
||||
@@ -73,7 +75,7 @@ public class DomContentHandlerTests {
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
assertThat("Invalid result", result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +84,7 @@ public class DomContentHandlerTests {
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
assertThat("Invalid result", result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +95,7 @@ public class DomContentHandlerTests {
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_2_EXPECTED)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
assertThat("Invalid result", result, isSimilarTo(expected));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
@@ -29,8 +32,6 @@ import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@@ -51,7 +52,7 @@ public class ListBasedXMLEventReaderTests {
|
||||
XMLEventWriter writer = this.outputFactory.createXMLEventWriter(resultWriter);
|
||||
writer.add(reader);
|
||||
|
||||
assertXMLEqual(xml, resultWriter.toString());
|
||||
assertThat(resultWriter.toString(), isSimilarTo(xml));
|
||||
}
|
||||
|
||||
private List<XMLEvent> readEvents(String xml) throws XMLStreamException {
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
@@ -26,13 +26,14 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -62,7 +63,7 @@ public class StaxResultTests {
|
||||
assertEquals("Invalid streamWriter returned", streamWriter, result.getXMLStreamWriter());
|
||||
assertNull("EventWriter returned", result.getXMLEventWriter());
|
||||
transformer.transform(source, result);
|
||||
assertXMLEqual("Invalid result", XML, stringWriter.toString());
|
||||
assertThat("Invalid result", stringWriter.toString(), isSimilarTo(XML));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +76,7 @@ public class StaxResultTests {
|
||||
assertEquals("Invalid eventWriter returned", eventWriter, result.getXMLEventWriter());
|
||||
assertNull("StreamWriter returned", result.getXMLStreamWriter());
|
||||
transformer.transform(source, result);
|
||||
assertXMLEqual("Invalid result", XML, stringWriter.toString());
|
||||
assertThat("Invalid result", stringWriter.toString(), isSimilarTo(XML));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
@@ -27,15 +30,13 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
@@ -68,7 +69,7 @@ public class StaxSourceTests {
|
||||
assertNull("EventReader returned", source.getXMLEventReader());
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(source, new StreamResult(writer));
|
||||
assertXMLEqual("Invalid result", XML, writer.toString());
|
||||
assertThat("Invalid result", writer.toString(), isSimilarTo(XML));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +82,7 @@ public class StaxSourceTests {
|
||||
Document expected = documentBuilder.parse(new InputSource(new StringReader(XML)));
|
||||
Document result = documentBuilder.newDocument();
|
||||
transformer.transform(source, new DOMResult(result));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
assertThat("Invalid result", result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +93,7 @@ public class StaxSourceTests {
|
||||
assertNull("StreamReader returned", source.getXMLStreamReader());
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(source, new StreamResult(writer));
|
||||
assertXMLEqual("Invalid result", XML, writer.toString());
|
||||
assertThat("Invalid result", writer.toString(), isSimilarTo(XML));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,6 +106,6 @@ public class StaxSourceTests {
|
||||
Document expected = documentBuilder.parse(new InputSource(new StringReader(XML)));
|
||||
Document result = documentBuilder.newDocument();
|
||||
transformer.transform(source, new DOMResult(result));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
assertThat("Invalid result", result, isSimilarTo(expected));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,22 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stax.StAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
public class XMLEventStreamReaderTests {
|
||||
|
||||
@@ -58,7 +61,9 @@ public class XMLEventStreamReaderTests {
|
||||
StAXSource source = new StAXSource(streamReader);
|
||||
StringWriter writer = new StringWriter();
|
||||
transformer.transform(source, new StreamResult(writer));
|
||||
assertXMLEqual(XML, writer.toString());
|
||||
Predicate<Node> nodeFilter = n ->
|
||||
n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
|
||||
assertThat(writer.toString(), isSimilarTo(XML).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,15 +16,18 @@
|
||||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import javax.xml.stream.XMLEventFactory;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
public class XMLEventStreamWriterTests {
|
||||
|
||||
@@ -57,7 +60,8 @@ public class XMLEventStreamWriterTests {
|
||||
streamWriter.writeEndElement();
|
||||
streamWriter.writeEndDocument();
|
||||
|
||||
assertXMLEqual(XML, stringWriter.toString());
|
||||
Predicate<Node> nodeFilter = n -> n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
|
||||
assertThat(stringWriter.toString(), isSimilarTo(XML).withNodeFilter(nodeFilter));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user