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.impl;
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.WebServiceAnnot;
025:
026: import javax.xml.ws.WebServiceException;
027: import java.util.HashMap;
028:
029: /**
030: *
031: */
032: public class ServiceDescriptionImplValidationTests extends TestCase {
033:
034: public void testValidateImplMethodsVsSEI() {
035:
036: DescriptionBuilderComposite seiComposite = new DescriptionBuilderComposite();
037: seiComposite
038: .setClassName("org.apache.axis2.jaxws.description.impl.MySEI");
039: MethodDescriptionComposite seiMDC = new MethodDescriptionComposite();
040: seiMDC.setMethodName("seiMethod");
041: seiComposite.addMethodDescriptionComposite(seiMDC);
042:
043: DescriptionBuilderComposite implComposite = new DescriptionBuilderComposite();
044: implComposite
045: .setClassName("org.apache.axis2.jaxws.description.impl.MyImpl");
046: MethodDescriptionComposite implMDC = new MethodDescriptionComposite();
047: implMDC.setMethodName("notSeiMethod");
048: implComposite.addMethodDescriptionComposite(implMDC);
049: WebServiceAnnot webServiceAnnot = WebServiceAnnot
050: .createWebServiceAnnotImpl();
051: webServiceAnnot.setName(null);
052: webServiceAnnot
053: .setEndpointInterface("org.apache.axis2.jaxws.description.impl.MySEI");
054: implComposite.setWebServiceAnnot(webServiceAnnot);
055: implComposite.setIsInterface(false);
056:
057: HashMap<String, DescriptionBuilderComposite> dbcList = new HashMap<String, DescriptionBuilderComposite>();
058: dbcList.put(seiComposite.getClassName(), seiComposite);
059: dbcList.put(implComposite.getClassName(), implComposite);
060:
061: try {
062: ServiceDescriptionImpl serviceDescImpl = new ServiceDescriptionImpl(
063: dbcList, implComposite);
064: fail("Should have caught exception for validation errors");
065: } catch (WebServiceException ex) {
066: // Expected path
067: } catch (Exception ex) {
068: fail("Caught wrong type of exception " + ex.toString());
069: }
070:
071: }
072:
073: public void testValidateImplMethodsVsSEIInheritence() {
074:
075: DescriptionBuilderComposite super SeiComposite = new DescriptionBuilderComposite();
076: super SeiComposite
077: .setClassName("org.apache.axis2.jaxws.description.impl.MySuperSEI");
078: MethodDescriptionComposite super SeiMDC = new MethodDescriptionComposite();
079: super SeiMDC.setMethodName("superSeiMethod");
080: super SeiComposite.addMethodDescriptionComposite(super SeiMDC);
081:
082: DescriptionBuilderComposite seiComposite = new DescriptionBuilderComposite();
083: seiComposite
084: .setClassName("org.apache.axis2.jaxws.description.impl.MySEI");
085: MethodDescriptionComposite seiMDC = new MethodDescriptionComposite();
086: seiMDC.setMethodName("seiMethod");
087: seiComposite.addMethodDescriptionComposite(seiMDC);
088: seiComposite
089: .setSuperClassName("org.apache.axis2.jaxws.description.impl.MySuperSEI");
090:
091: DescriptionBuilderComposite implComposite = new DescriptionBuilderComposite();
092: implComposite
093: .setClassName("org.apache.axis2.jaxws.description.impl.MyImpl");
094: MethodDescriptionComposite implMDC = new MethodDescriptionComposite();
095: implMDC.setMethodName("superSeiMethod");
096: implComposite.addMethodDescriptionComposite(implMDC);
097: WebServiceAnnot webServiceAnnot = WebServiceAnnot
098: .createWebServiceAnnotImpl();
099: webServiceAnnot.setName(null);
100: webServiceAnnot
101: .setEndpointInterface("org.apache.axis2.jaxws.description.impl.MySEI");
102: implComposite.setWebServiceAnnot(webServiceAnnot);
103: implComposite.setIsInterface(false);
104:
105: HashMap<String, DescriptionBuilderComposite> dbcList = new HashMap<String, DescriptionBuilderComposite>();
106: dbcList.put(seiComposite.getClassName(), seiComposite);
107: dbcList
108: .put(super SeiComposite.getClassName(),
109: super SeiComposite);
110: dbcList.put(implComposite.getClassName(), implComposite);
111:
112: try {
113: ServiceDescriptionImpl serviceDescImpl = new ServiceDescriptionImpl(
114: dbcList, implComposite);
115: fail("Should have caught validation failure exception");
116: } catch (WebServiceException ex) {
117: // Expected path
118: } catch (Exception ex) {
119: fail("Caught wrong exception " + ex.toString());
120: }
121: }
122:
123: // The tests below progressively setup an identical DBC, gradually setting more values until
124: // the last one does not cause a validation error.
125:
126: // FAILURE #1: No WebMethod annotation set on the SEI
127: public void testInvalidDBC1() {
128: DescriptionBuilderComposite seiComposite = new DescriptionBuilderComposite();
129: seiComposite
130: .setClassName("org.apache.axis2.jaxws.description.impl.MySEI");
131: MethodDescriptionComposite seiMDC = new MethodDescriptionComposite();
132: seiMDC.setMethodName("seiMethod");
133: seiComposite.addMethodDescriptionComposite(seiMDC);
134:
135: DescriptionBuilderComposite super ImplComposite = new DescriptionBuilderComposite();
136: super ImplComposite
137: .setClassName("org.apache.axis2.jaxws.description.impl.MySuperImpl");
138: MethodDescriptionComposite super ImplMDC = new MethodDescriptionComposite();
139: super ImplMDC.setMethodName("seiMethod");
140: super ImplComposite.addMethodDescriptionComposite(super ImplMDC);
141:
142: DescriptionBuilderComposite implComposite = new DescriptionBuilderComposite();
143: implComposite
144: .setClassName("org.apache.axis2.jaxws.description.impl.MyImpl");
145: MethodDescriptionComposite implMDC = new MethodDescriptionComposite();
146: implMDC.setMethodName("notSeiMethod");
147: implComposite.addMethodDescriptionComposite(implMDC);
148: WebServiceAnnot webServiceAnnot = WebServiceAnnot
149: .createWebServiceAnnotImpl();
150: webServiceAnnot.setName(null);
151: webServiceAnnot
152: .setEndpointInterface("org.apache.axis2.jaxws.description.impl.MySEI");
153: implComposite.setWebServiceAnnot(webServiceAnnot);
154: implComposite.setIsInterface(false);
155: implComposite
156: .setSuperClassName("org.apache.axis2.jaxws.description.impl.MySuperImpl");
157:
158: HashMap<String, DescriptionBuilderComposite> dbcList = new HashMap<String, DescriptionBuilderComposite>();
159: dbcList.put(seiComposite.getClassName(), seiComposite);
160: dbcList.put(implComposite.getClassName(), implComposite);
161: dbcList.put(super ImplComposite.getClassName(),
162: super ImplComposite);
163:
164: try {
165: ServiceDescriptionImpl serviceDescImpl = new ServiceDescriptionImpl(
166: dbcList, implComposite);
167: fail("Did not catch expected exception");
168: } catch (WebServiceException ex) {
169: // Expected path
170: } catch (Exception ex) {
171: fail("Unexpected exception received " + ex.toString());
172: }
173: }
174: }
|