1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
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
;
23 import Ice
.UnknownException
;
24 import Ice
.UnknownLocalException
;
25 import Ice
.UnknownUserException
;
34 throw new RuntimeException();
39 testExceptions(TestIntfPrx obj
, boolean collocated
)
43 obj
.requestFailedException();
46 catch(ObjectNotExistException ex
)
50 test(ex
.id
.equals(obj
.ice_getIdentity()));
51 test(ex
.facet
.equals(obj
.ice_getFacet()));
52 test(ex
.operation
.equals("requestFailedException"));
58 obj
.unknownUserException();
61 catch(UnknownUserException ex
)
63 test(ex
.unknown
.equals("reason"));
68 obj
.unknownLocalException();
71 catch(UnknownLocalException ex
)
73 test(ex
.unknown
.equals("reason"));
78 obj
.unknownException();
81 catch(UnknownException ex
)
83 test(ex
.unknown
.equals("reason"));
87 // User exceptions are checked exceptions
91 // obj.userException();
94 // catch(UnknownUserException ex)
96 // //System.err.println(ex.unknown);
98 // test(ex.unknown.equals("Test::TestIntfUserException"));
100 // catch(TestIntfUserException ex)
107 obj
.localException();
110 catch(UnknownLocalException ex
)
112 test(ex
.unknown
.indexOf("Ice::SocketException") >= 0);
124 catch(UnknownException ex
)
126 test(ex
.unknown
.indexOf("java.lang.RuntimeException: message") >= 0);
135 obj
.impossibleException(false);
138 catch(UnknownUserException ex
)
140 // Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
144 //System.err.println(ex);
150 obj
.impossibleException(true);
153 catch(UnknownUserException ex
)
155 // Operation throws TestImpossibleException, but locate() and finished() throw TestIntfUserException.
159 //System.err.println(ex);
165 obj
.intfUserException(false);
168 catch(TestImpossibleException ex
)
170 // Operation doesn't throw, but locate() and finished() throw TestImpossibleException.
174 //System.err.println(ex);
180 obj
.intfUserException(true);
183 catch(TestImpossibleException ex
)
185 // Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException.
189 //System.err.println(ex);
194 public static TestIntfPrx
195 allTests(Ice
.Communicator communicator
, boolean collocated
, PrintWriter out
)
197 out
.print("testing stringToProxy... ");
199 String ref
= "asm:default -p 12010";
200 Ice
.ObjectPrx base
= communicator
.stringToProxy(ref
);
204 out
.print("testing checked cast... ");
206 TestIntfPrx obj
= TestIntfPrxHelper
.checkedCast(base
);
208 test(obj
.equals(base
));
211 out
.print("testing ice_ids... ");
215 ObjectPrx o
= communicator
.stringToProxy("category/locate:default -p 12010");
219 catch(UnknownUserException ex
)
221 test(ex
.unknown
.equals("Test::TestIntfUserException"));
230 ObjectPrx o
= communicator
.stringToProxy("category/finished:default -p 12010");
234 catch(UnknownUserException ex
)
236 test(ex
.unknown
.equals("Test::TestIntfUserException"));
244 out
.print("testing servant locator... ");
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
)
257 out
.print("testing default servant locator... ");
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
)
279 out
.print("testing locate exceptions... ");
281 base
= communicator
.stringToProxy("category/locate:default -p 12010");
282 obj
= TestIntfPrxHelper
.checkedCast(base
);
283 testExceptions(obj
, collocated
);
286 out
.print("testing finished exceptions... ");
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.
299 catch(TestIntfUserException ex
)
303 catch(TestImpossibleException ex
)
306 // Called by finished().
311 // Only call these for category/finished.
315 obj
.asyncException();
317 catch(TestIntfUserException ex
)
321 catch(TestImpossibleException ex
)
324 // Called by finished().
330 out
.print("testing servant locator removal... ");
332 base
= communicator
.stringToProxy("test/activation:default -p 12010");
333 TestActivationPrx activation
= TestActivationPrxHelper
.checkedCast(base
);
334 activation
.activateServantLocator(false);
340 catch(ObjectNotExistException ex
)
344 out
.print("testing servant locator addition... ");
346 activation
.activateServantLocator(true);