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.description.AxisService;
023: import org.apache.axis2.description.Parameter;
024: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
025: import org.apache.axis2.jaxws.description.builder.MDQConstants;
026: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
027: import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
028: import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
029: import org.apache.axis2.jaxws.description.builder.WsdlComposite;
030: import org.apache.axis2.jaxws.description.builder.WsdlGenerator;
031:
032: import javax.jws.WebService;
033: import javax.wsdl.Definition;
034: import javax.xml.ws.WebServiceException;
035: import java.net.URL;
036: import java.util.HashMap;
037: import java.util.List;
038:
039: /**
040: *
041: */
042: public class PartialWSDLTests extends TestCase {
043:
044: /**
045: * Tests the binding, service, and port not specified in the WSDL.
046: * <p/>
047: * This test is based on the FVT test AddNumbersImplPartial1
048: */
049: public void testPartialWSDL1() {
050: String wsdlRelativeLocation = "test-resources/wsdl/";
051: String wsdlFileName = "PartialWSDL1.wsdl";
052:
053: String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
054: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
055:
056: // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
057: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
058:
059: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
060: Definition wsdlDefn = DescriptionTestUtils
061: .createWSDLDefinition(wsdlURL);
062: assertNotNull(wsdlDefn);
063:
064: WebServiceAnnot webServiceAnnot = WebServiceAnnot
065: .createWebServiceAnnotImpl();
066: assertNotNull(webServiceAnnot);
067: webServiceAnnot.setWsdlLocation(wsdlLocation);
068: webServiceAnnot.setTargetNamespace(targetNamespace);
069:
070: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
071: mdc.setMethodName("addTwoNumbers");
072: mdc.setReturnType("int");
073:
074: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
075: pdc1.setParameterType("int");
076: ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
077: pdc1.setParameterType("int");
078:
079: mdc.addParameterDescriptionComposite(pdc1);
080: mdc.addParameterDescriptionComposite(pdc2);
081:
082: dbc.addMethodDescriptionComposite(mdc);
083: dbc.setWebServiceAnnot(webServiceAnnot);
084: dbc.setClassName(AddNumbersImplPartial1.class.getName());
085: dbc.setWsdlDefinition(wsdlDefn);
086: dbc.setwsdlURL(wsdlURL);
087: dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
088:
089: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
090: dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
091:
092: List<ServiceDescription> serviceDescList = DescriptionFactory
093: .createServiceDescriptionFromDBCMap(dbcMap);
094: assertEquals(1, serviceDescList.size());
095: ServiceDescription sd = serviceDescList.get(0);
096: assertNotNull(sd);
097:
098: EndpointDescription[] edArray = sd.getEndpointDescriptions();
099: assertNotNull(edArray);
100: assertEquals(1, edArray.length);
101: EndpointDescription ed = edArray[0];
102: assertNotNull(ed);
103:
104: // Test for presence of generated WSDL
105: AxisService as = ed.getAxisService();
106: assertNotNull(as);
107: Parameter compositeParam = as
108: .getParameter(MDQConstants.WSDL_COMPOSITE);
109: assertNotNull(compositeParam);
110: assertNotNull(compositeParam.getValue());
111:
112: EndpointInterfaceDescription eid = ed
113: .getEndpointInterfaceDescription();
114: assertNotNull(eid);
115:
116: OperationDescription[] odArray = eid.getOperations();
117: assertNotNull(odArray);
118: assertEquals(1, odArray.length);
119: OperationDescription od = odArray[0];
120: }
121:
122: /**
123: * Tests the binding, service, and port not specified in the WSDL.
124: * <p/>
125: * This test is based on the FVT test AddNumbersImplPartial2
126: */
127: public void testPartialWSDL2() {
128: String wsdlRelativeLocation = "test-resources/wsdl/";
129: String wsdlFileName = "PartialWSDL2.wsdl";
130:
131: String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
132: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
133:
134: // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
135: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
136:
137: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
138: Definition wsdlDefn = DescriptionTestUtils
139: .createWSDLDefinition(wsdlURL);
140: assertNotNull(wsdlDefn);
141:
142: WebServiceAnnot webServiceAnnot = WebServiceAnnot
143: .createWebServiceAnnotImpl();
144: assertNotNull(webServiceAnnot);
145: webServiceAnnot.setWsdlLocation(wsdlLocation);
146: webServiceAnnot.setTargetNamespace(targetNamespace);
147:
148: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
149: mdc.setMethodName("addTwoNumbers");
150: mdc.setReturnType("int");
151:
152: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
153: pdc1.setParameterType("int");
154: ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
155: pdc1.setParameterType("int");
156:
157: mdc.addParameterDescriptionComposite(pdc1);
158: mdc.addParameterDescriptionComposite(pdc2);
159:
160: dbc.addMethodDescriptionComposite(mdc);
161: dbc.setWebServiceAnnot(webServiceAnnot);
162: dbc.setClassName(AddNumbersImplPartial1.class.getName());
163: dbc.setWsdlDefinition(wsdlDefn);
164: dbc.setwsdlURL(wsdlURL);
165: dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
166:
167: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
168: dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
169:
170: List<ServiceDescription> serviceDescList = DescriptionFactory
171: .createServiceDescriptionFromDBCMap(dbcMap);
172: assertEquals(1, serviceDescList.size());
173: ServiceDescription sd = serviceDescList.get(0);
174: assertNotNull(sd);
175:
176: EndpointDescription[] edArray = sd.getEndpointDescriptions();
177: assertNotNull(edArray);
178: assertEquals(1, edArray.length);
179: EndpointDescription ed = edArray[0];
180: assertNotNull(ed);
181:
182: // Test for presence of generated WSDL
183: AxisService as = ed.getAxisService();
184: assertNotNull(as);
185: Parameter compositeParam = as
186: .getParameter(MDQConstants.WSDL_COMPOSITE);
187: assertNotNull(compositeParam);
188: assertNotNull(compositeParam.getValue());
189:
190: EndpointInterfaceDescription eid = ed
191: .getEndpointInterfaceDescription();
192: assertNotNull(eid);
193:
194: OperationDescription[] odArray = eid.getOperations();
195: assertNotNull(odArray);
196: assertEquals(1, odArray.length);
197: OperationDescription od = odArray[0];
198: }
199: }
200:
201: @WebService(wsdlLocation="test-resources/wsdl/PartialWSDL2.wsdl",targetNamespace="http://serverPartial1.checkexception.webfault.annotations/")
202: class AddNumbersImplPartial1 {
203: public int addTwoNumbers(int number1, int number2) {
204: return number1 + number2;
205: }
206: }
207:
208: class WSDLGeneratorImpl implements WsdlGenerator {
209:
210: private Definition def;
211:
212: public WSDLGeneratorImpl(Definition def) {
213: this .def = def;
214: }
215:
216: public WsdlComposite generateWsdl(String implClass,
217: String bindingType) throws WebServiceException {
218: // Need WSDL generation code
219: WsdlComposite composite = new WsdlComposite();
220: composite.setWsdlFileName(implClass);
221: HashMap<String, Definition> testMap = new HashMap<String, Definition>();
222: testMap.put(composite.getWsdlFileName(), def);
223: composite.setWsdlDefinition(testMap);
224: return composite;
225: }
226:
227: }
|