Debian Codegraph @

test/wsdl/multiref/Main.java

raw
1 /*
2 * Copyright 2000,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
17 package test.wsdl.multiref;
18
19 import org.apache.axis.utils.Options;
20 import test.wsdl.multiref.holders.NodeHolder;
21
22 import java.net.URL;
23
24
25 /**
26 * This class shows/tests how multi-referenced objects are preserved.
27 *
28 * @author Rich Scheuerle ([email protected])
29 */
30 public class Main {
31
32 public static void main (String[] args) throws Exception {
33 Options opts = new Options(args);
34
35 MultiRefTestService service = new MultiRefTestServiceLocator();
36 opts.setDefaultURL( service.getMultiRefTestAddress() );
37 URL serviceURL = new URL(opts.getURL());
38 if (serviceURL == null)
39 serviceURL = new URL(service.getMultiRefTestAddress());
40
41 MultiRefTest remoteTest = service.getMultiRefTest(serviceURL);
42
43 // ----------------------
44 // Create a simple tree
45 Node t = new Node();
46 t.setData(0);
47 Node l = new Node();
48 l.setData(1);
49 Node r = new Node();
50 r.setData(2);
51 t.setLeft(l);
52 t.setRight(r);
53 NodeHolder holder = new NodeHolder(t);
54
55 // Test for simple tree
56 int rc = remoteTest.testSimpleTree(holder);
57 if (rc == 0) {
58 // System.err.println("Passed testSimpleTree 1");
59 } else {
60 System.err.println("Failed testSimpleTree 1");
61 throw new Exception("Failed testSimpleTree 1 with "+rc);
62 }
63 // Test returns the tree. To make sure it returned it successfully,
64 // invoke the test again!
65 rc = remoteTest.testSimpleTree(holder);
66 if (rc == 0) {
67 // System.err.println("Passed testSimpleTree 2");
68 } else {
69 System.err.println("Failed testSimpleTree 2");
70 throw new Exception("Failed testSimpleTree 2 with "+rc);
71 }
72
73 // ----------------------
74 // Create a diamond
75 t = new Node();
76 t.setData(0);
77 l = new Node();
78 l.setData(1);
79 r = new Node();
80 r.setData(2);
81 t.setLeft(l);
82 t.setRight(r);
83
84 Node d = new Node();
85 d.setData(3);
86 t.getLeft().setRight(d);
87 t.getRight().setLeft(d);
88 holder = new NodeHolder(t);
89
90 // Test for a diamond
91 rc = remoteTest.testDiamond(holder);
92 if (rc == 0) {
93 // System.err.println("Passed testDiamond 1");
94 } else {
95 System.err.println("Failed testDiamond 1");
96 throw new Exception("Failed testDiamond 1 with "+rc);
97 }
98 // Test returns the tree. To make sure it returned it successfully,
99 // invoke the test again!
100 rc = remoteTest.testDiamond(holder);
101 if (rc == 0) {
102 // System.err.println("Passed testDiamond 2");
103 } else {
104 System.err.println("Failed testDiamond 2");
105 throw new Exception("Failed testDiamond 2 with "+rc);
106 }
107
108 // ----------------------
109 // Create a 'loop' tree. The children of the root have children that reference the root.
110 t = new Node();
111 t.setData(0);
112 l = new Node();
113 l.setData(1);
114 r = new Node();
115 r.setData(2);
116 t.setLeft(l);
117 t.setRight(r);
118
119 l.setLeft(t);
120 l.setRight(t);
121 r.setLeft(t);
122 r.setRight(t);
123
124 holder = new NodeHolder(t);
125
126 // Test for loops
127 rc = remoteTest.testLoop(holder);
128 if (rc == 0) {
129 // System.err.println("Passed testLoop 1");
130 } else {
131 System.err.println("Failed testLoop 1");
132 throw new Exception("Failed testLoop 1 with "+rc);
133 }
134 // Test returns the tree. To make sure it returned it successfully,
135 // invoke the test again!
136 rc = remoteTest.testLoop(holder);
137 if (rc == 0) {
138 // System.err.println("Passed testLoop 2");
139 } else {
140 System.err.println("Failed testLoop 2");
141 throw new Exception("Failed testLoop 2 with "+rc);
142 }
143
144 // ----------------------
145 // Create a 'loop' tree. The children of the root have children that reference the root.
146 // In this test both children have the same data (thus the same equals()).
147 // There should still be separate nodes passed over the wire
148 t = new Node();
149 t.setData(0);
150 l = new Node();
151 l.setData(1);
152 r = new Node();
153 r.setData(1);
154 t.setLeft(l);
155 t.setRight(r);
156
157 l.setLeft(t);
158 l.setRight(t);
159 r.setLeft(t);
160 r.setRight(t);
161
162 holder = new NodeHolder(t);
163
164 // Test for loops
165 rc = remoteTest.testLoop(holder);
166 if (rc == 0) {
167 // System.err.println("Passed testLoop 1B");
168 } else {
169 System.err.println("Failed testLoop 1B");
170 throw new Exception("Failed testLoop 1B with "+rc);
171 }
172 // Test returns the tree. To make sure it returned it successfully,
173 // invoke the test again!
174 rc = remoteTest.testLoop(holder);
175 if (rc == 0) {
176 // System.err.println("Passed testLoop 2B");
177 } else {
178 System.err.println("Failed testLoop 2B");
179 throw new Exception("Failed testLoop 2B with "+rc);
180 }
181
182 // ----------------------
183 // Test passing of the same node argument.
184 t = new Node();
185 t.setData(0);
186 NodeHolder holder1 = new NodeHolder(t);
187 NodeHolder holder2 = new NodeHolder(t);
188
189 // Test
190 rc = remoteTest.testSameArgs(holder1, holder2);
191 if (rc == 0) {
192 // System.err.println("Passed testSameArgs 1");
193 } else {
194 System.err.println("Failed testSameArgs 1");
195 throw new Exception("Failed testSameArgs 1 with "+rc);
196 }
197 // Test returns the tree. To make sure it returned it successfully,
198 // invoke the test again!
199 rc = remoteTest.testSameArgs(holder1,holder2);
200 if (rc == 0) {
201 // System.err.println("Passed testSameArgs 2");
202 } else {
203 System.err.println("Failed testSameArgs 2");
204 throw new Exception("Failed testSameArgs 2 with "+rc);
205 }
206
207 // ----------------------
208 // Test args referencing same node.
209 Node t1 = new Node();
210 t1.setData(0);
211 Node t2 = new Node();
212 t2.setData(1);
213 Node s = new Node();
214 s.setData(1);
215 t1.setRight(s);
216 t2.setLeft(s);
217 holder1 = new NodeHolder(t1);
218 holder2 = new NodeHolder(t2);
219
220 // Test
221 rc = remoteTest.testArgsRefSameNode(holder1, holder2);
222 if (rc == 0) {
223 // System.err.println("Passed testArgsRefSameNode 1");
224 } else {
225 System.err.println("Failed testArgsRefSameNode 1");
226 throw new Exception("Failed testArgsRefSameNode 1 with "+rc);
227 }
228 // Test returns the tree. To make sure it returned it successfully,
229 // invoke the test again!
230 rc = remoteTest.testArgsRefSameNode(holder1,holder2);
231 if (rc == 0) {
232 // System.err.println("Passed testArgsRefSameNode 2");
233 } else {
234 System.err.println("Failed testArgsRefSameNode 2");
235 throw new Exception("Failed testArgsRefSameNode 2 with "+rc);
236 }
237 // ----------------------
238 // Test args referencing each other.
239 t1 = new Node();
240 t1.setData(0);
241 t2 = new Node();
242 t2.setData(1);
243 t2.setLeft(t1);
244 t2.setRight(t1);
245 t1.setRight(t2);
246 t1.setLeft(t2);
247 holder1 = new NodeHolder(t1);
248 holder2 = new NodeHolder(t2);
249
250 // Test
251 rc = remoteTest.testArgsRefEachOther(holder1, holder2);
252 if (rc == 0) {
253 // System.err.println("Passed testArgsRefEachOther 1");
254 } else {
255 System.err.println("Failed testArgsRefEachOther 1");
256 throw new Exception("Failed testArgsRefEachOther 1 with "+rc);
257 }
258 // Test returns the tree. To make sure it returned it successfully,
259 // invoke the test again!
260 rc = remoteTest.testArgsRefEachOther(holder1,holder2);
261 if (rc == 0) {
262 // System.err.println("Passed testArgsRefEachOther 2");
263 } else {
264 System.err.println("Failed testArgsRefEachOther 2");
265 throw new Exception("Failed testArgsRefEachOther 2 with "+rc);
266 }
267
268 // ----------------------
269 // Create self referencing node
270 t = new Node();
271 t.setData(0);
272 t.setLeft(t);
273 t.setRight(t);
274 holder = new NodeHolder(t);
275
276 // Self-Ref Test
277 rc = remoteTest.testSelfRef(holder);
278 if (rc == 0) {
279 // System.err.println("Passed testSelfRef 1");
280 } else {
281 System.err.println("Failed testSelfRef 1");
282 throw new Exception("Failed testSelfRef 1 with "+rc);
283 }
284 // Test returns the tree. To make sure it returned it successfully,
285 // invoke the test again!
286 rc = remoteTest.testSelfRef(holder);
287 if (rc == 0) {
288 // System.err.println("Passed testSelfRef 2");
289 } else {
290 System.err.println("Failed testSelfRef 2");
291 throw new Exception("Failed testSelfRef 2 with "+rc);
292 }
293
294 return;
295 }
296 }
297