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:
parent
9fb8a2eb2e
commit
3635c9dbfe
16
build.gradle
16
build.gradle
|
|
@ -87,7 +87,7 @@ configure(allprojects) { project ->
|
|||
ext.undertowVersion = "1.4.0.CR3"
|
||||
ext.websocketVersion = "1.1"
|
||||
ext.woodstoxVersion = "5.0.2"
|
||||
ext.xmlunitVersion = "1.6"
|
||||
ext.xmlunitVersion = "2.2.1"
|
||||
ext.xstreamVersion = "1.4.9"
|
||||
|
||||
ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
|
||||
|
|
@ -379,7 +379,7 @@ project("spring-core") {
|
|||
optional "io.reactivex:rxjava:${rxjavaVersion}"
|
||||
optional("io.netty:netty-buffer:${nettyVersion}")
|
||||
testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testCompile("com.fasterxml.woodstox:woodstox-core:${woodstoxVersion}") {
|
||||
exclude group: "stax", module: "stax-api"
|
||||
}
|
||||
|
|
@ -532,7 +532,7 @@ project("spring-oxm") {
|
|||
}
|
||||
optional("org.jibx:jibx-run:1.2.6")
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testCompile("xpp3:xpp3:1.1.4c")
|
||||
testCompile("org.codehaus.jettison:jettison:1.3.7") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
|
|
@ -585,7 +585,7 @@ project("spring-messaging") {
|
|||
testCompile("org.apache.tomcat.embed:tomcat-embed-websocket:${tomcatVersion}")
|
||||
testCompile("io.netty:netty-all:${nettyVersion}")
|
||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
|
||||
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
|
||||
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
|
||||
|
|
@ -740,7 +740,7 @@ project("spring-web") {
|
|||
optional("com.googlecode.protobuf-java-format:protobuf-java-format:1.4")
|
||||
optional("javax.mail:javax.mail-api:${javamailVersion}")
|
||||
testCompile(project(":spring-context-support")) // for JafMediaTypeFactory
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||
testCompile("org.apache.taglibs:taglibs-standard-jstlel:1.2.1") {
|
||||
exclude group: "org.apache.taglibs", module: "taglibs-standard-spec"
|
||||
|
|
@ -788,7 +788,7 @@ project("spring-web-reactive") {
|
|||
testCompile("com.fasterxml:aalto-xml:1.0.0")
|
||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||
testCompile("javax.validation:validation-api:${beanvalVersion}")
|
||||
testCompile("xmlunit:xmlunit:1.6")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testRuntime("javax.xml.bind:jaxb-api:${jaxbVersion}")
|
||||
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
|
||||
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
|
||||
|
|
@ -864,7 +864,7 @@ project("spring-webmvc") {
|
|||
exclude group: "org.springframework", module: "spring-web"
|
||||
}
|
||||
optional('org.webjars:webjars-locator:0.32')
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
testCompile("dom4j:dom4j:1.6.1") {
|
||||
exclude group: "xml-apis", module: "xml-apis"
|
||||
}
|
||||
|
|
@ -975,7 +975,7 @@ project("spring-test") {
|
|||
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
|
||||
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
||||
optional("org.hamcrest:hamcrest-core:${hamcrestVersion}")
|
||||
optional("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
optional("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
|
||||
optional("net.sourceforge.htmlunit:htmlunit:2.22")
|
||||
optional("org.seleniumhq.selenium:htmlunit-driver:2.21")
|
||||
optional("org.seleniumhq.selenium:selenium-java:2.53.1") {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,21 +16,24 @@
|
|||
|
||||
package org.springframework.messaging.converter;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.diff.ComparisonType.*;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xmlunit.diff.DifferenceEvaluator;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
|
|
@ -82,7 +85,8 @@ public class MarshallingMessageConverterTests {
|
|||
assertNotNull(message);
|
||||
String actual = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
|
||||
|
||||
assertXMLEqual("<myBean><name>Foo</name></myBean>", actual);
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat(actual, isSimilarTo("<myBean><name>Foo</name></myBean>").withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,14 @@
|
|||
|
||||
package org.springframework.oxm;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xmlunit.matchers.CompareMatcher;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
|
@ -28,20 +34,10 @@ import javax.xml.transform.Result;
|
|||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.stax.StAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
|
|
@ -62,7 +58,6 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
public final void setUp() throws Exception {
|
||||
marshaller = createMarshaller();
|
||||
flights = createFlights();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
protected abstract M createMarshaller() throws Exception;
|
||||
|
|
@ -89,7 +84,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
flightElement.appendChild(numberElement);
|
||||
Text text = expected.createTextNode("42");
|
||||
numberElement.appendChild(text);
|
||||
assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
|
||||
assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -113,7 +108,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
flightElement.appendChild(numberElement);
|
||||
Text text = expected.createTextNode("42");
|
||||
numberElement.appendChild(text);
|
||||
assertXMLEqual("Marshaller writes invalid DOMResult", expected, result);
|
||||
assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -121,7 +116,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -129,8 +124,8 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
StreamResult result = new StreamResult(os);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING,
|
||||
new String(os.toByteArray(), "UTF-8"));
|
||||
assertThat("Marshaller writes invalid StreamResult", new String(os.toByteArray(), "UTF-8"),
|
||||
isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -140,7 +135,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(streamWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -150,7 +145,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(eventWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -160,7 +155,7 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||
StAXResult result = new StAXResult(streamWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -170,7 +165,11 @@ public abstract class AbstractMarshallerTests<M extends Marshaller> {
|
|||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
|
||||
StAXResult result = new StAXResult(eventWriter);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
private static CompareMatcher isSimilarTo(final Object content) {
|
||||
return CompareMatcher.isSimilarTo(content)
|
||||
.ignoreWhitespace();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,35 +16,32 @@
|
|||
|
||||
package org.springframework.oxm.castor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.castor.xml.XMLProperties;
|
||||
import org.custommonkey.xmlunit.NamespaceContext;
|
||||
import org.custommonkey.xmlunit.SimpleNamespaceContext;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.custommonkey.xmlunit.XpathEngine;
|
||||
import org.exolab.castor.xml.XercesXMLSerializerFactory;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xmlunit.builder.Input;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link CastorMarshaller} class.
|
||||
*
|
||||
|
|
@ -163,14 +160,14 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
public void suppressNamespacesTrue() throws Exception {
|
||||
marshaller.setSuppressNamespaces(true);
|
||||
String result = marshalFlights();
|
||||
assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_NAMESPACE_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(SUPPRESSED_NAMESPACE_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressNamespacesFalse() throws Exception {
|
||||
marshaller.setSuppressNamespaces(false);
|
||||
String result = marshalFlights();
|
||||
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -179,7 +176,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
marshaller.setSuppressXsiType(true);
|
||||
marshaller.setRootElement("objects");
|
||||
String result = marshal(Arrays.asList(castorObject));
|
||||
assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_XSI_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(SUPPRESSED_XSI_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -188,14 +185,14 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
marshaller.setSuppressXsiType(false);
|
||||
marshaller.setRootElement("objects");
|
||||
String result = marshal(Arrays.asList(castorObject));
|
||||
assertXMLEqual("Marshaller wrote invalid result", XSI_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(XSI_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshalAsDocumentTrue() throws Exception {
|
||||
marshaller.setMarshalAsDocument(true);
|
||||
String result = marshalFlights();
|
||||
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(DOCUMENT_EXPECTED_STRING));
|
||||
assertTrue("Result doesn't contain xml declaration.",
|
||||
result.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||
}
|
||||
|
|
@ -204,7 +201,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
public void marshalAsDocumentFalse() throws Exception {
|
||||
marshaller.setMarshalAsDocument(true);
|
||||
String result = marshalFlights();
|
||||
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(EXPECTED_STRING));
|
||||
assertFalse("Result contains xml declaration.", result.matches("<\\?\\s*xml"));
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +209,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
public void rootElement() throws Exception {
|
||||
marshaller.setRootElement("canceledFlights");
|
||||
String result = marshalFlights();
|
||||
assertXMLEqual("Marshaller wrote invalid result", ROOT_ELEMENT_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(ROOT_ELEMENT_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -222,7 +219,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
String result = marshalFlights();
|
||||
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.",
|
||||
noNamespaceSchemaLocation, "/tns:flights/@xsi:noNamespaceSchemaLocation", result);
|
||||
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -232,7 +229,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
String result = marshalFlights();
|
||||
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.",
|
||||
schemaLocation, "/tns:flights/@xsi:schemaLocation", result);
|
||||
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -242,7 +239,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
marshaller.setUseXSITypeAtRoot(true);
|
||||
marshaller.setRootElement("objects");
|
||||
String result = marshal(Arrays.asList(castorObject));
|
||||
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITH_XSI_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(ROOT_WITH_XSI_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -252,7 +249,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
marshaller.setUseXSITypeAtRoot(false);
|
||||
marshaller.setRootElement("objects");
|
||||
String result = marshal(Arrays.asList(castorObject));
|
||||
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result);
|
||||
assertThat("Marshaller wrote invalid result", result, isSimilarTo(ROOT_WITHOUT_XSI_EXPECTED_STRING));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -282,13 +279,12 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
|
|||
namespaces.put("tns", "http://samples.springframework.org/flight");
|
||||
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
||||
|
||||
NamespaceContext ctx = new SimpleNamespaceContext(namespaces);
|
||||
XpathEngine engine = XMLUnit.newXpathEngine();
|
||||
engine.setNamespaceContext(ctx);
|
||||
JAXPXPathEngine engine = new JAXPXPathEngine();
|
||||
engine.setNamespaceContext(namespaces);
|
||||
|
||||
Document doc = XMLUnit.buildControlDocument(xmlDoc);
|
||||
NodeList node = engine.getMatchingNodes(xpath, doc);
|
||||
assertEquals(msg, expected, node.item(0).getNodeValue());
|
||||
Source source = Input.fromString(xmlDoc).build();
|
||||
Iterable<Node> nodeList = engine.selectNodes(xpath, source);
|
||||
assertEquals(msg, expected, nodeList.iterator().next().getNodeValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,34 +16,9 @@
|
|||
|
||||
package org.springframework.oxm.jaxb;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
|
|
@ -55,13 +30,53 @@ import org.springframework.oxm.jaxb.test.ObjectFactory;
|
|||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.Locator;
|
||||
import org.xmlunit.diff.Comparison;
|
||||
import org.xmlunit.diff.ComparisonResult;
|
||||
import org.xmlunit.diff.ComparisonType;
|
||||
import org.xmlunit.diff.DifferenceEvaluator;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.BDDMockito.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.inOrder;
|
||||
import static org.mockito.BDDMockito.isA;
|
||||
import static org.mockito.BDDMockito.mock;
|
||||
import static org.mockito.BDDMockito.reset;
|
||||
import static org.mockito.BDDMockito.times;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.xmlunit.diff.ComparisonType.XML_STANDALONE;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.Default;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.chain;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.downgradeDifferencesToEqual;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -122,7 +137,9 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
|||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
marshaller.marshal(flights, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(),
|
||||
isSimilarTo(EXPECTED_STRING).withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -305,8 +322,10 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
|||
StringWriter writer = new StringWriter();
|
||||
Result result = new StreamResult(writer);
|
||||
marshaller.marshal(airplane, result);
|
||||
assertXMLEqual("Marshalling should use root Element",
|
||||
writer.toString(), "<airplane><name>test</name></airplane>");
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat("Marshalling should use root Element",
|
||||
writer.toString(),
|
||||
isSimilarTo("<airplane><name>test</name></airplane>").withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
// SPR-10806
|
||||
|
|
@ -407,5 +426,4 @@ public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshalle
|
|||
private JAXBElement<DummyType> createDummyType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,21 +16,19 @@
|
|||
|
||||
package org.springframework.oxm.jibx;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* NOTE: These tests fail under Eclipse/IDEA because JiBX binding does not occur by
|
||||
|
|
@ -74,11 +72,10 @@ public class JibxMarshallerTests extends AbstractMarshallerTests<JibxMarshaller>
|
|||
marshaller.setIndent(4);
|
||||
StringWriter writer = new StringWriter();
|
||||
marshaller.marshal(flights, new StreamResult(writer));
|
||||
XMLUnit.setIgnoreWhitespace(false);
|
||||
String expected =
|
||||
"<?xml version=\"1.0\"?>\n" + "<flights xmlns=\"http://samples.springframework.org/flight\">\n" +
|
||||
" <flight>\n" + " <number>42</number>\n" + " </flight>\n" + "</flights>";
|
||||
assertXMLEqual(expected, writer.toString());
|
||||
assertThat(writer.toString(), isSimilarTo(expected).ignoreWhitespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,26 +16,6 @@
|
|||
|
||||
package org.springframework.oxm.xstream;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
|
@ -46,19 +26,46 @@ import org.junit.Before;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Text;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xmlunit.builder.Input;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.BDDMockito.eq;
|
||||
import static org.mockito.BDDMockito.inOrder;
|
||||
import static org.mockito.BDDMockito.isA;
|
||||
import static org.mockito.BDDMockito.mock;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -95,7 +102,7 @@ public class XStreamMarshallerTests {
|
|||
flightElement.appendChild(numberElement);
|
||||
Text text = expected.createTextNode("42");
|
||||
numberElement.appendChild(text);
|
||||
assertXMLEqual("Marshaller writes invalid DOMResult", expected, document);
|
||||
assertThat("Marshaller writes invalid DOMResult", document, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
// see SWS-392
|
||||
|
|
@ -124,7 +131,7 @@ public class XStreamMarshallerTests {
|
|||
eFlightElement.appendChild(eNumberElement);
|
||||
Text text = expected.createTextNode("42");
|
||||
eNumberElement.appendChild(text);
|
||||
assertXMLEqual("Marshaller writes invalid DOMResult", expected, existent);
|
||||
assertThat("Marshaller writes invalid DOMResult", existent, isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -132,7 +139,7 @@ public class XStreamMarshallerTests {
|
|||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
marshaller.marshal(flight, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -141,7 +148,7 @@ public class XStreamMarshallerTests {
|
|||
StreamResult result = new StreamResult(os);
|
||||
marshaller.marshal(flight, result);
|
||||
String s = new String(os.toByteArray(), "UTF-8");
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, s);
|
||||
assertThat("Marshaller writes invalid StreamResult", s, isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -166,7 +173,7 @@ public class XStreamMarshallerTests {
|
|||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(streamWriter);
|
||||
marshaller.marshal(flight, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -176,7 +183,7 @@ public class XStreamMarshallerTests {
|
|||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
|
||||
Result result = StaxUtils.createStaxResult(eventWriter);
|
||||
marshaller.marshal(flight, result);
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -185,7 +192,7 @@ public class XStreamMarshallerTests {
|
|||
byte[] buf = new byte[]{0x1, 0x2};
|
||||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(buf, new StreamResult(writer));
|
||||
assertXMLEqual("<byte-array>AQI=</byte-array>", writer.toString());
|
||||
assertThat(writer.toString(), isSimilarTo("<byte-array>AQI=</byte-array>"));
|
||||
Reader reader = new StringReader(writer.toString());
|
||||
byte[] bufResult = (byte[]) marshaller.unmarshal(new StreamSource(reader));
|
||||
assertTrue("Invalid result", Arrays.equals(buf, bufResult));
|
||||
|
|
@ -197,7 +204,7 @@ public class XStreamMarshallerTests {
|
|||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
String expected = "<flight flightNumber=\"42\" />";
|
||||
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -206,7 +213,7 @@ public class XStreamMarshallerTests {
|
|||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
String expected = "<flight flightNumber=\"42\" />";
|
||||
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -215,7 +222,7 @@ public class XStreamMarshallerTests {
|
|||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
String expected = "<flight flightNumber=\"42\" />";
|
||||
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -225,7 +232,7 @@ public class XStreamMarshallerTests {
|
|||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
String expected = "<flight flightNumber=\"42\" />";
|
||||
assertXMLEqual("Marshaller does not use attributes", expected, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -239,7 +246,7 @@ public class XStreamMarshallerTests {
|
|||
|
||||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -253,7 +260,7 @@ public class XStreamMarshallerTests {
|
|||
|
||||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
assertXMLEqual("Marshaller does not use attributes", EXPECTED_STRING, writer.toString());
|
||||
assertThat("Marshaller does not use attributes", writer.toString(), isSimilarTo(EXPECTED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -262,7 +269,7 @@ public class XStreamMarshallerTests {
|
|||
Writer writer = new StringWriter();
|
||||
marshaller.marshal(flight, new StreamResult(writer));
|
||||
String expected = "<flight><flightNo>42</flightNo></flight>";
|
||||
assertXMLEqual("Marshaller does not use aliases", expected, writer.toString());
|
||||
assertThat("Marshaller does not use aliases", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -337,8 +344,31 @@ public class XStreamMarshallerTests {
|
|||
flight.setFlightNumber(42);
|
||||
marshaller.marshal(flight, result);
|
||||
String expected = "<flight><number>42</number></flight>";
|
||||
assertXMLEqual("Marshaller writes invalid StreamResult", expected, writer.toString());
|
||||
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
private static void assertXpathExists(String xPathExpression, String inXMLString){
|
||||
Source source = Input.fromString(inXMLString).build();
|
||||
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);
|
||||
assertNotNull(nodes);
|
||||
int count = 0;
|
||||
|
||||
for (Node node : nodes){
|
||||
count++;
|
||||
}
|
||||
assertTrue("Expecting to find matches for Xpath " + xPathExpression, count > 0);
|
||||
}
|
||||
|
||||
|
||||
private static void assertXpathNotExists(String xPathExpression, String inXMLString){
|
||||
Source source = Input.fromString(inXMLString).build();
|
||||
Iterable<Node> nodes = new JAXPXPathEngine().selectNodes(xPathExpression, source);
|
||||
assertNotNull(nodes);
|
||||
int count = 0;
|
||||
|
||||
for (Node node : nodes){
|
||||
count++;
|
||||
}
|
||||
assertEquals("Should be zero matches for Xpath " + xPathExpression, 0, count);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
package org.springframework.http.codec.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.TestSubscriber;
|
||||
|
||||
|
|
@ -33,10 +31,10 @@ import org.springframework.core.io.buffer.support.DataBufferUtils;
|
|||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.Pojo;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
|
|
@ -80,10 +78,8 @@ public class Jaxb2EncoderTests extends AbstractDataBufferAllocatingTestCase {
|
|||
try {
|
||||
String s = DataBufferTestUtils
|
||||
.dumpString(dataBuffer, StandardCharsets.UTF_8);
|
||||
assertXMLEqual("<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>", s);
|
||||
}
|
||||
catch (SAXException | IOException e) {
|
||||
fail(e.getMessage());
|
||||
assertThat(s, isSimilarTo("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||
"<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>"));
|
||||
}
|
||||
finally {
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.springframework.http.converter.feed;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
|
@ -25,19 +28,17 @@ import java.util.List;
|
|||
|
||||
import com.rometools.rome.feed.atom.Entry;
|
||||
import com.rometools.rome.feed.atom.Feed;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xmlunit.diff.DefaultNodeMatcher;
|
||||
import org.xmlunit.diff.ElementSelectors;
|
||||
import org.xmlunit.diff.NodeMatcher;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MockHttpInputMessage;
|
||||
import org.springframework.http.MockHttpOutputMessage;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
|
|
@ -49,7 +50,6 @@ public class AtomFeedHttpMessageConverterTests {
|
|||
@Before
|
||||
public void setUp() {
|
||||
converter = new AtomFeedHttpMessageConverter();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -111,7 +111,9 @@ public class AtomFeedHttpMessageConverterTests {
|
|||
String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
|
||||
"<entry><id>id1</id><title>title1</title></entry>" +
|
||||
"<entry><id>id2</id><title>title2</title></entry></feed>";
|
||||
assertXMLEqual(expected, outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
|
||||
assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.http.converter.feed;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
|
@ -25,19 +27,15 @@ import java.util.List;
|
|||
|
||||
import com.rometools.rome.feed.rss.Channel;
|
||||
import com.rometools.rome.feed.rss.Item;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xmlunit.matchers.CompareMatcher;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MockHttpInputMessage;
|
||||
import org.springframework.http.MockHttpOutputMessage;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
|
|
@ -49,7 +47,6 @@ public class RssChannelHttpMessageConverterTests {
|
|||
@Before
|
||||
public void setUp() {
|
||||
converter = new RssChannelHttpMessageConverter();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -113,7 +110,7 @@ public class RssChannelHttpMessageConverterTests {
|
|||
"<item><title>title1</title></item>" +
|
||||
"<item><title>title2</title></item>" +
|
||||
"</channel></rss>";
|
||||
assertXMLEqual(expected, outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -136,4 +133,8 @@ public class RssChannelHttpMessageConverterTests {
|
|||
outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
private static CompareMatcher isSimilarTo(final String content) {
|
||||
return CompareMatcher.isSimilarTo(content)
|
||||
.ignoreWhitespace();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@
|
|||
|
||||
package org.springframework.http.converter.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.xmlunit.diff.ComparisonType.*;
|
||||
import static org.xmlunit.diff.DifferenceEvaluators.*;
|
||||
import static org.xmlunit.matchers.CompareMatcher.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
|
@ -30,6 +36,7 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.xmlunit.diff.DifferenceEvaluator;
|
||||
|
||||
import org.springframework.aop.framework.AdvisedSupport;
|
||||
import org.springframework.aop.framework.AopProxy;
|
||||
|
|
@ -41,11 +48,6 @@ import org.springframework.http.MockHttpInputMessage;
|
|||
import org.springframework.http.MockHttpOutputMessage;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests for {@link Jaxb2RootElementHttpMessageConverter}.
|
||||
*
|
||||
|
|
@ -175,8 +177,9 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
|||
converter.write(rootElement, null, outputMessage);
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
assertXMLEqual("Invalid result", "<rootElement><type s=\"Hello World\"/></rootElement>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>").withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -185,8 +188,9 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
|||
converter.write(rootElementCglib, null, outputMessage);
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
assertXMLEqual("Invalid result", "<rootElement><type s=\"Hello World\"/></rootElement>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>").withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
// SPR-11488
|
||||
|
|
@ -196,8 +200,9 @@ public class Jaxb2RootElementHttpMessageConverterTests {
|
|||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
|
||||
myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage);
|
||||
assertXMLEqual("Invalid result", "<myRootElement><element>a|||b</element></myRootElement>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<myRootElement><element>a|||b</element></myRootElement>").withDifferenceEvaluator(ev));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -49,10 +49,11 @@ import org.springframework.http.MockHttpOutputMessage;
|
|||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
// Do NOT statically import org.junit.Assert.*, since XMLAssert extends junit.framework.Assert
|
||||
|
||||
|
|
@ -150,7 +151,7 @@ public class SourceHttpMessageConverterTests {
|
|||
SAXSource result = (SAXSource) converter.read(SAXSource.class, inputMessage);
|
||||
InputSource inputSource = result.getInputSource();
|
||||
String s = FileCopyUtils.copyToString(new InputStreamReader(inputSource.getByteStream()));
|
||||
assertXMLEqual("Invalid result", BODY, s);
|
||||
assertThat("Invalid result", s, isSimilarTo(BODY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -278,7 +279,7 @@ public class SourceHttpMessageConverterTests {
|
|||
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
||||
StreamSource result = (StreamSource) converter.read(StreamSource.class, inputMessage);
|
||||
String s = FileCopyUtils.copyToString(new InputStreamReader(result.getInputStream()));
|
||||
assertXMLEqual("Invalid result", BODY, s);
|
||||
assertThat("Invalid result", s, isSimilarTo(BODY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -300,8 +301,8 @@ public class SourceHttpMessageConverterTests {
|
|||
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
converter.write(domSource, null, outputMessage);
|
||||
assertXMLEqual("Invalid result", "<root>Hello World</root>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<root>Hello World</root>"));
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
assertEquals("Invalid content-length", outputMessage.getBodyAsBytes().length,
|
||||
|
|
@ -315,8 +316,8 @@ public class SourceHttpMessageConverterTests {
|
|||
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
converter.write(saxSource, null, outputMessage);
|
||||
assertXMLEqual("Invalid result", "<root>Hello World</root>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<root>Hello World</root>"));
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
|
@ -328,8 +329,8 @@ public class SourceHttpMessageConverterTests {
|
|||
|
||||
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
|
||||
converter.write(streamSource, null, outputMessage);
|
||||
assertXMLEqual("Invalid result", "<root>Hello World</root>",
|
||||
outputMessage.getBodyAsString(StandardCharsets.UTF_8));
|
||||
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
|
||||
isSimilarTo("<root>Hello World</root>"));
|
||||
assertEquals("Invalid content-type", new MediaType("application", "xml"),
|
||||
outputMessage.getHeaders().getContentType());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,26 +16,25 @@
|
|||
|
||||
package org.springframework.web.servlet.view.feed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.rometools.rome.feed.atom.Content;
|
||||
import com.rometools.rome.feed.atom.Entry;
|
||||
import com.rometools.rome.feed.atom.Feed;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.xmlunit.matchers.CompareMatcher;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.custommonkey.xmlunit.XMLUnit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -47,7 +46,6 @@ public class AtomFeedViewTests {
|
|||
@Before
|
||||
public void createView() throws Exception {
|
||||
view = new MyAtomFeedView();
|
||||
setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -64,9 +62,13 @@ public class AtomFeedViewTests {
|
|||
String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>Test Feed</title>" +
|
||||
"<entry><title>2</title><summary>This is entry 2</summary></entry>" +
|
||||
"<entry><title>1</title><summary>This is entry 1</summary></entry>" + "</feed>";
|
||||
assertXMLEqual(expected, response.getContentAsString());
|
||||
assertThat(response.getContentAsString(), isSimilarTo(expected));
|
||||
}
|
||||
|
||||
private static CompareMatcher isSimilarTo(final String content) {
|
||||
return CompareMatcher.isSimilarTo(content)
|
||||
.ignoreWhitespace();
|
||||
}
|
||||
|
||||
private static class MyAtomFeedView extends AbstractAtomFeedView {
|
||||
|
||||
|
|
|
|||
|
|
@ -16,25 +16,25 @@
|
|||
|
||||
package org.springframework.web.servlet.view.feed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.rometools.rome.feed.rss.Channel;
|
||||
import com.rometools.rome.feed.rss.Description;
|
||||
import com.rometools.rome.feed.rss.Item;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.xmlunit.matchers.CompareMatcher;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static org.custommonkey.xmlunit.XMLUnit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -46,7 +46,6 @@ public class RssFeedViewTests {
|
|||
@Before
|
||||
public void createView() throws Exception {
|
||||
view = new MyRssFeedView();
|
||||
setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -64,7 +63,7 @@ public class RssFeedViewTests {
|
|||
"<channel><title>Test Feed</title><link>http://example.com</link><description>Test feed description</description>" +
|
||||
"<item><title>2</title><description>This is entry 2</description></item>" +
|
||||
"<item><title>1</title><description>This is entry 1</description></item>" + "</channel></rss>";
|
||||
assertXMLEqual(expected, response.getContentAsString());
|
||||
assertThat(response.getContentAsString(), isSimilarTo(expected).ignoreWhitespace());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue