Search in sources :

Example 6 with MarshallingFailureException

use of org.springframework.oxm.MarshallingFailureException in project spring-framework by spring-projects.

the class MarshallingHttpMessageConverterTests method writeWithMarshallingFailureException.

@Test
public void writeWithMarshallingFailureException() throws Exception {
    String body = "<root>Hello World</root>";
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    MarshallingFailureException ex = new MarshallingFailureException("forced");
    Marshaller marshaller = mock(Marshaller.class);
    willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class));
    MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
    assertThatExceptionOfType(HttpMessageNotWritableException.class).isThrownBy(() -> converter.write(body, null, outputMessage)).withCause(ex);
}
Also used : Marshaller(org.springframework.oxm.Marshaller) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MarshallingFailureException(org.springframework.oxm.MarshallingFailureException) Result(javax.xml.transform.Result) Test(org.junit.jupiter.api.Test)

Aggregations

MarshallingFailureException (org.springframework.oxm.MarshallingFailureException)6 IOException (java.io.IOException)3 Transformer (javax.xml.transform.Transformer)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Result (javax.xml.transform.Result)2 TransformerException (javax.xml.transform.TransformerException)2 DOMResult (javax.xml.transform.dom.DOMResult)2 SAXResult (javax.xml.transform.sax.SAXResult)2 StreamResult (javax.xml.transform.stream.StreamResult)2 StreamSource (javax.xml.transform.stream.StreamSource)1 Test (org.junit.jupiter.api.Test)1 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)1 Marshaller (org.springframework.oxm.Marshaller)1 XmlMappingException (org.springframework.oxm.XmlMappingException)1