ICE 3.4.2
[php5-ice-freebsdport.git] / java / test / Ice / servantLocator / AllTests.java
blobdbca713db204bd3ecc857e095afffe0a0e27323e
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 package test.Ice.servantLocator;
12 import java.io.PrintWriter;
14 import test.Ice.servantLocator.Test.TestImpossibleException;
15 import test.Ice.servantLocator.Test.TestIntfUserException;
16 import test.Ice.servantLocator.Test.TestIntfPrx;
17 import test.Ice.servantLocator.Test.TestIntfPrxHelper;
18 import test.Ice.servantLocator.Test.TestActivationPrx;
19 import test.Ice.servantLocator.Test.TestActivationPrxHelper;
21 import Ice.ObjectNotExistException;
22 import Ice.ObjectPrx;
23 import Ice.UnknownException;
24 import Ice.UnknownLocalException;
25 import Ice.UnknownUserException;
27 public class AllTests
29 private static void
30 test(boolean b)
32 if(!b)
34 throw new RuntimeException();
38 public static void
39 testExceptions(TestIntfPrx obj, boolean collocated)
41 try
43 obj.requestFailedException();
44 test(false);
46 catch(ObjectNotExistException ex)
48 if(!collocated)
50 test(ex.id.equals(obj.ice_getIdentity()));
51 test(ex.facet.equals(obj.ice_getFacet()));
52 test(ex.operation.equals("requestFailedException"));
56 try
58 obj.unknownUserException();
59 test(false);
61 catch(UnknownUserException ex)
63 test(ex.unknown.equals("reason"));
66 try
68 obj.unknownLocalException();
69 test(false);
71 catch(UnknownLocalException ex)
73 test(ex.unknown.equals("reason"));
76 try
78 obj.unknownException();
79 test(false);
81 catch(UnknownException ex)
83 test(ex.unknown.equals("reason"));
87 // User exceptions are checked exceptions
89 // try
90 // {
91 // obj.userException();
92 // test(false);
93 // }
94 // catch(UnknownUserException ex)
95 // {
96 // //System.err.println(ex.unknown);
97 // test(!collocated);
98 // test(ex.unknown.equals("Test::TestIntfUserException"));
99 // }
100 // catch(TestIntfUserException ex)
101 // {
102 // test(collocated);
103 // }
107 obj.localException();
108 test(false);
110 catch(UnknownLocalException ex)
112 test(ex.unknown.indexOf("Ice::SocketException") >= 0);
114 catch(Throwable ex)
116 test(false);
121 obj.javaException();
122 test(false);
124 catch(UnknownException ex)
126 test(ex.unknown.indexOf("java.lang.RuntimeException: message") >= 0);
128 catch(Throwable ex)
130 test(false);
135 obj.impossibleException(false);
136 test(false);
138 catch(UnknownUserException ex)
140 // Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
142 catch(Throwable ex)
144 //System.err.println(ex);
145 test(false);
150 obj.impossibleException(true);
151 test(false);
153 catch(UnknownUserException ex)
155 // Operation throws TestImpossibleException, but locate() and finished() throw TestIntfUserException.
157 catch(Throwable ex)
159 //System.err.println(ex);
160 test(false);
165 obj.intfUserException(false);
166 test(false);
168 catch(TestImpossibleException ex)
170 // Operation doesn't throw, but locate() and finished() throw TestImpossibleException.
172 catch(Throwable ex)
174 //System.err.println(ex);
175 test(false);
180 obj.intfUserException(true);
181 test(false);
183 catch(TestImpossibleException ex)
185 // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException.
187 catch(Throwable ex)
189 //System.err.println(ex);
190 test(false);
194 public static TestIntfPrx
195 allTests(Ice.Communicator communicator, boolean collocated, PrintWriter out)
197 out.print("testing stringToProxy... ");
198 out.flush();
199 String ref = "asm:default -p 12010";
200 Ice.ObjectPrx base = communicator.stringToProxy(ref);
201 test(base != null);
202 out.println("ok");
204 out.print("testing checked cast... ");
205 out.flush();
206 TestIntfPrx obj = TestIntfPrxHelper.checkedCast(base);
207 test(obj != null);
208 test(obj.equals(base));
209 out.println("ok");
211 out.print("testing ice_ids... ");
212 out.flush();
215 ObjectPrx o = communicator.stringToProxy("category/locate:default -p 12010");
216 o.ice_ids();
217 test(false);
219 catch(UnknownUserException ex)
221 test(ex.unknown.equals("Test::TestIntfUserException"));
223 catch(Throwable ex)
225 test(false);
230 ObjectPrx o = communicator.stringToProxy("category/finished:default -p 12010");
231 o.ice_ids();
232 test(false);
234 catch(UnknownUserException ex)
236 test(ex.unknown.equals("Test::TestIntfUserException"));
238 catch(Throwable ex)
240 test(false);
242 out.println("ok");
244 out.print("testing servant locator... ");
245 out.flush();
246 base = communicator.stringToProxy("category/locate:default -p 12010");
247 obj = TestIntfPrxHelper.checkedCast(base);
250 TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010"));
252 catch(ObjectNotExistException ex)
255 out.println("ok");
257 out.print("testing default servant locator... ");
258 out.flush();
259 base = communicator.stringToProxy("anothercat/locate:default -p 12010");
260 obj = TestIntfPrxHelper.checkedCast(base);
261 base = communicator.stringToProxy("locate:default -p 12010");
262 obj = TestIntfPrxHelper.checkedCast(base);
265 TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010"));
267 catch(ObjectNotExistException ex)
272 TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010"));
274 catch(ObjectNotExistException ex)
277 out.println("ok");
279 out.print("testing locate exceptions... ");
280 out.flush();
281 base = communicator.stringToProxy("category/locate:default -p 12010");
282 obj = TestIntfPrxHelper.checkedCast(base);
283 testExceptions(obj, collocated);
284 out.println("ok");
286 out.print("testing finished exceptions... ");
287 out.flush();
288 base = communicator.stringToProxy("category/finished:default -p 12010");
289 obj = TestIntfPrxHelper.checkedCast(base);
290 testExceptions(obj, collocated);
293 // Only call these for category/finished.
297 obj.asyncResponse();
299 catch(TestIntfUserException ex)
301 test(false);
303 catch(TestImpossibleException ex)
306 // Called by finished().
311 // Only call these for category/finished.
315 obj.asyncException();
317 catch(TestIntfUserException ex)
319 test(false);
321 catch(TestImpossibleException ex)
324 // Called by finished().
328 out.println("ok");
330 out.print("testing servant locator removal... ");
331 out.flush();
332 base = communicator.stringToProxy("test/activation:default -p 12010");
333 TestActivationPrx activation = TestActivationPrxHelper.checkedCast(base);
334 activation.activateServantLocator(false);
337 obj.ice_ping();
338 test(false);
340 catch(ObjectNotExistException ex)
342 out.println("ok");
344 out.print("testing servant locator addition... ");
345 out.flush();
346 activation.activateServantLocator(true);
349 obj.ice_ping();
350 out.println("ok");
352 catch(Exception ex)
354 test(false);
357 return obj;