Added tests for WebServiceTargetAdapterParser.
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
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-ws-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:ws-target id="adapterWithAllInOneMarshaller" uri="http://example.org" channel="testChannel"
|
||||
marshaller="marshallerAndUnmarshaller"/>
|
||||
|
||||
<si:ws-target id="adapterWithSeparateMarshallerAndUnmarshaller" uri="http://example.org" channel="testChannel"
|
||||
marshaller="marshaller" unmarshaller="unmarshaller"/>
|
||||
|
||||
<bean id="marshallerAndUnmarshaller" class="org.springframework.integration.ws.config.StubMarshallerAndUnmarshaller"/>
|
||||
|
||||
<bean id="marshaller" class="org.springframework.integration.ws.config.StubMarshaller"/>
|
||||
|
||||
<bean id="unmarshaller" class="org.springframework.integration.ws.config.StubUnmarshaller"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
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-ws-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:ws-target id="adapterWithDefaultSourceExtractor" uri="http://example.org" channel="testChannel"/>
|
||||
|
||||
<si:ws-target id="adapterWithCustomSourceExtractor" uri="http://example.org" channel="testChannel"
|
||||
source-extractor="sourceExtractor"/>
|
||||
|
||||
<bean id="sourceExtractor" class="org.springframework.integration.ws.config.StubSourceExtractor"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user