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: package org.apache.axis2.jaxws.description.builder.converter;
020:
021: import junit.framework.TestCase;
022: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
023: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
024: import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
025: import org.apache.axis2.jaxws.description.builder.WebMethodAnnot;
026: import org.apache.axis2.jaxws.description.builder.WebParamAnnot;
027: import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
028: import org.apache.log4j.BasicConfigurator;
029:
030: import javax.jws.WebMethod;
031: import javax.jws.WebParam;
032: import javax.jws.WebService;
033: import java.util.Collections;
034: import java.util.Comparator;
035: import java.util.HashMap;
036: import java.util.List;
037:
038: public class ReflectiveConverterTests extends TestCase {
039: static {
040: // Note you will probably need to increase the java heap size, for example
041: // -Xmx512m. This can be done by setting maven.junit.jvmargs in project.properties.
042: // To change the settings, edit the log4j.property file
043: // in the test-resources directory.
044: BasicConfigurator.configure();
045: }
046:
047: private static DescriptionBuilderComposite implDBC;
048: private static DescriptionBuilderComposite seiDBC;
049:
050: public void setUp() {
051: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
052: SimpleServiceImpl.class);
053: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
054: .produceDBC();
055: assertNotNull(dbcMap);
056: implDBC = dbcMap
057: .get("org.apache.axis2.jaxws.description.builder.converter.SimpleServiceImpl");
058: seiDBC = dbcMap
059: .get("org.apache.axis2.jaxws.description.builder.converter.SimpleService");
060: }
061:
062: public static void testCreateImplDBC() {
063: assertNotNull(implDBC);
064: WebServiceAnnot wsAnnot = implDBC.getWebServiceAnnot();
065: assertNotNull(wsAnnot);
066: assertEquals("SimpleService", wsAnnot.serviceName());
067: }
068:
069: public static void testImplMethods() {
070: assertNotNull(implDBC);
071: List<MethodDescriptionComposite> mdcList = sortList(implDBC
072: .getMethodDescriptionsList());
073: sortList(mdcList);
074: assertNotNull(mdcList);
075: assertEquals(mdcList.size(), 3);
076: MethodDescriptionComposite mdc = mdcList.get(0);
077: assertNotNull(mdc);
078: assertEquals("<init>", mdc.getMethodName());
079: mdc = mdcList.get(1);
080: assertNotNull(mdc);
081: assertEquals("invoke", mdc.getMethodName());
082: assertEquals("java.lang.String", mdc.getReturnType());
083: mdc = mdcList.get(2);
084: assertNotNull(mdc);
085: assertEquals("invoke2", mdc.getMethodName());
086: assertEquals("int", mdc.getReturnType());
087: }
088:
089: public static void testImplParams() {
090: assertNotNull(implDBC);
091: List<MethodDescriptionComposite> mdcList = sortList(implDBC
092: .getMethodDescriptionsList());
093: assertNotNull(mdcList);
094: assertEquals(mdcList.size(), 3);
095: MethodDescriptionComposite mdc = mdcList.get(0);
096: assertNotNull(mdc);
097: List<ParameterDescriptionComposite> pdcList = mdc
098: .getParameterDescriptionCompositeList();
099: assertNotNull(pdcList);
100: assertEquals(0, pdcList.size());
101: mdc = mdcList.get(1);
102: assertNotNull(mdc);
103: pdcList = mdc.getParameterDescriptionCompositeList();
104: assertNotNull(pdcList);
105: assertEquals(pdcList.size(), 1);
106: ParameterDescriptionComposite pdc = pdcList.get(0);
107: assertEquals("java.util.List<java.lang.String>", pdc
108: .getParameterType());
109: mdc = mdcList.get(2);
110: pdcList = mdc.getParameterDescriptionCompositeList();
111: assertNotNull(pdcList);
112: assertEquals(pdcList.size(), 2);
113: pdc = pdcList.get(0);
114: assertEquals("int", pdc.getParameterType());
115: pdc = pdcList.get(1);
116: assertNotNull(pdc);
117: assertEquals("int", pdc.getParameterType());
118: }
119:
120: public static void testCreateSEIDBC() {
121: assertNotNull(seiDBC);
122: WebServiceAnnot wsAnnot = seiDBC.getWebServiceAnnot();
123: assertNotNull(wsAnnot);
124: assertEquals("SimpleServicePort", wsAnnot.name());
125: }
126:
127: public static void testSEIMethods() {
128: assertNotNull(seiDBC);
129: List<MethodDescriptionComposite> mdcList = sortList(seiDBC
130: .getMethodDescriptionsList());
131: assertNotNull(mdcList);
132: assertEquals(mdcList.size(), 2);
133: MethodDescriptionComposite mdc = mdcList.get(0);
134: assertEquals("invoke", mdc.getMethodName());
135: assertEquals("java.lang.String", mdc.getReturnType());
136: assertNotNull(mdc.getWebMethodAnnot());
137: WebMethodAnnot wmAnnot = mdc.getWebMethodAnnot();
138: assertEquals("invoke", wmAnnot.operationName());
139: mdc = mdcList.get(1);
140: assertEquals("invoke2", mdc.getMethodName());
141: assertEquals("int", mdc.getReturnType());
142: }
143:
144: public static void testSEIParams() {
145: assertNotNull(seiDBC);
146: List<MethodDescriptionComposite> mdcList = sortList(seiDBC
147: .getMethodDescriptionsList());
148: assertNotNull(mdcList);
149: assertEquals(mdcList.size(), 2);
150: MethodDescriptionComposite mdc = mdcList.get(0);
151: assertNotNull(mdc);
152: List<ParameterDescriptionComposite> pdcList = mdc
153: .getParameterDescriptionCompositeList();
154: assertNotNull(pdcList);
155: assertEquals(pdcList.size(), 1);
156: ParameterDescriptionComposite pdc = pdcList.get(0);
157: assertNotNull(pdc);
158: assertEquals("java.util.List<java.lang.String>", pdc
159: .getParameterType());
160: WebParamAnnot wpAnnot = pdc.getWebParamAnnot();
161: assertNotNull(wpAnnot);
162: assertEquals("echoString", wpAnnot.name());
163: mdc = mdcList.get(1);
164: assertNotNull(mdc);
165: pdcList = mdc.getParameterDescriptionCompositeList();
166: assertNotNull(pdcList);
167: assertEquals(pdcList.size(), 2);
168: pdc = pdcList.get(0);
169: assertNotNull(pdc);
170: assertEquals("int", pdc.getParameterType());
171: assertNull(pdc.getWebParamAnnot());
172: pdc = pdcList.get(1);
173: assertNotNull(pdc);
174: assertEquals("int", pdc.getParameterType());
175: assertNull(pdc.getWebParamAnnot());
176: }
177:
178: public void testDBCHierarchy() {
179: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
180: ChildClass.class);
181: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
182: .produceDBC();
183: DescriptionBuilderComposite dbc = dbcMap
184: .get("org.apache.axis2.jaxws.description.builder.converter.ChildClass");
185: assertNotNull(dbc);
186: List<MethodDescriptionComposite> mdcList = sortList(dbc
187: .getMethodDescriptionsList());
188: assertNotNull(mdcList);
189: assertEquals(mdcList.size(), 3);
190: assertEquals("<init>", mdcList.get(0).getMethodName());
191: assertEquals("doAbstract", mdcList.get(1).getMethodName());
192: assertEquals("extraMethod", mdcList.get(2).getMethodName());
193: dbc = dbcMap
194: .get("org.apache.axis2.jaxws.description.builder.converter.ParentClass");
195: assertNotNull(dbc);
196: mdcList = sortList(dbc.getMethodDescriptionsList());
197: assertNotNull(mdcList);
198: assertEquals(mdcList.size(), 2);
199: assertEquals("<init>", mdcList.get(0).getMethodName());
200: assertEquals("doParentAbstract", mdcList.get(1).getMethodName());
201: dbc = dbcMap
202: .get("org.apache.axis2.jaxws.description.builder.converter.ServiceInterface");
203: assertNotNull(dbc);
204: mdcList = sortList(dbc.getMethodDescriptionsList());
205: assertNotNull(mdcList);
206: assertEquals(mdcList.size(), 1);
207: assertEquals("doAbstract", mdcList.get(0).getMethodName());
208: dbc = dbcMap
209: .get("org.apache.axis2.jaxws.description.builder.converter.CommonService");
210: assertNotNull(dbc);
211: mdcList = sortList(dbc.getMethodDescriptionsList());
212: assertNotNull(mdcList);
213: assertEquals(mdcList.size(), 1);
214: assertEquals("extraMethod", mdcList.get(0).getMethodName());
215: dbc = dbcMap
216: .get("org.apache.axis2.jaxws.description.builder.converter.ParentServiceInterface");
217: assertNotNull(dbc);
218: mdcList = sortList(dbc.getMethodDescriptionsList());
219: assertNotNull(mdcList);
220: assertEquals(mdcList.size(), 1);
221: assertEquals("doParentAbstract", mdcList.get(0).getMethodName());
222: dbc = dbcMap
223: .get("org.apache.axis2.jaxws.description.builder.converter.AbstractService");
224: assertNotNull(dbc);
225: mdcList = sortList(dbc.getMethodDescriptionsList());
226: assertNotNull(mdcList);
227: assertEquals(mdcList.size(), 2);
228: assertEquals("<init>", mdcList.get(0).getMethodName());
229: assertEquals("someAbstractMethod", mdcList.get(1)
230: .getMethodName());
231:
232: }
233:
234: private static List<MethodDescriptionComposite> sortList(
235: List<MethodDescriptionComposite> mdc) {
236: Comparator<MethodDescriptionComposite> c = new Comparator<MethodDescriptionComposite>() {
237: public int compare(MethodDescriptionComposite mdc1,
238: MethodDescriptionComposite o2) {
239: return mdc1.getMethodName().compareTo(
240: o2.getMethodName());
241: }
242: };
243: Collections.sort(mdc, c);
244: return mdc;
245: }
246: }
247:
248: @WebService(serviceName="SimpleService",endpointInterface="org.apache.axis2.jaxws." + "description.builder.converter.SimpleService")
249: class SimpleServiceImpl {
250: public SimpleServiceImpl() {
251: }
252:
253: ;
254:
255: public String invoke(List<String> myParam) {
256: return myParam.get(0);
257: }
258:
259: public int invoke2(int num1, int num2) {
260: return num1 + num2;
261: }
262: }
263:
264: @WebService(name="SimpleServicePort")
265: interface SimpleService {
266: @WebMethod(operationName="invoke")
267: public String invoke(@WebParam(name="echoString")
268: List<String> arg1);
269:
270: public int invoke2(int arg1, int arg2);
271: }
272:
273: @WebService(serviceName="InheritanceTestChild")
274: class ChildClass extends ParentClass implements ServiceInterface,
275: CommonService {
276: public ChildClass() {
277: }
278:
279: public void doAbstract() {
280: }
281:
282: ;
283:
284: public void extraMethod() {
285: }
286:
287: ;
288: }
289:
290: @WebService(serviceName="InhertianceTestParent")
291: class ParentClass extends AbstractService implements
292: ParentServiceInterface {
293: public ParentClass() {
294: }
295:
296: public void doParentAbstract() {
297: }
298:
299: ;
300: }
301:
302: interface ServiceInterface {
303: public void doAbstract();
304: }
305:
306: interface CommonService {
307: public void extraMethod();
308: }
309:
310: interface ParentServiceInterface {
311: public void doParentAbstract();
312: }
313:
314: class AbstractService {
315: public void someAbstractMethod() {
316: }
317:
318: ;
319: }
|