From e900ad54c5e3bbb027559d3bc51fa6dcc8b23e61 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 28 Mar 2008 20:48:46 +0000 Subject: [PATCH] Added tests for WebServiceTargetAdapterParser. --- .../integration/ws/config/StubMarshaller.java | 38 ++++++++ .../config/StubMarshallerAndUnmarshaller.java | 44 +++++++++ .../ws/config/StubSourceExtractor.java | 35 +++++++ .../ws/config/StubUnmarshaller.java | 39 ++++++++ .../WebServiceTargetAdapterParserTests.java | 92 +++++++++++++++++++ ...lingWebServiceTargetAdapterParserTests.xml | 26 ++++++ ...mpleWebServiceTargetAdapterParserTests.xml | 21 +++++ 7 files changed, 295 insertions(+) create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshaller.java create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshallerAndUnmarshaller.java create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubSourceExtractor.java create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubUnmarshaller.java create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParserTests.java create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/marshallingWebServiceTargetAdapterParserTests.xml create mode 100644 spring-integration-ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceTargetAdapterParserTests.xml diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshaller.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshaller.java new file mode 100644 index 0000000000..7fea47e992 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshaller.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2008 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.config; + +import java.io.IOException; + +import javax.xml.transform.Result; + +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.XmlMappingException; + +/** + * @author Mark Fisher + */ +public class StubMarshaller implements Marshaller { + + public boolean supports(Class clazz) { + return false; + } + + public void marshal(Object graph, Result result) throws XmlMappingException, IOException { + } + +} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshallerAndUnmarshaller.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshallerAndUnmarshaller.java new file mode 100644 index 0000000000..a3a8428ad3 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubMarshallerAndUnmarshaller.java @@ -0,0 +1,44 @@ +/* + * Copyright 2002-2008 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.config; + +import java.io.IOException; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; + +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.oxm.XmlMappingException; + +/** + * @author Mark Fisher + */ +public class StubMarshallerAndUnmarshaller implements Marshaller, Unmarshaller { + + public boolean supports(Class clazz) { + return false; + } + + public void marshal(Object graph, Result result) throws XmlMappingException, IOException { + } + + public Object unmarshal(Source source) throws XmlMappingException, IOException { + return null; + } + +} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubSourceExtractor.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubSourceExtractor.java new file mode 100644 index 0000000000..ea616d20a8 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubSourceExtractor.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2008 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.config; + +import java.io.IOException; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; + +import org.springframework.ws.client.core.SourceExtractor; + +/** + * @author Mark Fisher + */ +public class StubSourceExtractor implements SourceExtractor { + + public Object extractData(Source source) throws IOException, TransformerException { + return "test"; + } + +} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubUnmarshaller.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubUnmarshaller.java new file mode 100644 index 0000000000..356968f418 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/StubUnmarshaller.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2008 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.config; + +import java.io.IOException; + +import javax.xml.transform.Source; + +import org.springframework.oxm.Unmarshaller; +import org.springframework.oxm.XmlMappingException; + +/** + * @author Mark Fisher + */ +public class StubUnmarshaller implements Unmarshaller { + + public boolean supports(Class clazz) { + return false; + } + + public Object unmarshal(Source source) throws XmlMappingException, IOException { + return null; + } + +} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParserTests.java new file mode 100644 index 0000000000..27da9b33af --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceTargetAdapterParserTests.java @@ -0,0 +1,92 @@ +/* + * Copyright 2002-2008 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.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.endpoint.DefaultMessageEndpoint; +import org.springframework.integration.ws.adapter.MarshallingWebServiceTargetAdapter; +import org.springframework.integration.ws.adapter.SimpleWebServiceTargetAdapter; +import org.springframework.oxm.Marshaller; +import org.springframework.oxm.Unmarshaller; +import org.springframework.ws.client.core.SourceExtractor; + +/** + * @author Mark Fisher + */ +public class WebServiceTargetAdapterParserTests { + + @Test + public void testSimpleWebServiceTargetAdapterWithDefaultSourceExtractor() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = + (DefaultMessageEndpoint) context.getBean("adapterWithDefaultSourceExtractor"); + assertEquals(SimpleWebServiceTargetAdapter.class, endpoint.getHandler().getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint.getHandler()); + assertEquals("DefaultSourceExtractor", accessor.getPropertyValue("sourceExtractor").getClass().getSimpleName()); + } + + @Test + public void testSimpleWebServiceTargetAdapterWithCustomSourceExtractor() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = + (DefaultMessageEndpoint) context.getBean("adapterWithCustomSourceExtractor"); + assertEquals(SimpleWebServiceTargetAdapter.class, endpoint.getHandler().getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint.getHandler()); + SourceExtractor sourceExtractor = (SourceExtractor) context.getBean("sourceExtractor"); + assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor")); + } + + @Test + public void testWebServiceTargetAdapterWithAllInOneMarshaller() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "marshallingWebServiceTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = + (DefaultMessageEndpoint) context.getBean("adapterWithAllInOneMarshaller"); + assertEquals(MarshallingWebServiceTargetAdapter.class, endpoint.getHandler().getClass()); + DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(endpoint.getHandler()); + DirectFieldAccessor templateAccessor = new DirectFieldAccessor( + handlerAccessor.getPropertyValue("webServiceTemplate")); + Marshaller marshaller = (Marshaller) context.getBean("marshallerAndUnmarshaller"); + assertEquals(marshaller, templateAccessor.getPropertyValue("marshaller")); + assertEquals(marshaller, templateAccessor.getPropertyValue("unmarshaller")); + } + + @Test + public void testWebServiceTargetAdapterWithSeparateMarshallerAndUnmarshaller() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "marshallingWebServiceTargetAdapterParserTests.xml", this.getClass()); + DefaultMessageEndpoint endpoint = + (DefaultMessageEndpoint) context.getBean("adapterWithSeparateMarshallerAndUnmarshaller"); + assertEquals(MarshallingWebServiceTargetAdapter.class, endpoint.getHandler().getClass()); + DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(endpoint.getHandler()); + DirectFieldAccessor templateAccessor = new DirectFieldAccessor( + handlerAccessor.getPropertyValue("webServiceTemplate")); + Marshaller marshaller = (Marshaller) context.getBean("marshaller"); + Unmarshaller unmarshaller = (Unmarshaller) context.getBean("unmarshaller"); + assertEquals(marshaller, templateAccessor.getPropertyValue("marshaller")); + assertEquals(unmarshaller, templateAccessor.getPropertyValue("unmarshaller")); + } + +} diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/marshallingWebServiceTargetAdapterParserTests.xml b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/marshallingWebServiceTargetAdapterParserTests.xml new file mode 100644 index 0000000000..4924766c25 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/marshallingWebServiceTargetAdapterParserTests.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceTargetAdapterParserTests.xml b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceTargetAdapterParserTests.xml new file mode 100644 index 0000000000..1aa5b2b4b7 --- /dev/null +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceTargetAdapterParserTests.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + +