Search in sources :

Example 1 with DifferenceEvaluator

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));
}
Also used : DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Example 2 with DifferenceEvaluator

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));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult) DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Example 3 with DifferenceEvaluator

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));
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MediaType(org.springframework.http.MediaType) DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Example 4 with DifferenceEvaluator

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));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Example 5 with DifferenceEvaluator

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));
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 DifferenceEvaluator (org.xmlunit.diff.DifferenceEvaluator)6 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)3 StringWriter (java.io.StringWriter)2 StreamResult (javax.xml.transform.stream.StreamResult)2 MediaType (org.springframework.http.MediaType)2 Result (javax.xml.transform.Result)1 SAXResult (javax.xml.transform.sax.SAXResult)1