KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package org.apache.wsdl;
17
18 import org.apache.wsdl.impl.WSDLInterfaceImpl;
19 import org.apache.wsdl.impl.WSDLOperationImpl;
20
21 import javax.xml.namespace.QName JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 public class InterfaceTest extends AbstractTestCase {
25     public InterfaceTest(String JavaDoc testName) {
26         super(testName);
27     }
28
29     public void testGetAllOperations() {
30         WSDLOperation op;
31         WSDLInterface intfc;
32         WSDLInterface[] array = new WSDLInterface[5];
33         int interfaceCounter = 5;
34         int operationCounter = 5;
35         for (int j = 0; j < interfaceCounter; j++) {
36             intfc = new WSDLInterfaceImpl();
37             intfc.setName(new QName JavaDoc(WSDLConstants.WSDL2_0_NAMESPACE, "inteface"
38                     + j));
39             for (int i = 0; i < operationCounter; i++) {
40                 op = new WSDLOperationImpl();
41                 op.setName(new QName JavaDoc(WSDLConstants.WSDL1_1_NAMESPACE, "op" + i
42                         + "of inteface" + j));
43                 assertNotNull(op.getName());
44                 intfc.setOperation(op);
45             }
46             if (j > 0) {
47                 intfc.addSuperInterface(array[j - 1]);
48             }
49             array[j] = intfc;
50         }
51         assertEquals(((WSDLOperation) array[0].getOperation("op0of inteface0"))
52                 .getName().getLocalPart(), "op0of inteface0");
53         assertEquals(((WSDLOperation) array[0].getOperation("op1of inteface0"))
54                 .getName().getLocalPart(), "op1of inteface0");
55         assertEquals(array[interfaceCounter - 1].getAllOperations().size(),
56                 interfaceCounter * operationCounter);
57         assertEquals(interfaceCounter * operationCounter,
58                 array[interfaceCounter - 1].getAllOperations().size());
59         Iterator JavaDoc iter = array[1].getAllOperations().keySet().iterator();
60         while (iter.hasNext()) {
61             assertNotNull(((WSDLOperation) array[interfaceCounter - 1]
62                     .getAllOperations().get(iter.next())).getName());
63         }
64         for (int j = 0; j < interfaceCounter; j++) {
65             for (int i = 0; i < operationCounter; i++) {
66                 WSDLOperation operation = (WSDLOperation) array[interfaceCounter - 1]
67                         .getAllOperations().get("op" + j + "of inteface" + i);
68                 assertEquals((operation).getName().getLocalPart(), "op" + j
69                         + "of inteface" + i);
70             }
71         }
72
73     }
74
75     /**
76      * When a interface inherit two or more Interfaces the inherited operation
77      * who have the same QName should be the same Operation.
78      */

79     public void testInheritedOperationResolution() throws Exception JavaDoc {
80         WSDLOperation op;
81         WSDLInterface intfc;
82         WSDLInterface[] array = new WSDLInterface[5];
83         int interfaceCounter = 5;
84         int operationCounter = 5;
85         for (int i = 0; i < interfaceCounter; i++) {
86             intfc = new WSDLInterfaceImpl();
87             for (int j = 0; j < operationCounter; j++) {
88                 op = new WSDLOperationImpl();
89                 op.setName(new QName JavaDoc(WSDLConstants.WSDL1_1_NAMESPACE,
90                         "operation" + j));
91                 intfc.setOperation(op);
92             }
93             intfc.setName(new QName JavaDoc(WSDLConstants.WSDL2_0_NAMESPACE,
94                     "Interface" + i));
95             array[i] = intfc;
96         }
97         WSDLInterface inheritedInterface = new WSDLInterfaceImpl();
98         for (int i = 0; i < array.length; i++) {
99             inheritedInterface.addSuperInterface(array[i]);
100         }
101         assertEquals(inheritedInterface.getAllOperations().size(), 5);
102
103     }
104 }
105
106
Popular Tags