RESOLVED - issue INT-162: Provide Spring-WS source adapters

http://jira.springframework.org/browse/INT-162

Added integration test for inbound gateway
This commit is contained in:
Iwein Fuld
2009-03-12 10:48:47 +00:00
parent b817c04202
commit 3c9ddafdcd
4 changed files with 162 additions and 1 deletions

View File

@@ -8,13 +8,14 @@
<classpathentry kind="var" path="IVY_CACHE/javax.xml.soap/com.springsource.javax.xml.soap/1.3.0/com.springsource.javax.xml.soap-1.3.0.jar" sourcepath="/IVY_CACHE/javax.xml.soap/com.springsource.javax.xml.soap/1.3.0/com.springsource.javax.xml.soap-sources-1.3.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.xml.stream/com.springsource.javax.xml.stream/1.0.1/com.springsource.javax.xml.stream-1.0.1.jar" sourcepath="/IVY_CACHE/javax.xml.stream/com.springsource.javax.xml.stream/1.0.1/com.springsource.javax.xml.stream-sources-1.0.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-1.1.1.jar" sourcepath="/IVY_CACHE/org.apache.commons/com.springsource.org.apache.commons.logging/1.1.1/com.springsource.org.apache.commons.logging-sources-1.1.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-4.4.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-sources-4.4.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.beans/2.5.6.A/org.springframework.beans-2.5.6.A.jar" sourcepath="/IVY_CACHE/org.springframework/org.springframework.beans/2.5.6.A/org.springframework.beans-sources-2.5.6.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.context/2.5.6.A/org.springframework.context-2.5.6.A.jar" sourcepath="/IVY_CACHE/org.springframework/org.springframework.context/2.5.6.A/org.springframework.context-sources-2.5.6.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.core/2.5.6.A/org.springframework.core-2.5.6.A.jar" sourcepath="/IVY_CACHE/org.springframework/org.springframework.core/2.5.6.A/org.springframework.core-sources-2.5.6.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework.ws/org.springframework.ws/1.5.5.A/org.springframework.ws-1.5.5.A.jar" sourcepath="/IVY_CACHE/org.springframework.ws/org.springframework.ws/1.5.5.A/org.springframework.ws-sources-1.5.5.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework.ws/org.springframework.oxm/1.5.5.A/org.springframework.oxm-1.5.5.A.jar" sourcepath="/IVY_CACHE/org.springframework.ws/org.springframework.oxm/1.5.5.A/org.springframework.oxm-sources-1.5.5.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework.ws/org.springframework.xml/1.5.5.A/org.springframework.xml-1.5.5.A.jar" sourcepath="/IVY_CACHE/org.springframework.ws/org.springframework.xml/1.5.5.A/org.springframework.xml-sources-1.5.5.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.springframework/org.springframework.test/2.5.6.A/org.springframework.test-2.5.6.A.jar" sourcepath="IVY_CACHE/org.springframework/org.springframework.test/2.5.6.A/org.springframework.test-sources-2.5.6.A.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-4.4.0.jar" sourcepath="/IVY_CACHE/org.junit/com.springsource.org.junit/4.4.0/com.springsource.org.junit-sources-4.4.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.mockito/com.springsource.org.mockito/1.6.0/com.springsource.org.mockito-1.6.0.jar" sourcepath="/IVY_CACHE/org.mockito/com.springsource.org.mockito/1.6.0/com.springsource.org.mockito-sources-1.6.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.objenesis/com.springsource.org.objenesis/1.0.0/com.springsource.org.objenesis-1.0.0.jar" sourcepath="/IVY_CACHE/org.objenesis/com.springsource.org.objenesis/1.0.0/com.springsource.org.objenesis-sources-1.0.0.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.springframework.integration.adapter"/>

View File

@@ -32,6 +32,7 @@
</dependency>
<!-- test dependencies -->
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.4.0" conf="test->runtime"/>
<dependency org="org.springframework" name="org.springframework.test" rev="2.5.6.A" conf="test->runtime"/>
<dependency org="org.mockito" name="com.springsource.org.mockito" rev="1.6.0" conf="test->runtime"/>
<dependency org="org.springframework" name="org.springframework.test" rev="2.5.6.A" conf="test->runtime"/>
</dependencies>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:si="http://www.springframework.org/schema/integration"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/spring-integration-ws-1.0.xsd">
<si:annotation-config />
<bean
class="org.springframework.integration.ws.MarshallingWebServiceInboundGateway"
p:requestChannel-ref="requests" p:marshaller-ref="marshaller"
p:unmarshaller-ref="marshaller" />
<bean id="marshaller"
class="org.springframework.integration.ws.MarshallingWebServiceIntegrationTests$StubMarshaller" />
<si:channel id="requests" />
<si:service-activator input-channel="requests"
ref="endpointStub" />
<bean id="endpointStub"
class="org.springframework.integration.ws.MarshallingWebServiceIntegrationTests$StubEndpoint" />
</beans>

View File

@@ -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 = "<hello/>";
@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;
}
}
}