Added more tests for WebServiceHandlerParser with 'messageFactory'.

This commit is contained in:
Mark Fisher
2008-07-10 08:38:09 +00:00
parent d85b9da3be
commit 58896de557
4 changed files with 67 additions and 7 deletions

View File

@@ -18,7 +18,6 @@ package org.springframework.integration.ws.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@@ -26,8 +25,6 @@ import org.springframework.integration.ConfigurationException;
import org.springframework.integration.ws.handler.MarshallingWebServiceHandler;
import org.springframework.integration.ws.handler.SimpleWebServiceHandler;
import org.springframework.util.StringUtils;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.SourceExtractor;
/**
* Parser for the <ws-handler/> element.
@@ -70,8 +67,7 @@ public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser
else {
String sourceExtractorRef = element.getAttribute("source-extractor");
if (StringUtils.hasText(sourceExtractorRef)) {
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
new RuntimeBeanReference(sourceExtractorRef), SourceExtractor.class.getName());
builder.addConstructorArgReference(sourceExtractorRef);
}
else {
builder.addConstructorArgValue(null);
@@ -79,8 +75,7 @@ public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser
}
String messageFactoryRef = element.getAttribute("message-factory");
if (StringUtils.hasText(messageFactoryRef)) {
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
new RuntimeBeanReference(messageFactoryRef), WebServiceMessageFactory.class.getName());
builder.addConstructorArgReference(messageFactoryRef);
}
String requestCallbackRef = element.getAttribute("request-callback");
if (StringUtils.hasText(requestCallbackRef)) {

View File

@@ -82,6 +82,20 @@ public class WebServiceHandlerParserTests {
assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
@Test
public void testSimpleWebServiceHandlerWithCustomSourceExtractorAndMessageFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"simpleWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithCustomSourceExtractorAndMessageFactory");
SourceExtractor sourceExtractor = (SourceExtractor) context.getBean("sourceExtractor");
assertEquals(SimpleWebServiceHandler.class, handler.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor"));
accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
@Test
public void testSimpleWebServiceHandlerWithCustomFaultMessageResolver() {
ApplicationContext context = new ClassPathXmlApplicationContext(
@@ -134,4 +148,37 @@ public class WebServiceHandlerParserTests {
assertEquals(callback, accessor.getPropertyValue("requestCallback"));
}
@Test
public void testWebServiceHandlerWithAllInOneMarshallerAndMessageFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"marshallingWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithAllInOneMarshallerAndMessageFactory");
assertEquals(MarshallingWebServiceHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(
handlerAccessor.getPropertyValue("webServiceTemplate"));
Marshaller marshaller = (Marshaller) context.getBean("marshallerAndUnmarshaller");
assertEquals(marshaller, templateAccessor.getPropertyValue("marshaller"));
assertEquals(marshaller, templateAccessor.getPropertyValue("unmarshaller"));
WebServiceMessageFactory messageFactory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(messageFactory, templateAccessor.getPropertyValue("messageFactory"));
}
@Test
public void testWebServiceHandlerWithSeparateMarshallerAndUnmarshallerAndMessageFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"marshallingWebServiceHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handlerWithSeparateMarshallerAndUnmarshallerAndMessageFactory");
assertEquals(MarshallingWebServiceHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
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"));
WebServiceMessageFactory messageFactory = (WebServiceMessageFactory) context.getBean("messageFactory");
assertEquals(messageFactory, templateAccessor.getPropertyValue("messageFactory"));
}
}

View File

@@ -21,6 +21,17 @@
marshaller="marshallerAndUnmarshaller"
request-callback="requestCallback"/>
<si:ws-handler id="handlerWithAllInOneMarshallerAndMessageFactory"
uri="http://example.org"
marshaller="marshallerAndUnmarshaller"
message-factory="messageFactory"/>
<si:ws-handler id="handlerWithSeparateMarshallerAndUnmarshallerAndMessageFactory"
uri="http://example.org"
marshaller="marshaller"
unmarshaller="unmarshaller"
message-factory="messageFactory"/>
<bean id="marshallerAndUnmarshaller" class="org.springframework.integration.ws.config.StubMarshallerAndUnmarshaller"/>
<bean id="marshaller" class="org.springframework.integration.ws.config.StubMarshaller"/>
@@ -29,4 +40,6 @@
<bean id="requestCallback" class="org.springframework.integration.ws.config.StubWebServiceMessageCallback"/>
<bean id="messageFactory" class="org.springframework.integration.ws.config.StubMessageFactory"/>
</beans>

View File

@@ -22,6 +22,11 @@
uri="http://example.org"
message-factory="messageFactory"/>
<si:ws-handler id="handlerWithCustomSourceExtractorAndMessageFactory"
uri="http://example.org"
source-extractor="sourceExtractor"
message-factory="messageFactory"/>
<si:ws-handler id="handlerWithCustomFaultMessageResolver"
uri="http://example.org"
fault-message-resolver="faultMessageResolver"/>