use of org.xmlunit.diff.DifferenceEvaluator in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method toMessage.
@Test
public void toMessage() throws Exception {
MyBean payload = new MyBean();
payload.setName("Foo");
Message<?> message = this.converter.toMessage(payload, null);
assertNotNull(message);
String actual = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat(actual, isSimilarTo("<myBean><name>Foo</name></myBean>").withDifferenceEvaluator(ev));
}
use of org.xmlunit.diff.DifferenceEvaluator in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method marshalAWrappedObjectHoldingAnXmlElementDeclElement.
@Test
public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception {
// SPR-10714
marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" });
marshaller.afterPropertiesSet();
Airplane airplane = new Airplane();
airplane.setName("test");
StringWriter writer = new StringWriter();
Result result = new StreamResult(writer);
marshaller.marshal(airplane, result);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Marshalling should use root Element", writer.toString(), isSimilarTo("<airplane><name>test</name></airplane>").withDifferenceEvaluator(ev));
}
use of org.xmlunit.diff.DifferenceEvaluator in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method writeXmlRootElement.
@Test
public void writeXmlRootElement() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(rootElement, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType());
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>").withDifferenceEvaluator(ev));
}
use of org.xmlunit.diff.DifferenceEvaluator in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method lazyInit.
@Test
public void lazyInit() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.setLazyInit(true);
marshaller.afterPropertiesSet();
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
marshaller.marshal(flights, result);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING).withDifferenceEvaluator(ev));
}
use of org.xmlunit.diff.DifferenceEvaluator in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method customizeMarshaller.
// SPR-11488
@Test
public void customizeMarshaller() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<myRootElement><element>a|||b</element></myRootElement>").withDifferenceEvaluator(ev));
}
Aggregations