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: */package org.apache.cxf.wsdl11;
019:
020: import java.io.File;
021: import java.io.FileOutputStream;
022: import java.net.URI;
023: import java.net.URL;
024: import java.net.URLDecoder;
025: import java.net.URLEncoder;
026: import java.util.Collection;
027: import java.util.List;
028: import java.util.logging.Logger;
029:
030: import javax.wsdl.Definition;
031: import javax.wsdl.Service;
032: import javax.wsdl.extensions.UnknownExtensibilityElement;
033: import javax.wsdl.factory.WSDLFactory;
034: import javax.wsdl.xml.WSDLReader;
035: import javax.xml.namespace.QName;
036: import javax.xml.parsers.DocumentBuilder;
037: import javax.xml.parsers.DocumentBuilderFactory;
038: import javax.xml.validation.Schema;
039:
040: import org.w3c.dom.Document;
041: import org.w3c.dom.Element;
042:
043: import org.apache.cxf.Bus;
044: import org.apache.cxf.binding.BindingFactoryManager;
045: import org.apache.cxf.helpers.CastUtils;
046: import org.apache.cxf.helpers.XMLUtils;
047: import org.apache.cxf.service.model.BindingFaultInfo;
048: import org.apache.cxf.service.model.BindingInfo;
049: import org.apache.cxf.service.model.BindingMessageInfo;
050: import org.apache.cxf.service.model.BindingOperationInfo;
051: import org.apache.cxf.service.model.EndpointInfo;
052: import org.apache.cxf.service.model.FaultInfo;
053: import org.apache.cxf.service.model.InterfaceInfo;
054: import org.apache.cxf.service.model.MessageInfo;
055: import org.apache.cxf.service.model.MessagePartInfo;
056: import org.apache.cxf.service.model.OperationInfo;
057: import org.apache.cxf.service.model.SchemaInfo;
058: import org.apache.cxf.service.model.ServiceInfo;
059: import org.apache.cxf.transport.DestinationFactory;
060: import org.apache.cxf.transport.DestinationFactoryManager;
061: import org.apache.cxf.wsdl.EndpointReferenceUtils;
062: import org.apache.ws.commons.schema.XmlSchemaCollection;
063: import org.apache.ws.commons.schema.XmlSchemaElement;
064: import org.easymock.classextension.EasyMock;
065: import org.easymock.classextension.IMocksControl;
066: import org.junit.Assert;
067: import org.junit.Before;
068: import org.junit.Test;
069:
070: public class WSDLServiceBuilderTest extends Assert {
071: // TODO: reuse the wsdl in testutils and add the parameter order into one of the wsdl
072: private static final Logger LOG = Logger
073: .getLogger(WSDLServiceBuilderTest.class.getName());
074: private static final String WSDL_PATH = "hello_world.wsdl";
075: private static final String BARE_WSDL_PATH = "hello_world_bare.wsdl";
076: private static final String IMPORT_WSDL_PATH = "hello_world_schema_import.wsdl";
077: private static final String MULTIPORT_WSDL_PATH = "hello_world_multiporttype.wsdl";
078:
079: private static final String EXTENSION_NAMESPACE = "http://cxf.apache.org/extension/ns";
080: private static final QName EXTENSION_ATTR_BOOLEAN = new QName(
081: EXTENSION_NAMESPACE, "booleanAttr");
082: private static final QName EXTENSION_ATTR_STRING = new QName(
083: EXTENSION_NAMESPACE, "stringAttr");
084: private static final QName EXTENSION_ELEM = new QName(
085: EXTENSION_NAMESPACE, "stringElem");
086:
087: private Definition def;
088:
089: private Service service;
090:
091: private ServiceInfo serviceInfo;
092: private List<ServiceInfo> serviceInfos;
093:
094: private IMocksControl control;
095:
096: private Bus bus;
097:
098: private BindingFactoryManager bindingFactoryManager;
099:
100: private DestinationFactoryManager destinationFactoryManager;
101:
102: @Before
103: public void setUp() throws Exception {
104: setUpWSDL(WSDL_PATH, 0);
105: }
106:
107: private void setUpWSDL(String wsdl, int serviceSeq)
108: throws Exception {
109: URL url = getClass().getResource(wsdl);
110: assertNotNull("could not find wsdl " + wsdl, url);
111: String wsdlUrl = url.toString();
112: LOG.info("the path of wsdl file is " + wsdlUrl);
113: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
114: WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
115: wsdlReader.setFeature("javax.wsdl.verbose", false);
116:
117: def = wsdlReader.readWSDL(new WSDLLocatorImpl(wsdlUrl));
118:
119: int seq = 0;
120: for (Service serv : CastUtils.cast(def.getServices().values(),
121: Service.class)) {
122: if (serv != null) {
123: service = serv;
124: if (seq == serviceSeq) {
125: break;
126: } else {
127: seq++;
128: }
129: }
130: }
131:
132: control = EasyMock.createNiceControl();
133: bus = control.createMock(Bus.class);
134: bindingFactoryManager = control
135: .createMock(BindingFactoryManager.class);
136: destinationFactoryManager = control
137: .createMock(DestinationFactoryManager.class);
138: DestinationFactory destinationFactory = control
139: .createMock(DestinationFactory.class);
140:
141: WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(
142: bus);
143:
144: EasyMock.expect(bus.getExtension(BindingFactoryManager.class))
145: .andReturn(bindingFactoryManager).anyTimes();
146:
147: EasyMock.expect(
148: bus.getExtension(DestinationFactoryManager.class))
149: .andReturn(destinationFactoryManager).atLeastOnce();
150:
151: EasyMock
152: .expect(
153: destinationFactoryManager
154: .getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/"))
155: .andReturn(destinationFactory).anyTimes();
156:
157: control.replay();
158: serviceInfos = wsdlServiceBuilder.buildServices(def, service);
159: serviceInfo = serviceInfos.get(0);
160:
161: }
162:
163: @Test
164: public void testMultiPorttype() throws Exception {
165: setUpWSDL(MULTIPORT_WSDL_PATH, 0);
166: assertEquals(2, serviceInfos.size());
167: control.verify();
168: }
169:
170: @Test
171: public void testServiceInfo() throws Exception {
172: assertEquals("SOAPService", serviceInfo.getName()
173: .getLocalPart());
174: assertEquals("http://apache.org/hello_world_soap_http",
175: serviceInfo.getName().getNamespaceURI());
176: assertEquals("http://apache.org/hello_world_soap_http",
177: serviceInfo.getTargetNamespace());
178: assertTrue(serviceInfo
179: .getProperty(WSDLServiceBuilder.WSDL_DEFINITION) == def);
180: assertTrue(serviceInfo
181: .getProperty(WSDLServiceBuilder.WSDL_SERVICE) == service);
182:
183: assertEquals("Incorrect number of endpoints", serviceInfo
184: .getEndpoints().size(), 1);
185: EndpointInfo ei = serviceInfo.getEndpoint(new QName(
186: "http://apache.org/hello_world_soap_http", "SoapPort"));
187: assertNotNull(ei);
188: assertEquals("http://schemas.xmlsoap.org/wsdl/soap/", ei
189: .getTransportId());
190: assertNotNull(ei.getBinding());
191: control.verify();
192: }
193:
194: @Test
195: public void testInterfaceInfo() throws Exception {
196: assertEquals("Greeter", serviceInfo.getInterface().getName()
197: .getLocalPart());
198: control.verify();
199: }
200:
201: @Test
202: public void testOperationInfo() throws Exception {
203: QName name = new QName(serviceInfo.getName().getNamespaceURI(),
204: "sayHi");
205: assertEquals(serviceInfo.getInterface().getOperations().size(),
206: 4);
207: OperationInfo sayHi = serviceInfo.getInterface().getOperation(
208: new QName(serviceInfo.getName().getNamespaceURI(),
209: "sayHi"));
210: assertNotNull(sayHi);
211: assertEquals(sayHi.getName(), name);
212: assertFalse(sayHi.isOneWay());
213: assertTrue(sayHi.hasInput());
214: assertTrue(sayHi.hasOutput());
215:
216: assertNull(sayHi.getParameterOrdering());
217:
218: name = new QName(serviceInfo.getName().getNamespaceURI(),
219: "greetMe");
220: OperationInfo greetMe = serviceInfo.getInterface()
221: .getOperation(name);
222: assertNotNull(greetMe);
223: assertEquals(greetMe.getName(), name);
224: assertFalse(greetMe.isOneWay());
225: assertTrue(greetMe.hasInput());
226: assertTrue(greetMe.hasOutput());
227:
228: List<MessagePartInfo> inParts = greetMe.getInput()
229: .getMessageParts();
230: assertEquals(1, inParts.size());
231: MessagePartInfo part = inParts.get(0);
232: assertNotNull(part.getXmlSchema());
233: assertTrue(part.getXmlSchema() instanceof XmlSchemaElement);
234:
235: List<MessagePartInfo> outParts = greetMe.getOutput()
236: .getMessageParts();
237: assertEquals(1, outParts.size());
238: part = outParts.get(0);
239: assertNotNull(part.getXmlSchema());
240: assertTrue(part.getXmlSchema() instanceof XmlSchemaElement);
241:
242: assertTrue("greatMe should be wrapped", greetMe
243: .isUnwrappedCapable());
244: OperationInfo greetMeUnwrapped = greetMe
245: .getUnwrappedOperation();
246:
247: assertNotNull(greetMeUnwrapped.getInput());
248: assertNotNull(greetMeUnwrapped.getOutput());
249: assertEquals("wrapped part not set", 1, greetMeUnwrapped
250: .getInput().size());
251: assertEquals("wrapped part not set", 1, greetMeUnwrapped
252: .getOutput().size());
253: assertEquals("wrapper part name wrong", "requestType",
254: greetMeUnwrapped.getInput().getMessagePartByIndex(0)
255: .getName().getLocalPart());
256: assertEquals("wrapper part type name wrong", "MyStringType",
257: greetMeUnwrapped.getInput().getMessagePartByIndex(0)
258: .getTypeQName().getLocalPart());
259:
260: assertEquals("wrapper part name wrong", "responseType",
261: greetMeUnwrapped.getOutput().getMessagePartByIndex(0)
262: .getName().getLocalPart());
263: assertEquals("wrapper part type name wrong", "string",
264: greetMeUnwrapped.getOutput().getMessagePartByIndex(0)
265: .getTypeQName().getLocalPart());
266:
267: name = new QName(serviceInfo.getName().getNamespaceURI(),
268: "greetMeOneWay");
269: OperationInfo greetMeOneWay = serviceInfo.getInterface()
270: .getOperation(name);
271: assertNotNull(greetMeOneWay);
272: assertEquals(greetMeOneWay.getName(), name);
273: assertTrue(greetMeOneWay.isOneWay());
274: assertTrue(greetMeOneWay.hasInput());
275: assertFalse(greetMeOneWay.hasOutput());
276:
277: OperationInfo greetMeOneWayUnwrapped = greetMeOneWay
278: .getUnwrappedOperation();
279: assertNotNull(greetMeOneWayUnwrapped);
280: assertNotNull(greetMeOneWayUnwrapped.getInput());
281: assertNull(greetMeOneWayUnwrapped.getOutput());
282: assertEquals("wrapped part not set", 1, greetMeOneWayUnwrapped
283: .getInput().size());
284: assertEquals(new QName(
285: "http://apache.org/hello_world_soap_http/types",
286: "requestType"), greetMeOneWayUnwrapped.getInput()
287: .getMessagePartByIndex(0).getConcreteName());
288:
289: name = new QName(serviceInfo.getName().getNamespaceURI(),
290: "pingMe");
291: OperationInfo pingMe = serviceInfo.getInterface().getOperation(
292: name);
293: assertNotNull(pingMe);
294: assertEquals(pingMe.getName(), name);
295: assertFalse(pingMe.isOneWay());
296: assertTrue(pingMe.hasInput());
297: assertTrue(pingMe.hasOutput());
298:
299: assertNull(serviceInfo.getInterface().getOperation(
300: new QName("what ever")));
301: control.verify();
302: }
303:
304: @Test
305: public void testBindingInfo() throws Exception {
306: BindingInfo bindingInfo = null;
307: assertEquals(1, serviceInfo.getBindings().size());
308: bindingInfo = serviceInfo.getBindings().iterator().next();
309: assertNotNull(bindingInfo);
310: assertEquals(bindingInfo.getInterface().getName()
311: .getLocalPart(), "Greeter");
312: assertEquals(bindingInfo.getName().getLocalPart(),
313: "Greeter_SOAPBinding");
314: assertEquals(bindingInfo.getName().getNamespaceURI(),
315: "http://apache.org/hello_world_soap_http");
316: control.verify();
317: }
318:
319: @Test
320: public void testBindingOperationInfo() throws Exception {
321: BindingInfo bindingInfo = null;
322: bindingInfo = serviceInfo.getBindings().iterator().next();
323: Collection<BindingOperationInfo> bindingOperationInfos = bindingInfo
324: .getOperations();
325: assertNotNull(bindingOperationInfos);
326: assertEquals(bindingOperationInfos.size(), 4);
327: LOG.info("the binding operation is "
328: + bindingOperationInfos.iterator().next().getName());
329:
330: QName name = new QName(serviceInfo.getName().getNamespaceURI(),
331: "sayHi");
332: BindingOperationInfo sayHi = bindingInfo.getOperation(name);
333: assertNotNull(sayHi);
334: assertEquals(sayHi.getName(), name);
335:
336: name = new QName(serviceInfo.getName().getNamespaceURI(),
337: "greetMe");
338: BindingOperationInfo greetMe = bindingInfo.getOperation(name);
339: assertNotNull(greetMe);
340: assertEquals(greetMe.getName(), name);
341:
342: name = new QName(serviceInfo.getName().getNamespaceURI(),
343: "greetMeOneWay");
344: BindingOperationInfo greetMeOneWay = bindingInfo
345: .getOperation(name);
346: assertNotNull(greetMeOneWay);
347: assertEquals(greetMeOneWay.getName(), name);
348:
349: name = new QName(serviceInfo.getName().getNamespaceURI(),
350: "pingMe");
351: BindingOperationInfo pingMe = bindingInfo.getOperation(name);
352: assertNotNull(pingMe);
353: assertEquals(pingMe.getName(), name);
354: control.verify();
355: }
356:
357: @Test
358: public void testBindingMessageInfo() throws Exception {
359: BindingInfo bindingInfo = null;
360: bindingInfo = serviceInfo.getBindings().iterator().next();
361:
362: QName name = new QName(serviceInfo.getName().getNamespaceURI(),
363: "sayHi");
364: BindingOperationInfo sayHi = bindingInfo.getOperation(name);
365: BindingMessageInfo input = sayHi.getInput();
366: assertNotNull(input);
367: assertEquals(input.getMessageInfo().getName().getLocalPart(),
368: "sayHiRequest");
369: assertEquals(
370: input.getMessageInfo().getName().getNamespaceURI(),
371: "http://apache.org/hello_world_soap_http");
372: assertEquals(input.getMessageInfo().getMessageParts().size(), 1);
373: assertEquals(input.getMessageInfo().getMessageParts().get(0)
374: .getName().getLocalPart(), "in");
375: assertEquals(input.getMessageInfo().getMessageParts().get(0)
376: .getName().getNamespaceURI(),
377: "http://apache.org/hello_world_soap_http");
378: assertTrue(input.getMessageInfo().getMessageParts().get(0)
379: .isElement());
380: QName elementName = input.getMessageInfo().getMessageParts()
381: .get(0).getElementQName();
382: assertEquals(elementName.getLocalPart(), "sayHi");
383: assertEquals(elementName.getNamespaceURI(),
384: "http://apache.org/hello_world_soap_http/types");
385:
386: BindingMessageInfo output = sayHi.getOutput();
387: assertNotNull(output);
388: assertEquals(output.getMessageInfo().getName().getLocalPart(),
389: "sayHiResponse");
390: assertEquals(output.getMessageInfo().getName()
391: .getNamespaceURI(),
392: "http://apache.org/hello_world_soap_http");
393: assertEquals(output.getMessageInfo().getMessageParts().size(),
394: 1);
395: assertEquals(output.getMessageInfo().getMessageParts().get(0)
396: .getName().getLocalPart(), "out");
397: assertEquals(output.getMessageInfo().getMessageParts().get(0)
398: .getName().getNamespaceURI(),
399: "http://apache.org/hello_world_soap_http");
400: assertTrue(output.getMessageInfo().getMessageParts().get(0)
401: .isElement());
402: elementName = output.getMessageInfo().getMessageParts().get(0)
403: .getElementQName();
404: assertEquals(elementName.getLocalPart(), "sayHiResponse");
405: assertEquals(elementName.getNamespaceURI(),
406: "http://apache.org/hello_world_soap_http/types");
407:
408: assertTrue(sayHi.getFaults().size() == 0);
409:
410: name = new QName(serviceInfo.getName().getNamespaceURI(),
411: "pingMe");
412: BindingOperationInfo pingMe = bindingInfo.getOperation(name);
413: assertNotNull(pingMe);
414: assertEquals(1, pingMe.getFaults().size());
415: BindingFaultInfo fault = pingMe.getFaults().iterator().next();
416:
417: assertNotNull(fault);
418: assertEquals(fault.getFaultInfo().getName().getLocalPart(),
419: "pingMeFault");
420: assertEquals(fault.getFaultInfo().getName().getNamespaceURI(),
421: "http://apache.org/hello_world_soap_http");
422: assertEquals(fault.getFaultInfo().getMessageParts().size(), 1);
423: assertEquals(fault.getFaultInfo().getMessageParts().get(0)
424: .getName().getLocalPart(), "faultDetail");
425: assertEquals(fault.getFaultInfo().getMessageParts().get(0)
426: .getName().getNamespaceURI(),
427: "http://apache.org/hello_world_soap_http");
428: assertTrue(fault.getFaultInfo().getMessageParts().get(0)
429: .isElement());
430: elementName = fault.getFaultInfo().getMessageParts().get(0)
431: .getElementQName();
432: assertEquals(elementName.getLocalPart(), "faultDetail");
433: assertEquals(elementName.getNamespaceURI(),
434: "http://apache.org/hello_world_soap_http/types");
435: control.verify();
436: }
437:
438: @Test
439: public void testSchema() {
440: XmlSchemaCollection schemas = serviceInfo.getProperty(
441: WSDLServiceBuilder.WSDL_SCHEMA_LIST,
442: XmlSchemaCollection.class);
443: assertNotNull(schemas);
444: assertEquals(serviceInfo.getSchemas().size(), 1);
445: SchemaInfo schemaInfo = serviceInfo.getSchemas().iterator()
446: .next();
447: assertNotNull(schemaInfo);
448: assertEquals(schemaInfo.getNamespaceURI(),
449: "http://apache.org/hello_world_soap_http/types");
450: assertEquals(schemas.read(schemaInfo.getElement())
451: .getTargetNamespace(),
452: "http://apache.org/hello_world_soap_http/types");
453: // add below code to test the creation of javax.xml.validation.Schema
454: // with schema in serviceInfo
455: Schema schema = EndpointReferenceUtils.getSchema(serviceInfo);
456: assertNotNull(schema);
457: control.verify();
458: }
459:
460: @Test
461: public void testBare() throws Exception {
462: setUpWSDL(BARE_WSDL_PATH, 0);
463: BindingInfo bindingInfo = null;
464: bindingInfo = serviceInfo.getBindings().iterator().next();
465: Collection<BindingOperationInfo> bindingOperationInfos = bindingInfo
466: .getOperations();
467: assertNotNull(bindingOperationInfos);
468: assertEquals(bindingOperationInfos.size(), 1);
469: LOG.info("the binding operation is "
470: + bindingOperationInfos.iterator().next().getName());
471: QName name = new QName(serviceInfo.getName().getNamespaceURI(),
472: "greetMe");
473: BindingOperationInfo greetMe = bindingInfo.getOperation(name);
474: assertNotNull(greetMe);
475: assertEquals("greetMe OperationInfo name error", greetMe
476: .getName(), name);
477: assertFalse("greetMe should be a Unwrapped operation ", greetMe
478: .isUnwrappedCapable());
479:
480: assertNotNull(serviceInfo.getXmlSchemaCollection());
481: control.verify();
482: }
483:
484: @Test
485: public void testImport() throws Exception {
486: // rewrite the schema1.xsd to import schema2.xsd with absolute path.
487: DocumentBuilder db = DocumentBuilderFactory.newInstance()
488: .newDocumentBuilder();
489: Document doc = db.parse(this .getClass().getResourceAsStream(
490: "./s1/s2/schema2.xsd"));
491: Element schemaImport = null;
492: for (int i = 0; i < doc.getChildNodes().getLength(); i++) {
493: if (doc.getChildNodes().item(i) instanceof Element) {
494: Element schema = (Element) doc.getChildNodes().item(i);
495: for (int j = 0; j < schema.getChildNodes().getLength(); j++) {
496: if (schema.getChildNodes().item(j) instanceof Element) {
497: schemaImport = (Element) schema.getChildNodes()
498: .item(j);
499: break;
500: }
501: }
502: break;
503: }
504: }
505: if (schemaImport == null) {
506: fail("Can't find import element");
507: }
508: String filePath = this .getClass().getResource(
509: "./s1/s2/s4/schema4.xsd").toURI().getPath();
510: String importPath = schemaImport.getAttributeNode(
511: "schemaLocation").getValue();
512: if (!new URI(URLEncoder.encode(importPath, "utf-8"))
513: .isAbsolute()) {
514: schemaImport.getAttributeNode("schemaLocation")
515: .setNodeValue("file:" + filePath);
516: String fileStr = this .getClass().getResource(
517: "./s1/s2/schema2.xsd").toURI().getPath();
518: fileStr = URLDecoder.decode(fileStr, "utf-8");
519: File file = new File(fileStr);
520: if (file.exists()) {
521: file.delete();
522: }
523: FileOutputStream fout = new FileOutputStream(file);
524: XMLUtils.writeTo(doc, fout);
525: fout.flush();
526: fout.close();
527: }
528: setUpWSDL(IMPORT_WSDL_PATH, 0);
529: assertNotNull(serviceInfo.getSchemas());
530: Element ele = serviceInfo.getSchemas().iterator().next()
531: .getElement();
532: assertNotNull(ele);
533: Schema schema = EndpointReferenceUtils.getSchema(serviceInfo);
534: assertNotNull(schema);
535: control.verify();
536: }
537:
538: @Test
539: public void testDiffPortTypeNsImport() throws Exception {
540: setUpWSDL("/DiffPortTypeNs.wsdl", 0);
541: doDiffPortTypeNsImport();
542: setUpWSDL("/DiffPortTypeNs.wsdl", 1);
543: doDiffPortTypeNsImport();
544: control.verify();
545: }
546:
547: private void doDiffPortTypeNsImport() {
548: if (serviceInfo.getName().getLocalPart().endsWith("Rpc")) {
549: String ns = serviceInfo.getInterface().getName()
550: .getNamespaceURI();
551: OperationInfo oi = serviceInfo.getInterface().getOperation(
552: new QName(ns, "NewOperationRpc"));
553: assertNotNull(oi);
554: ns = oi.getInput().getName().getNamespaceURI();
555: MessagePartInfo mpi = oi.getInput().getMessagePart(
556: new QName(ns, "NewOperationRequestRpc"));
557: assertNotNull(mpi);
558: } else {
559: String ns = serviceInfo.getInterface().getName()
560: .getNamespaceURI();
561: OperationInfo oi = serviceInfo.getInterface().getOperation(
562: new QName(ns, "NewOperation"));
563: assertNotNull(oi);
564: ns = oi.getInput().getName().getNamespaceURI();
565: MessagePartInfo mpi = oi.getInput().getMessagePart(
566: new QName(ns, "NewOperationRequest"));
567: assertNotNull(mpi);
568: }
569: }
570:
571: @Test
572: public void testParameterOrder() throws Exception {
573: String ns = "http://apache.org/hello_world_xml_http/bare";
574: setUpWSDL("hello_world_xml_bare.wsdl", 0);
575:
576: OperationInfo operation = serviceInfo.getInterface()
577: .getOperation(new QName(ns, "testTriPart"));
578: assertNotNull(operation);
579: List<MessagePartInfo> parts = operation.getInput()
580: .getMessageParts();
581: assertNotNull(parts);
582: assertEquals(3, parts.size());
583: assertEquals("in3", parts.get(0).getName().getLocalPart());
584: assertEquals("in1", parts.get(1).getName().getLocalPart());
585: assertEquals("in2", parts.get(2).getName().getLocalPart());
586:
587: List<String> order = operation.getParameterOrdering();
588: assertNotNull(order);
589: assertEquals(3, order.size());
590: assertEquals("in1", order.get(0));
591: assertEquals("in3", order.get(1));
592: assertEquals("in2", order.get(2));
593:
594: parts = operation.getInput().getOrderedParts(order);
595: assertNotNull(parts);
596: assertEquals(3, parts.size());
597: assertEquals("in1", parts.get(0).getName().getLocalPart());
598: assertEquals("in3", parts.get(1).getName().getLocalPart());
599: assertEquals("in2", parts.get(2).getName().getLocalPart());
600:
601: operation = serviceInfo.getInterface().getOperation(
602: new QName(ns, "testTriPartNoOrder"));
603: assertNotNull(operation);
604: parts = operation.getInput().getMessageParts();
605: assertNotNull(parts);
606: assertEquals(3, parts.size());
607: assertEquals("in3", parts.get(0).getName().getLocalPart());
608: assertEquals("in1", parts.get(1).getName().getLocalPart());
609: assertEquals("in2", parts.get(2).getName().getLocalPart());
610: control.verify();
611: }
612:
613: @Test
614: public void testParameterOrder2() throws Exception {
615: setUpWSDL("header2.wsdl", 0);
616: String ns = "http://apache.org/header2";
617: OperationInfo operation = serviceInfo.getInterface()
618: .getOperation(new QName(ns, "headerMethod"));
619: assertNotNull(operation);
620: List<MessagePartInfo> parts = operation.getInput()
621: .getMessageParts();
622: assertNotNull(parts);
623: assertEquals(2, parts.size());
624: assertEquals("header_info", parts.get(0).getName()
625: .getLocalPart());
626: assertEquals("the_request", parts.get(1).getName()
627: .getLocalPart());
628: control.verify();
629: }
630:
631: @Test
632: public void testExtensions() throws Exception {
633: setUpWSDL("hello_world_ext.wsdl", 0);
634:
635: String ns = "http://apache.org/hello_world_soap_http";
636: QName pingMeOpName = new QName(ns, "pingMe");
637: QName greetMeOpName = new QName(ns, "greetMe");
638: QName faultName = new QName(ns, "pingMeFault");
639:
640: // portType extensions
641:
642: InterfaceInfo ii = serviceInfo.getInterface();
643: assertEquals(2, ii.getExtensionAttributes().size());
644: assertNotNull(ii.getExtensionAttribute(EXTENSION_ATTR_BOOLEAN));
645: assertNotNull(ii.getExtensionAttribute(EXTENSION_ATTR_STRING));
646: assertEquals(1, ii.getExtensors(
647: UnknownExtensibilityElement.class).size());
648: assertEquals(EXTENSION_ELEM, ii.getExtensor(
649: UnknownExtensibilityElement.class).getElementType());
650:
651: // portType/operation extensions
652:
653: OperationInfo oi = ii.getOperation(pingMeOpName);
654: assertPortTypeOperationExtensions(oi, true);
655: assertPortTypeOperationExtensions(ii
656: .getOperation(greetMeOpName), false);
657:
658: // portType/operation/[input|output|fault] extensions
659:
660: assertPortTypeOperationMessageExtensions(oi, true, true,
661: faultName);
662: assertPortTypeOperationMessageExtensions(ii
663: .getOperation(greetMeOpName), false, true, null);
664:
665: // service extensions
666:
667: assertEquals(1, serviceInfo.getExtensionAttributes().size());
668: assertNotNull(serviceInfo
669: .getExtensionAttribute(EXTENSION_ATTR_STRING));
670: assertEquals(1, serviceInfo.getExtensors(
671: UnknownExtensibilityElement.class).size());
672: assertEquals(EXTENSION_ELEM, serviceInfo.getExtensor(
673: UnknownExtensibilityElement.class).getElementType());
674:
675: // service/port extensions
676:
677: EndpointInfo ei = serviceInfo.getEndpoints().iterator().next();
678: assertEquals(1, ei.getExtensionAttributes().size());
679: assertNotNull(ei.getExtensionAttribute(EXTENSION_ATTR_STRING));
680: assertEquals(1, ei.getExtensors(
681: UnknownExtensibilityElement.class).size());
682: assertEquals(EXTENSION_ELEM, ei.getExtensor(
683: UnknownExtensibilityElement.class).getElementType());
684:
685: // binding extensions
686:
687: BindingInfo bi = ei.getBinding();
688: // REVISIT: bug in wsdl4j?
689: // getExtensionAttributes on binding element returns an empty map
690: // assertEquals(1, bi.getExtensionAttributes().size());
691: // assertNotNull(bi.getExtensionAttribute(EXTENSION_ATTR_STRING));
692: assertEquals(1, bi.getExtensors(
693: UnknownExtensibilityElement.class).size());
694: assertEquals(EXTENSION_ELEM, bi.getExtensor(
695: UnknownExtensibilityElement.class).getElementType());
696:
697: // binding/operation extensions
698:
699: BindingOperationInfo boi = bi.getOperation(pingMeOpName);
700: assertBindingOperationExtensions(boi, true);
701: assertBindingOperationExtensions(
702: bi.getOperation(greetMeOpName), false);
703:
704: // binding/operation/[input|output|fault] extensions
705:
706: assertBindingOperationMessageExtensions(boi, true, true,
707: faultName);
708: assertBindingOperationMessageExtensions(bi
709: .getOperation(greetMeOpName), false, true, null);
710: control.verify();
711:
712: }
713:
714: private void assertPortTypeOperationExtensions(OperationInfo oi,
715: boolean expectExtensions) {
716: if (expectExtensions) {
717: assertEquals(1, oi.getExtensionAttributes().size());
718: assertNotNull(oi
719: .getExtensionAttribute(EXTENSION_ATTR_STRING));
720: assertEquals(1, oi.getExtensors(
721: UnknownExtensibilityElement.class).size());
722: assertEquals(EXTENSION_ELEM, oi.getExtensor(
723: UnknownExtensibilityElement.class).getElementType());
724: } else {
725: assertNull(oi.getExtensionAttributes());
726: assertNull(oi.getExtensionAttribute(EXTENSION_ATTR_STRING));
727: assertNull(oi
728: .getExtensors(UnknownExtensibilityElement.class));
729: assertNull(oi
730: .getExtensor(UnknownExtensibilityElement.class));
731: }
732: }
733:
734: private void assertBindingOperationExtensions(
735: BindingOperationInfo boi, boolean expectExtensions) {
736: if (expectExtensions) {
737: assertEquals(1, boi.getExtensionAttributes().size());
738: assertNotNull(boi
739: .getExtensionAttribute(EXTENSION_ATTR_STRING));
740: assertEquals(1, boi.getExtensors(
741: UnknownExtensibilityElement.class).size());
742: assertEquals(EXTENSION_ELEM, boi.getExtensor(
743: UnknownExtensibilityElement.class).getElementType());
744: } else {
745: assertNull(boi.getExtensionAttributes());
746: assertNull(boi.getExtensionAttribute(EXTENSION_ATTR_STRING));
747: assertEquals(0, boi.getExtensors(
748: UnknownExtensibilityElement.class).size());
749: assertNull(boi
750: .getExtensor(UnknownExtensibilityElement.class));
751: }
752: }
753:
754: private void assertPortTypeOperationMessageExtensions(
755: OperationInfo oi, boolean expectExtensions,
756: boolean hasOutput, QName fault) {
757:
758: MessageInfo mi = oi.getInput();
759: if (expectExtensions) {
760: assertEquals(1, mi.getExtensionAttributes().size());
761: assertNotNull(mi
762: .getExtensionAttribute(EXTENSION_ATTR_STRING));
763: assertEquals(1, mi.getExtensors(
764: UnknownExtensibilityElement.class).size());
765: assertEquals(EXTENSION_ELEM, mi.getExtensor(
766: UnknownExtensibilityElement.class).getElementType());
767: } else {
768: assertNull(mi.getExtensionAttributes());
769: assertNull(mi.getExtensionAttribute(EXTENSION_ATTR_STRING));
770: assertNull(mi
771: .getExtensors(UnknownExtensibilityElement.class));
772: assertNull(mi
773: .getExtensor(UnknownExtensibilityElement.class));
774: }
775:
776: if (hasOutput) {
777: mi = oi.getOutput();
778: if (expectExtensions) {
779: assertEquals(1, mi.getExtensionAttributes().size());
780: assertNotNull(mi
781: .getExtensionAttribute(EXTENSION_ATTR_STRING));
782: assertEquals(1, mi.getExtensors(
783: UnknownExtensibilityElement.class).size());
784: assertEquals(EXTENSION_ELEM, mi.getExtensor(
785: UnknownExtensibilityElement.class)
786: .getElementType());
787: } else {
788: assertNull(mi.getExtensionAttributes());
789: assertNull(mi
790: .getExtensionAttribute(EXTENSION_ATTR_STRING));
791: assertNull(mi
792: .getExtensors(UnknownExtensibilityElement.class));
793: assertNull(mi
794: .getExtensor(UnknownExtensibilityElement.class));
795: }
796: }
797:
798: if (null != fault) {
799: FaultInfo fi = oi.getFault(fault);
800: if (expectExtensions) {
801: assertEquals(1, fi.getExtensionAttributes().size());
802: assertNotNull(fi
803: .getExtensionAttribute(EXTENSION_ATTR_STRING));
804: assertEquals(1, fi.getExtensors(
805: UnknownExtensibilityElement.class).size());
806: assertEquals(EXTENSION_ELEM, fi.getExtensor(
807: UnknownExtensibilityElement.class)
808: .getElementType());
809: } else {
810: assertNull(fi.getExtensionAttributes());
811: assertNull(fi
812: .getExtensionAttribute(EXTENSION_ATTR_STRING));
813: assertNull(fi
814: .getExtensors(UnknownExtensibilityElement.class));
815: assertNull(fi
816: .getExtensor(UnknownExtensibilityElement.class));
817: }
818: }
819: }
820:
821: private void assertBindingOperationMessageExtensions(
822: BindingOperationInfo boi, boolean expectExtensions,
823: boolean hasOutput, QName fault) {
824:
825: BindingMessageInfo bmi = boi.getInput();
826: if (expectExtensions) {
827: // REVISIT: bug in wsdl4j?
828: // getExtensionAttributes on binding/operation/input element returns an empty map
829: // assertEquals(1, bmi.getExtensionAttributes().size());
830: // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
831: assertEquals(1, bmi.getExtensors(
832: UnknownExtensibilityElement.class).size());
833: assertEquals(EXTENSION_ELEM, bmi.getExtensor(
834: UnknownExtensibilityElement.class).getElementType());
835: } else {
836: assertNull(bmi.getExtensionAttributes());
837: assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
838: assertEquals(0, bmi.getExtensors(
839: UnknownExtensibilityElement.class).size());
840: assertNull(bmi
841: .getExtensor(UnknownExtensibilityElement.class));
842: }
843:
844: if (hasOutput) {
845: bmi = boi.getOutput();
846: if (expectExtensions) {
847: // REVISIT: bug in wsdl4j?
848: // getExtensionAttributes on binding/operation/output element returns an empty map
849: // assertEquals(1, bmi.getExtensionAttributes().size());
850: // assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
851: assertEquals(1, bmi.getExtensors(
852: UnknownExtensibilityElement.class).size());
853: assertEquals(EXTENSION_ELEM, bmi.getExtensor(
854: UnknownExtensibilityElement.class)
855: .getElementType());
856: } else {
857: assertNull(bmi.getExtensionAttributes());
858: assertNull(bmi
859: .getExtensionAttribute(EXTENSION_ATTR_STRING));
860: assertEquals(0, bmi.getExtensors(
861: UnknownExtensibilityElement.class).size());
862: assertNull(bmi
863: .getExtensor(UnknownExtensibilityElement.class));
864: }
865: }
866:
867: if (null != fault) {
868: BindingFaultInfo bfi = boi.getFault(fault);
869: if (expectExtensions) {
870: assertEquals(1, bfi.getExtensionAttributes().size());
871: assertNotNull(bfi
872: .getExtensionAttribute(EXTENSION_ATTR_STRING));
873: assertEquals(1, bfi.getExtensors(
874: UnknownExtensibilityElement.class).size());
875: assertEquals(EXTENSION_ELEM, bfi.getExtensor(
876: UnknownExtensibilityElement.class)
877: .getElementType());
878: } else {
879: assertNull(bfi.getExtensionAttributes());
880: assertNull(bfi
881: .getExtensionAttribute(EXTENSION_ATTR_STRING));
882: assertNull(bfi
883: .getExtensors(UnknownExtensibilityElement.class));
884: assertNull(bfi
885: .getExtensor(UnknownExtensibilityElement.class));
886: }
887: }
888: }
889:
890: }
|