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;
020:
021: import java.util.HashMap;
022: import java.util.List;
023:
024: import javax.jws.WebService;
025:
026: import org.apache.axis2.jaxws.ExceptionFactory;
027: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
028: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
029: import org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter;
030:
031: import junit.framework.TestCase;
032:
033: /**
034: *
035: */
036: public class ValidateServiceImplTests extends TestCase {
037:
038: public void testValidServiceImpl() {
039: try {
040: Class serviceImplClass = ServiceImpl.class;
041: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
042: serviceImplClass);
043: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
044: .produceDBC();
045: List<ServiceDescription> serviceDescList = DescriptionFactory
046: .createServiceDescriptionFromDBCMap(dbcMap);
047: assertNotNull(serviceDescList);
048: assertEquals(1, serviceDescList.size());
049: } catch (Exception e) {
050: e.printStackTrace();
051: fail("Caught unexpected exception" + e);
052: }
053: }
054:
055: public void testMissingMethods() {
056: try {
057: Class serviceImplClass = MissingMethodsImpl.class;
058: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
059: serviceImplClass);
060: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
061: .produceDBC();
062: List<ServiceDescription> serviceDescList = DescriptionFactory
063: .createServiceDescriptionFromDBCMap(dbcMap);
064: fail("Should have caused exception");
065: } catch (Exception e) {
066: // Expected path
067: }
068: }
069:
070: public void testInvalidThrows() {
071: try {
072: Class serviceImplClass = InvalidThrowsImpl.class;
073: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
074: serviceImplClass);
075: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
076: .produceDBC();
077: List<ServiceDescription> serviceDescList = DescriptionFactory
078: .createServiceDescriptionFromDBCMap(dbcMap);
079: fail("Should have caused exception");
080: } catch (Exception e) {
081: // Expected path
082: }
083: }
084:
085: public void testMismatchedReturnTypesDBC() {
086: try {
087: Class serviceImplClass = ServiceImpl.class;
088: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
089: serviceImplClass);
090: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
091: .produceDBC();
092: // Set the return types for one of the methods on the impl class to mismatch the SEI
093: DescriptionBuilderComposite implDBC = dbcMap
094: .get("org.apache.axis2.jaxws.description.ServiceImpl");
095: assertNotNull(implDBC);
096: List<MethodDescriptionComposite> m1MDCList = implDBC
097: .getMethodDescriptionComposite("method1");
098: assertNotNull(m1MDCList);
099: assertEquals(1, m1MDCList.size());
100: MethodDescriptionComposite m1MDC = m1MDCList.get(0);
101: assertEquals("java.lang.String", m1MDC.getReturnType());
102: m1MDC.setReturnType("lava.lang.Integer");
103:
104: List<ServiceDescription> serviceDescList = DescriptionFactory
105: .createServiceDescriptionFromDBCMap(dbcMap);
106: fail("Should have caused exception");
107: } catch (Exception e) {
108: // Expected path
109: }
110: }
111:
112: public void testMismatchedReturnTypes() {
113: try {
114: Class serviceImplClass = MismatchedReturnTypesImpl.class;
115: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
116: serviceImplClass);
117: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
118: .produceDBC();
119: List<ServiceDescription> serviceDescList = DescriptionFactory
120: .createServiceDescriptionFromDBCMap(dbcMap);
121: fail("Should have caused exception");
122: } catch (Exception e) {
123: // Expected path
124: }
125: }
126:
127: public void testMismatchedParameterNumber() {
128: try {
129: Class serviceImplClass = MismatchedParameterNumberImpl.class;
130: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
131: serviceImplClass);
132: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
133: .produceDBC();
134: List<ServiceDescription> serviceDescList = DescriptionFactory
135: .createServiceDescriptionFromDBCMap(dbcMap);
136: fail("Should have caused exception");
137: } catch (Exception e) {
138: // Expected path
139: }
140: }
141:
142: public void testMismatchedParameterTypes() {
143: try {
144: Class serviceImplClass = MismatchedParameterTypesImpl.class;
145: JavaClassToDBCConverter converter = new JavaClassToDBCConverter(
146: serviceImplClass);
147: HashMap<String, DescriptionBuilderComposite> dbcMap = converter
148: .produceDBC();
149: List<ServiceDescription> serviceDescList = DescriptionFactory
150: .createServiceDescriptionFromDBCMap(dbcMap);
151: fail("Should have caused exception");
152: } catch (Exception e) {
153: // Expected path
154: }
155: }
156:
157: }
158:
159: @WebService
160: interface EndpointInterface {
161: public String method1(int param1, int param2) throws MyException;
162:
163: public void method2(String param1) throws MyException;
164:
165: public int method3();
166: }
167:
168: class MyException extends Exception {
169:
170: }
171:
172: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
173: class ServiceImpl {
174: public String method1(int param1, int param2) throws MyException {
175: return null;
176: }
177:
178: // Intentionally doesn't throw MyException. It is valid for a service impl to throw
179: // fewer exceptions than the endpoint interface
180: public void method2(String param1) {
181:
182: }
183:
184: public int method3() {
185: return 0;
186: }
187: }
188:
189: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
190: class MissingMethodsImpl {
191: public String method1(int param1, int param2) {
192: return null;
193: }
194:
195: // public void method2(String param1) {
196: //
197: // }
198:
199: public int method3() {
200: return 0;
201: }
202: }
203:
204: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
205: class InvalidThrowsImpl {
206: public String method1(int param1, int param2) throws MyException {
207: return null;
208: }
209:
210: // Intentionally doesn't throw MyException. It is valid for a service impl to throw
211: // fewer exceptions than the endpoint interface
212: public void method2(String param1) {
213:
214: }
215:
216: // It is invalid to throw more exceptions than the endpoint interface
217: public int method3() throws MyException {
218: return 0;
219: }
220: }
221:
222: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
223: class MismatchedReturnTypesImpl {
224: // Return type doesn't match SEI
225: public Integer method1(int param1, int param2) throws MyException {
226: return null;
227: }
228:
229: public void method2(String param1) {
230:
231: }
232:
233: public int method3() {
234: return 0;
235: }
236: }
237:
238: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
239: class MismatchedParameterNumberImpl {
240: public String method1(int param1) throws MyException {
241: return null;
242: }
243:
244: public void method2(String param1) {
245:
246: }
247:
248: public int method3() {
249: return 0;
250: }
251: }
252:
253: @WebService(endpointInterface="org.apache.axis2.jaxws.description.EndpointInterface")
254: class MismatchedParameterTypesImpl {
255: public String method1(int param1, String param2) throws MyException {
256: return null;
257: }
258:
259: // Intentionally doesn't throw MyException. It is valid for a service impl to throw
260: // fewer exceptions than the endpoint interface
261: public void method2(String param1) {
262:
263: }
264:
265: public int method3() {
266: return 0;
267: }
268: }
|