diff --git a/org.springframework.integration.ws/.classpath b/org.springframework.integration.ws/.classpath index 3287c3bcf3..6005adecc0 100644 --- a/org.springframework.integration.ws/.classpath +++ b/org.springframework.integration.ws/.classpath @@ -8,13 +8,14 @@ - + + diff --git a/org.springframework.integration.ws/ivy.xml b/org.springframework.integration.ws/ivy.xml index 6934ec9aa9..b24e20819f 100644 --- a/org.springframework.integration.ws/ivy.xml +++ b/org.springframework.integration.ws/ivy.xml @@ -32,6 +32,7 @@ + diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests-context.xml b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests-context.xml new file mode 100644 index 0000000000..3426615307 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests-context.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java new file mode 100644 index 0000000000..d85c56cf95 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java @@ -0,0 +1,132 @@ +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.ws; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.annotation.ServiceActivator; +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.MarshallingFailureException; +import org.springframework.oxm.Unmarshaller; +import org.springframework.oxm.XmlMappingException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.context.MessageContext; +import org.springframework.xml.transform.StringSource; + +/** + * + * @author Iwein Fuld + * + */ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class MarshallingWebServiceIntegrationTests { + + private static final String input = ""; + + @Autowired MarshallingWebServiceInboundGateway gateway; + + @Mock + private MessageContext context; + + @Mock + private WebServiceMessage response; + + @Mock + private WebServiceMessage request; + + private Source stringSource = new StreamSource(new StringReader(input)); + + private StringWriter output = new StringWriter(); + + private Result stringResult = new StreamResult(output); + + @Before public void setupMocks(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void configOk() throws Exception { + // just flag invalid config + } + + @Test + public void sendString() throws Exception { + when(context.getResponse()).thenReturn(response); + when(context.getRequest()).thenReturn(request); + when(request.getPayloadSource()).thenReturn(stringSource ); + when(response.getPayloadResult()).thenReturn(stringResult); + gateway.invoke(context); + assertTrue(output.toString().endsWith(input)); + } + + public static class StubMarshaller implements Marshaller, Unmarshaller { + + public void marshal(Object graph, Result result) + throws XmlMappingException, IOException { + Transformer transformer; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + StringSource stringSource = new StringSource(graph.toString()); + transformer.transform(stringSource, result); + } + catch (Exception e) { + throw new MarshallingFailureException("Stub failed to marshal", + e); + } + } + + @SuppressWarnings("unchecked") + public boolean supports(Class clazz) { + return true; + } + + public Object unmarshal(Source source) throws XmlMappingException, + IOException { + //this is a hack, but we're not here to test marshalling + return input; + } + } + + public static class StubEndpoint { + @ServiceActivator(inputChannel="requests") + public Object handle(Object o) { + return o; + } + } +}