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 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.WebServiceAnnot;
026:
027: import javax.jws.WebService;
028: import javax.wsdl.Definition;
029: import javax.xml.ws.WebServiceException;
030: import java.net.URL;
031: import java.util.HashMap;
032: import java.util.List;
033:
034: /** Tests validation against the WSDL for invalid configurations */
035: public class ValidateWSDLTests extends TestCase {
036:
037: /** The SEI used by the service impl does not contain all the methods defined on the PortType */
038: public void testValidatePortType() {
039: String wsdlRelativeLocation = System
040: .getProperty("basedir", ".")
041: + "/" + "test-resources/wsdl/";
042: String wsdlFileName = "ValidateWSDL1.wsdl";
043:
044: String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
045: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
046:
047: // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
048: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
049:
050: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
051: Definition wsdlDefn = DescriptionTestUtils
052: .createWSDLDefinition(wsdlURL);
053: assertNotNull(wsdlDefn);
054:
055: WebServiceAnnot webServiceAnnot = WebServiceAnnot
056: .createWebServiceAnnotImpl();
057: assertNotNull(webServiceAnnot);
058: webServiceAnnot.setWsdlLocation(wsdlLocation);
059: webServiceAnnot.setTargetNamespace(targetNamespace);
060:
061: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
062: mdc.setMethodName("addTwoNumbers");
063: mdc.setReturnType("int");
064:
065: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
066: pdc1.setParameterType("int");
067: ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
068: pdc1.setParameterType("int");
069:
070: mdc.addParameterDescriptionComposite(pdc1);
071: mdc.addParameterDescriptionComposite(pdc2);
072:
073: dbc.addMethodDescriptionComposite(mdc);
074: dbc.setWebServiceAnnot(webServiceAnnot);
075: dbc.setClassName(ValidateWSDLImpl1.class.getName());
076: dbc.setWsdlDefinition(wsdlDefn);
077: dbc.setwsdlURL(wsdlURL);
078:
079: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
080: dbcMap.put(ValidateWSDLImpl1.class.getName(), dbc);
081:
082: try {
083: List<ServiceDescription> serviceDescList = DescriptionFactory
084: .createServiceDescriptionFromDBCMap(dbcMap);
085: fail();
086: } catch (WebServiceException e) {
087: // Expected code path
088: }
089: }
090:
091: /**
092: * Reference a Port (which does not exist) under a Service that does. This is not a valid
093: * partial WSDL case and so is an error.
094: */
095: public void testValidatePort() {
096: String wsdlRelativeLocation = "test-resources/wsdl/";
097: String wsdlFileName = "ValidateWSDL1.wsdl";
098:
099: String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
100: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
101:
102: // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
103: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
104:
105: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
106: Definition wsdlDefn = DescriptionTestUtils
107: .createWSDLDefinition(wsdlURL);
108: assertNotNull(wsdlDefn);
109:
110: WebServiceAnnot webServiceAnnot = WebServiceAnnot
111: .createWebServiceAnnotImpl();
112: assertNotNull(webServiceAnnot);
113: webServiceAnnot.setWsdlLocation(wsdlLocation);
114: webServiceAnnot.setTargetNamespace(targetNamespace);
115: webServiceAnnot
116: .setServiceName("ValidateWSDLImpl1ServiceInvalidPort");
117:
118: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
119: mdc.setMethodName("addTwoNumbers");
120: mdc.setReturnType("int");
121:
122: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
123: pdc1.setParameterType("int");
124: ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
125: pdc1.setParameterType("int");
126:
127: mdc.addParameterDescriptionComposite(pdc1);
128: mdc.addParameterDescriptionComposite(pdc2);
129:
130: dbc.addMethodDescriptionComposite(mdc);
131: dbc.setWebServiceAnnot(webServiceAnnot);
132: dbc.setClassName(ValidateWSDLImpl2.class.getName());
133: dbc.setWsdlDefinition(wsdlDefn);
134: dbc.setwsdlURL(wsdlURL);
135:
136: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
137: dbcMap.put(ValidateWSDLImpl1.class.getName(), dbc);
138:
139: try {
140: List<ServiceDescription> serviceDescList = DescriptionFactory
141: .createServiceDescriptionFromDBCMap(dbcMap);
142: fail();
143: } catch (WebServiceException e) {
144: // Expected code path
145: }
146: }
147: }
148:
149: @WebService(wsdlLocation="test-resources/wsdl/ValidateWSDL2.wsdl",targetNamespace="http://serverPartial1.checkexception.webfault.annotations/")
150: class ValidateWSDLImpl1 {
151: public int addTwoNumbers(int number1, int number2) {
152: return number1 + number2;
153: }
154: }
155:
156: @WebService(serviceName="ValidateWSDLImpl1ServiceInvalidPort",wsdlLocation="test-resources/wsdl/ValidateWSDL2.wsdl",targetNamespace="http://serverPartial1.checkexception.webfault.annotations/")
157: class ValidateWSDLImpl2 {
158: public int addTwoNumbers(int number1, int number2) {
159: return number1 + number2;
160: }
161: }
|