Search in sources :

Example 1 with Marshaller

use of org.springframework.oxm.Marshaller in project spring-integration by spring-projects.

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithAllInOneMarshallerAndMessageFactory.

@Test
public void marshallingGatewayWithAllInOneMarshallerAndMessageFactory() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
    AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithAllInOneMarshallerAndMessageFactory");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
    Marshaller marshaller = context.getBean("marshallerAndUnmarshaller", Marshaller.class);
    assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller", Marshaller.class));
    assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller", Unmarshaller.class));
    WebServiceMessageFactory messageFactory = (WebServiceMessageFactory) context.getBean("messageFactory");
    assertEquals(messageFactory, TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Marshaller(org.springframework.oxm.Marshaller) WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.Test)

Example 2 with Marshaller

use of org.springframework.oxm.Marshaller in project spring-integration by spring-projects.

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithSeparateMarshallerAndUnmarshaller.

@Test
public void marshallingGatewayWithSeparateMarshallerAndUnmarshaller() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
    AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithSeparateMarshallerAndUnmarshaller");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
    Marshaller marshaller = context.getBean("marshaller", Marshaller.class);
    Unmarshaller unmarshaller = context.getBean("unmarshaller", Unmarshaller.class);
    assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller", Marshaller.class));
    assertSame(unmarshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller", Unmarshaller.class));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Marshaller(org.springframework.oxm.Marshaller) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.Test)

Example 3 with Marshaller

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

the class MarshallingHttpMessageConverterTests method readWithTypeMismatchException.

@Test
public void readWithTypeMismatchException() throws Exception {
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
    Marshaller marshaller = mock(Marshaller.class);
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(3);
    MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller);
    assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() -> converter.read(String.class, inputMessage)).withCauseInstanceOf(TypeMismatchException.class);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) Marshaller(org.springframework.oxm.Marshaller) StreamSource(javax.xml.transform.stream.StreamSource) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.jupiter.api.Test)

Example 4 with Marshaller

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

the class MarshallingHttpMessageConverterTests method write.

@Test
public void write() throws Exception {
    String body = "<root>Hello World</root>";
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    Marshaller marshaller = mock(Marshaller.class);
    willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class));
    MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
    converter.write(body, null, outputMessage);
    assertThat(outputMessage.getHeaders().getContentType()).as("Invalid content-type").isEqualTo(new MediaType("application", "xml"));
}
Also used : Marshaller(org.springframework.oxm.Marshaller) MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) MediaType(org.springframework.http.MediaType) Result(javax.xml.transform.Result) Test(org.junit.jupiter.api.Test)

Example 5 with Marshaller

use of org.springframework.oxm.Marshaller in project spring-boot by spring-projects.

the class WebServiceTemplateBuilderTests method setMarshaller.

@Test
void setMarshaller() {
    Marshaller marshaller = mock(Marshaller.class);
    WebServiceTemplate template = this.builder.setMarshaller(marshaller).build();
    assertThat(template.getMarshaller()).isEqualTo(marshaller);
}
Also used : Marshaller(org.springframework.oxm.Marshaller) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) 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