Search in sources :

Example 11 with Marshaller

use of org.springframework.oxm.Marshaller 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

Marshaller (org.springframework.oxm.Marshaller)11 Unmarshaller (org.springframework.oxm.Unmarshaller)6 Test (org.junit.jupiter.api.Test)5 Test (org.junit.Test)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)4 IOException (java.io.IOException)2 Result (javax.xml.transform.Result)2 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)2 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 StAXSource (javax.xml.transform.stax.StAXSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Diff (org.custommonkey.xmlunit.Diff)1 MediaType (org.springframework.http.MediaType)1