001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.jaxws.description;
021:
022: import junit.framework.TestCase;
023: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
024: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
025: import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
026: import org.apache.axis2.jaxws.description.builder.WebMethodAnnot;
027: import org.apache.axis2.jaxws.description.builder.WebParamAnnot;
028: import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
029:
030: import javax.jws.WebParam;
031: import javax.xml.ws.WebServiceException;
032: import java.util.HashMap;
033: import java.util.List;
034:
035: /**
036: * Tests the creation of the Description classes based on a service implementation bean and various
037: * combinations of annotations
038: */
039: public class AnnotationServiceImplWithDBCTests extends TestCase {
040: /**
041: * Create the description classes with a service implementation that contains the @WebService
042: * JSR-181 annotation which references an SEI.
043: */
044:
045: //Test creation of a Service Description from DBC, using a basic list.
046: //An implicit SEI that extends only java.lang.object
047: public void testServiceImplAsImplicitSEI() {
048: //org.apache.log4j.BasicConfigurator.configure();
049:
050: //Build a Hashmap of DescriptionBuilderComposites that contains the serviceImpl and
051: //all necessary associated DBC's possibly including SEI and superclasses
052: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
053:
054: DescriptionBuilderComposite dbc = buildDBCNoEndpointInterface();
055:
056: dbcMap.put(dbc.getClassName(), dbc);
057:
058: // TODO: This test is invalid as is. It does not specify WSDL, and WSDL generator is not currently available in Open Source
059: // So, an exception is currently being thrown. It may be the correct fix is to NOT always try to generate WSDL; and only
060: // try to generate it if it is asked for.
061: try {
062: List<ServiceDescription> serviceDescList = DescriptionFactory
063: .createServiceDescriptionFromDBCMap(dbcMap);
064: assertNotNull(serviceDescList.get(0));
065:
066: //We know this list contains only one SD, so no need to loop
067: EndpointDescription[] endpointDesc = serviceDescList.get(0)
068: .getEndpointDescriptions();
069: assertNotNull(endpointDesc);
070: assertEquals(endpointDesc.length, 1);
071:
072: // TODO: How will the JAX-WS dispatcher get the appropriate port (i.e. endpoint)? Currently assumes [0]
073: EndpointInterfaceDescription endpointIntfDesc = endpointDesc[0]
074: .getEndpointInterfaceDescription();
075: assertNotNull(endpointIntfDesc);
076:
077: } catch (WebServiceException e) {
078: }
079:
080: /*
081: * Deprecated -- this used to be the test for
082: * EndpointInterfaceDescription.getOperationForJavaMethod
083: */
084: /*
085: OperationDescription[] operations = endpointIntfDesc.getOperations();
086:
087: String[] paramTypes = operations[0].getJavaParameters();
088: assertNotNull(paramTypes);
089: assertEquals(paramTypes.length, 1);
090: assertEquals("javax.xml.ws.Holder", paramTypes[0]);
091:
092: // Test RequestWrapper annotations
093: assertEquals(operations[0].getRequestWrapperLocalName(), "Echo");
094: assertEquals(operations[0].getRequestWrapperTargetNamespace(), "http://ws.apache.org/axis2/tests");
095: assertEquals(operations[0].getRequestWrapperClassName(), "org.apache.ws.axis2.tests.Echo");
096:
097: // Test ResponseWrapper annotations
098: assertEquals(operations[0].getResponseWrapperLocalName(), "EchoResponse");
099: assertEquals(operations[0].getResponseWrapperTargetNamespace(), "http://ws.apache.org/axis2/tests");
100: assertEquals(operations[0].getResponseWrapperClassName(), "org.apache.ws.axis2.tests.EchoResponse");
101:
102: // Test SOAPBinding default; that annotation is not present in the SEI
103: // Note that annotation could occur on the operation or the type
104: // (although on this SEI it doesn't occur either place).
105: assertEquals(SOAPBinding.Style.DOCUMENT, operations[0].getSoapBindingStyle());
106: assertEquals(SOAPBinding.Style.DOCUMENT, endpointIntfDesc.getSoapBindingStyle());
107: */
108: }
109:
110: //TODO: Basic Test with EndpointInterface set to something valid, so another DBC must
111: // exist in list
112:
113: //TODO: Basic Test for Provider
114:
115: //TODO: Validation Tests
116: // - Setting WS and WSP
117: // - Fail just one in List, But allow successful ones to pass
118:
119: /*
120: * Method to return the endpoint interface description for a given implementation class.
121: */
122:
123: //private EndpointInterfaceDescription getEndpointInterfaceDesc(Class implementationClass) {
124: // // Use the description factory directly; this will be done within the JAX-WS runtime
125: // return (new EndpointInterfaceDescription());
126: // //return testEndpointInterfaceDesc;
127: //}
128: static public DescriptionBuilderComposite buildDBCNoEndpointInterface() {
129:
130: //Create a WebServiceAnnot
131: String WSName = "EchoServiceAnnotated";
132: String WSTargetNamespace = "http://description.jaxws.axis2.apache.org/";
133: String WSServiceName = "EchoServiceName";
134: //String WSWsdlLocation = "http://EchoService/wsdl";
135: String WSWsdlLocation = "";
136: String WSEndpointInterface = "";
137: String WSPortName = "EchoServiceAnnotatedPort";
138:
139: WebServiceAnnot webServiceAnnot = WebServiceAnnot
140: .createWebServiceAnnotImpl(WSName, WSTargetNamespace,
141: WSServiceName, WSWsdlLocation,
142: WSEndpointInterface, WSPortName);
143:
144: //Create a WebMethodAnnot
145: String operationName = "echoStringMethod";
146: String action = "urn:EchoStringMethod";
147: boolean exclude = false;
148:
149: WebMethodAnnot webMethodAnnot = WebMethodAnnot
150: .createWebMethodAnnotImpl();
151: webMethodAnnot.setOperationName(operationName);
152: webMethodAnnot.setAction(action);
153: webMethodAnnot.setExclude(exclude);
154:
155: //Create the WebParamAnnot
156: String WPName = "arg0";
157: String WPPartName = "sku";
158: String WPTargetNamespace = "http://description.jaxws.axis2.apache.org/";
159: WebParam.Mode WPMode = WebParam.Mode.IN;
160: boolean WPHeader = true;
161:
162: WebParamAnnot webParamAnnot = WebParamAnnot
163: .createWebParamAnnotImpl();
164: webParamAnnot.setName(WPName);
165: webParamAnnot.setPartName(WPPartName);
166: webParamAnnot.setMode(WPMode);
167: webParamAnnot.setTargetNamespace(WPTargetNamespace);
168: webParamAnnot.setHeader(WPHeader);
169:
170: //Build up the the DBC and all necessary composites
171: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
172: pdc.setParameterType("java.lang.String");
173: pdc.setWebParamAnnot(webParamAnnot);
174:
175: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
176: mdc.setWebMethodAnnot(webMethodAnnot);
177: mdc.setMethodName(operationName);
178: mdc.addParameterDescriptionComposite(pdc, 0);
179:
180: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
181: dbc
182: .setClassName("org.apache.axis2.samples.EchoServiceAnnotated");
183: dbc.setWebServiceAnnot(webServiceAnnot);
184: dbc.addMethodDescriptionComposite(mdc);
185:
186: return dbc;
187: }
188: }
|