KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsdl > WOMBuilderTest


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.wsdl;
17
18
19 import org.apache.axis2.wsdl.WSDLVersionWrapper;
20 import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
21
22 import javax.wsdl.Definition;
23 import javax.wsdl.Operation;
24 import javax.wsdl.PortType;
25 import javax.wsdl.Service;
26 import java.io.FileInputStream JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * @author chathura@opensource.lk
32  */

33 public class WOMBuilderTest extends AbstractTestCase {
34
35     private WSDLDescription womDescription = null;
36
37     private Definition wsdl4jDefinition = null;
38
39     public WOMBuilderTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     private void initialize() throws Exception JavaDoc {
44
45         WSDLVersionWrapper wsdlVersionWrapper = null;
46         if (null == this.womDescription) {
47             InputStream JavaDoc in = new FileInputStream JavaDoc(getTestResourceFile("InteropTest.wsdl"));
48             wsdlVersionWrapper = WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in);
49             this.womDescription = wsdlVersionWrapper.getDescription();
50         }
51         if (null == wsdl4jDefinition) {
52             this.wsdl4jDefinition = wsdlVersionWrapper.getDefinition();
53         }
54     }
55
56     public void testTopLevelComponentCount() throws Exception JavaDoc {
57         this.initialize();
58         assertEquals(womDescription.getServices().size(), wsdl4jDefinition.getServices().size());
59         assertEquals(womDescription.getWsdlInterfaces().size(), wsdl4jDefinition.getPortTypes().size());
60         ;
61         assertEquals(womDescription.getServices().size(), wsdl4jDefinition.getServices().size());
62         assertEquals(womDescription.getBindings().size(), wsdl4jDefinition.getBindings().size());
63         
64     }
65
66     public void testInterfacesComponent() throws Exception JavaDoc {
67         this.initialize();
68         Iterator JavaDoc interfaceIterator = this.womDescription.getWsdlInterfaces().values().iterator();
69         Iterator JavaDoc porttypeIterator = this.wsdl4jDefinition.getPortTypes().values().iterator();
70         while (interfaceIterator.hasNext() & porttypeIterator.hasNext()) {
71             WSDLInterface wsdlInterface = (WSDLInterface) interfaceIterator.next();
72             PortType porttype = (PortType) porttypeIterator.next();
73             assertEquals(wsdlInterface.getName(), porttype.getQName());
74             assertEquals(wsdlInterface.getTargetnamespace(), porttype.getQName().getNamespaceURI());
75             assertEquals(wsdlInterface.getAllOperations().size(), porttype.getOperations().size());
76             Iterator JavaDoc womOperationIterator = wsdlInterface.getAllOperations().values().iterator();
77             Iterator JavaDoc wsdl4jOprationIterator = porttype.getOperations().iterator();
78             //Will only work if the order is retained in the iteration
79
while (wsdl4jOprationIterator.hasNext()) {
80                 Operation wsdl4jOperation = (Operation) wsdl4jOprationIterator.next();
81                 this.operationsWaliking(wsdlInterface.getOperation(wsdl4jOperation.getName()), wsdl4jOperation);
82             }
83             while(womOperationIterator.hasNext() ){
84                 WSDLOperation womOperation = (WSDLOperation)womOperationIterator.next();
85                 this.operationsWaliking(womOperation, porttype.getOperation(womOperation.getName().getLocalPart(), null,null));
86             }
87
88         }
89     }
90
91     public void testServiceComponent() throws Exception JavaDoc {
92         this.initialize();
93         Iterator JavaDoc womServiceIterator = this.womDescription.getServices().values().iterator();
94         Iterator JavaDoc wsdl4jServiceIterator = this.wsdl4jDefinition.getServices().values().iterator();
95
96         while (womServiceIterator.hasNext() & wsdl4jServiceIterator.hasNext()) {
97             WSDLService wsdlService = (WSDLService) womServiceIterator.next();
98             Service wsdl4jService = (Service) wsdl4jServiceIterator.next();
99             assertEquals(wsdlService.getName(), wsdl4jService.getQName());
100
101         }
102     }
103
104
105     private void operationsWaliking(WSDLOperation womOperation, Operation wsdl4jOperation) {
106         assertEquals(womOperation.getName().getLocalPart(), wsdl4jOperation.getName());
107         //System.out.println(womOperation.getMessageExchangePattern());
108

109       
110     }
111
112
113 }
114
Popular Tags