📄 annotationservicefactorytest.java
字号:
package org.codehaus.xfire.annotations;/** * @author Arjen Poutsma */import java.lang.reflect.Method;import java.util.Collection;import java.util.Collections;import java.util.Properties;import javax.xml.namespace.QName;import org.codehaus.xfire.aegis.AbstractXFireAegisTest;import org.codehaus.xfire.annotations.commons.CommonsWebAttributes;import org.codehaus.xfire.annotations.soap.SOAPBindingAnnotation;import org.codehaus.xfire.service.MessagePartInfo;import org.codehaus.xfire.service.OperationInfo;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.ServiceInfo;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import org.codehaus.xfire.soap.AbstractSoapBinding;import org.codehaus.xfire.soap.SoapConstants;import org.codehaus.xfire.wsdl.ResourceWSDL;import org.easymock.MockControl;public class AnnotationServiceFactoryTest extends AbstractXFireAegisTest{ private AnnotationServiceFactory annotationServiceFactory; private MockControl webAnnotationsControl; private WebAnnotations webAnnotations; public void setUp() throws Exception { super.setUp(); webAnnotationsControl = MockControl.createControl(WebAnnotations.class); webAnnotations = (WebAnnotations) webAnnotationsControl.getMock(); annotationServiceFactory = new AnnotationServiceFactory(webAnnotations, getXFire().getTransportManager(), null); annotationServiceFactory.setValidator(new AnnotationsEmptyValidator()); } public void testCreateWithFileWSDL() throws Exception { testCreate(getTestFile("src/test/org/codehaus/xfire/annotations/echo.wsdl").getAbsolutePath()); } public void testCreateWithClasspathWSDL() throws Exception { testCreate("org/codehaus/xfire/annotations/echo.wsdl"); } public void testCreate(String wsdlLocation) throws Exception { webAnnotations.hasSOAPBindingAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.hasWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(true); webAnnotations.hasHandlerChainAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); WebServiceAnnotation annotation = new WebServiceAnnotation(); annotation.setServiceName("EchoService"); annotation.setTargetNamespace("http://xfire.codehaus.org/EchoService"); annotation.setWsdlLocation(wsdlLocation); webAnnotations.getWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(annotation); Method echoMethod = EchoServiceImpl.class.getMethod("echo", new Class[]{String.class}); webAnnotations.hasWebMethodAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(true); webAnnotations.hasWebMethodAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(true); WebMethodAnnotation wma = new WebMethodAnnotation(); wma.setAction("test"); webAnnotations.getWebMethodAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(wma); webAnnotations.hasOnewayAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.hasWebParamAnnotation(echoMethod, 0); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.hasWebResultAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(false); Method asyncMethod = EchoServiceImpl.class.getMethod("async", new Class[0]); webAnnotations.hasWebMethodAnnotation(asyncMethod); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.getServiceProperties(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(new Properties()); webAnnotations.getInHandlers(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(Collections.EMPTY_LIST); webAnnotations.getOutHandlers(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(Collections.EMPTY_LIST); webAnnotations.getFaultHandlers(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(Collections.EMPTY_LIST); webAnnotationsControl.replay(); Service service = annotationServiceFactory.create(EchoServiceImpl.class); webAnnotationsControl.verify(); assertEquals(new QName(annotation.getTargetNamespace(), "EchoService"), service.getName()); assertEquals(new QName(annotation.getTargetNamespace(), "EchoServicePortType"), service.getServiceInfo().getPortType()); assertTrue(service.getWSDLWriter() instanceof ResourceWSDL); } public void testNoWebServiceAnnotation() { webAnnotations.hasSOAPBindingAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.hasWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); webAnnotationsControl.replay(); try { annotationServiceFactory.create(EchoServiceImpl.class); fail("Not a AnnotationException thrown"); } catch (AnnotationException e) { // expected behavior } } public void testEndpointInterface() throws SecurityException, NoSuchMethodException { webAnnotations.hasSOAPBindingAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); webAnnotations.hasWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(true); webAnnotations.hasHandlerChainAnnotation(EchoServiceImpl.class); webAnnotationsControl.setDefaultReturnValue(false); WebServiceAnnotation implAnnotation = new WebServiceAnnotation(); implAnnotation.setServiceName("Echo"); implAnnotation.setTargetNamespace("not used"); implAnnotation.setEndpointInterface(EchoService.class.getName()); implAnnotation.setPortName("EchoPort"); webAnnotations.getWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setReturnValue(implAnnotation); webAnnotations.getWebServiceAnnotation(EchoServiceImpl.class); webAnnotationsControl.setReturnValue(implAnnotation); webAnnotations.hasWebServiceAnnotation(EchoService.class); webAnnotationsControl.setReturnValue(true); WebServiceAnnotation intfAnnotation = new WebServiceAnnotation(); intfAnnotation.setName("EchoPortType"); intfAnnotation.setTargetNamespace("http://xfire.codehaus.org/EchoService"); intfAnnotation.setEndpointInterface(EchoService.class.getName()); webAnnotations.getWebServiceAnnotation(EchoService.class); webAnnotationsControl.setDefaultReturnValue(intfAnnotation); Method asyncMethod = EchoServiceImpl.class.getMethod("async", new Class[]{}); webAnnotations.hasWebMethodAnnotation(asyncMethod); webAnnotationsControl.setReturnValue(false); webAnnotations.hasWebResultAnnotation(asyncMethod); webAnnotationsControl.setDefaultReturnValue(false); Method echoMethod = EchoServiceImpl.class.getMethod("echo", new Class[]{String.class}); webAnnotations.hasWebMethodAnnotation(echoMethod); webAnnotationsControl.setDefaultReturnValue(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -