⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xfirewebannotationshandlermappingtest.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
字号:
package org.codehaus.xfire.spring.remoting;/** * @author Arjen Poutsma */import java.lang.reflect.Method;import java.util.Collections;import java.util.Properties;import org.codehaus.xfire.aegis.AbstractXFireAegisTest;import org.codehaus.xfire.aegis.type.DefaultTypeMappingRegistry;import org.codehaus.xfire.annotations.AnnotationServiceFactory;import org.codehaus.xfire.annotations.AnnotationsEmptyValidator;import org.codehaus.xfire.annotations.WebAnnotations;import org.codehaus.xfire.annotations.WebMethodAnnotation;import org.codehaus.xfire.annotations.WebServiceAnnotation;import org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping;import org.codehaus.xfire.test.EchoImpl;import org.easymock.MockControl;import org.springframework.beans.MutablePropertyValues;import org.springframework.mock.web.MockHttpServletRequest;import org.springframework.web.context.support.StaticWebApplicationContext;public class XFireWebAnnotationsHandlerMappingTest        extends AbstractXFireAegisTest{    private Jsr181HandlerMapping handlerMapping;    private MockControl control;    private WebAnnotations webAnnotations;    public void setUp()            throws Exception    {        super.setUp();        handlerMapping = new Jsr181HandlerMapping();        control = MockControl.createControl(WebAnnotations.class);        webAnnotations = (WebAnnotations) control.getMock();        handlerMapping.setWebAnnotations(webAnnotations);        handlerMapping.setXfire(getXFire());        handlerMapping.setTypeMappingRegistry(new DefaultTypeMappingRegistry(true));           }    public void testHandler()            throws Exception    {        StaticWebApplicationContext appContext = new StaticWebApplicationContext();        appContext.registerSingleton("echo", EchoImpl.class, new MutablePropertyValues());        webAnnotations.hasWebServiceAnnotation(EchoImpl.class);        control.setReturnValue(true);        webAnnotations.hasHandlerChainAnnotation(EchoImpl.class);        control.setReturnValue(false);        webAnnotations.hasSOAPBindingAnnotation(EchoImpl.class);        control.setReturnValue(false);        webAnnotations.hasWebServiceAnnotation(EchoImpl.class);        control.setReturnValue(true);        WebServiceAnnotation serviceAnnotation = new WebServiceAnnotation();        serviceAnnotation.setServiceName("EchoService");        webAnnotations.getWebServiceAnnotation(EchoImpl.class);        control.setReturnValue(serviceAnnotation);        webAnnotations.getWebServiceAnnotation(EchoImpl.class);        control.setReturnValue(serviceAnnotation);                Method echoMethod = EchoImpl.class.getMethod("echo", new Class[]{String.class});        webAnnotations.hasWebMethodAnnotation(echoMethod);        control.setDefaultReturnValue(true);                webAnnotations.hasWebMethodAnnotation(echoMethod);        control.setDefaultReturnValue(true);                WebMethodAnnotation wma = new WebMethodAnnotation();        wma.setOperationName("echo");        webAnnotations.getWebMethodAnnotation(echoMethod);        control.setDefaultReturnValue(wma);                webAnnotations.hasWebParamAnnotation(echoMethod, 0);        control.setDefaultReturnValue(false);        webAnnotations.hasWebResultAnnotation(echoMethod);        control.setDefaultReturnValue(false);        webAnnotations.hasOnewayAnnotation(echoMethod);        control.setDefaultReturnValue(false);        webAnnotations.getServiceProperties(EchoImpl.class);        control.setDefaultReturnValue(new Properties());        webAnnotations.getInHandlers(EchoImpl.class);        control.setDefaultReturnValue(Collections.EMPTY_LIST);        webAnnotations.getOutHandlers(EchoImpl.class);        control.setDefaultReturnValue(Collections.EMPTY_LIST);        webAnnotations.getFaultHandlers(EchoImpl.class);        control.setDefaultReturnValue(Collections.EMPTY_LIST);                control.replay();        String urlPrefix = "/services/";        handlerMapping.setUrlPrefix(urlPrefix);                handlerMapping.setValidator(new AnnotationsEmptyValidator());        handlerMapping.setApplicationContext(appContext);                MockHttpServletRequest request = new MockHttpServletRequest("GET", urlPrefix + "EchoService");        Object handler = handlerMapping.getHandler(request);        assertNotNull("No valid handler is returned", handler);        control.verify();    }    public void testNoAnnotation()            throws Exception    {        StaticWebApplicationContext appContext = new StaticWebApplicationContext();        appContext.registerSingleton("echo", EchoImpl.class, new MutablePropertyValues());        webAnnotations.hasWebServiceAnnotation(EchoImpl.class);        control.setReturnValue(false);        control.replay();                handlerMapping.setValidator(new AnnotationsEmptyValidator());        handlerMapping.setApplicationContext(appContext);                MockHttpServletRequest request = new MockHttpServletRequest("GET", "/services/EchoService");        Object handler = handlerMapping.getHandler(request);        assertNull("Handler is returned", handler);        control.verify();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -