ICE 3.4.2
[php5-ice-freebsdport.git] / py / test / Ice / servantLocator / AllTests.py
blobb21325b6eea051225f8f8dae3dc5e36f36409f84
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 import sys, Ice, Test
12 def test(b):
13 if not b:
14 raise RuntimeError('test assertion failed')
16 def testExceptions(obj, collocated):
18 try:
19 obj.requestFailedException()
20 test(False)
21 except Ice.ObjectNotExistException, ex:
22 if not collocated:
23 test(ex.id == obj.ice_getIdentity())
24 test(ex.facet == obj.ice_getFacet())
25 test(ex.operation == "requestFailedException")
26 except:
27 test(False)
29 try:
30 obj.unknownUserException()
31 test(False)
32 except Ice.UnknownUserException, ex:
33 test(ex.unknown == "reason")
34 except:
35 test(False)
37 try:
38 obj.unknownLocalException()
39 test(False)
40 except Ice.UnknownLocalException, ex:
41 test(ex.unknown == "reason")
42 except:
43 test(False)
45 try:
46 obj.unknownException()
47 test(False)
48 except Ice.UnknownException, ex:
49 test(ex.unknown == "reason")
50 pass
52 try:
53 obj.userException()
54 test(False)
55 except Ice.UnknownUserException, ex:
56 test(ex.unknown.find("Test::TestIntfUserException") >= 0)
57 except:
58 test(False)
60 try:
61 obj.localException()
62 test(False)
63 except Ice.UnknownLocalException, ex:
64 test(not collocated)
65 test(ex.unknown.find("Ice.SocketException") >= 0)
66 except SocketException:
67 test(collocated)
68 except:
69 test(False)
71 try:
72 obj.pythonException()
73 test(False)
74 except Ice.UnknownException, ex:
75 test(ex.unknown.find("RuntimeError: message") >= 0)
76 except:
77 test(False)
79 try:
80 obj.unknownExceptionWithServantException()
81 test(False)
82 except Ice.UnknownException, ex:
83 test(ex.unknown == "reason")
84 except:
85 test(False)
87 try:
88 obj.impossibleException(False)
89 test(False)
90 except Ice.UnknownUserException:
91 # Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
92 pass
93 except:
94 test(False)
96 try:
97 obj.impossibleException(True)
98 test(False)
99 except Ice.UnknownUserException:
100 # Operation doesn't throw, but locate() and finished() throw TestIntfUserException.
101 pass
102 except:
103 test(False)
105 try:
106 obj.intfUserException(False)
107 test(False)
108 except Test.TestImpossibleException:
109 # Operation doesn't throw, but locate() and finished() throw TestImpossibleException.
110 pass
111 except:
112 test(False)
114 try:
115 obj.intfUserException(True)
116 test(False)
117 except Test.TestImpossibleException:
118 # Operation throws TestIntfUserException, but locate() and finished() throw TestImpossibleException.
119 pass
120 except:
121 test(False)
123 def allTests(communicator, collocated):
124 print "testing stringToProxy...",
125 sys.stdout.flush()
126 base = communicator.stringToProxy("asm:default -p 12010")
127 test(base)
128 print "ok"
130 print "testing checked cast...",
131 sys.stdout.flush()
132 obj = Test.TestIntfPrx.checkedCast(base)
133 test(obj)
134 test(obj == base)
135 print "ok"
137 print "testing ice_ids...",
138 sys.stdout.flush()
139 try:
140 obj = communicator.stringToProxy("category/locate:default -p 12010")
141 obj.ice_ids()
142 test(False)
143 except Ice.UnknownUserException, ex:
144 test(ex.unknown == "Test::TestIntfUserException")
145 except:
146 test(False)
148 try:
149 obj = communicator.stringToProxy("category/finished:default -p 12010")
150 obj.ice_ids()
151 test(False)
152 except Ice.UnknownUserException, ex:
153 test(ex.unknown == "Test::TestIntfUserException")
154 except:
155 test(False)
156 print "ok"
158 print "testing servant locator...",
159 sys.stdout.flush()
160 base = communicator.stringToProxy("category/locate:default -p 12010")
161 obj = Test.TestIntfPrx.checkedCast(base)
162 try:
163 Test.TestIntfPrx.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010"))
164 except Ice.ObjectNotExistException:
165 pass
166 print "ok"
168 print "testing default servant locator...",
169 sys.stdout.flush()
170 base = communicator.stringToProxy("anothercat/locate:default -p 12010")
171 obj = Test.TestIntfPrx.checkedCast(base)
172 base = communicator.stringToProxy("locate:default -p 12010")
173 obj = Test.TestIntfPrx.checkedCast(base)
174 try:
175 Test.TestIntfPrx.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010"))
176 except Ice.ObjectNotExistException:
177 pass
178 try:
179 Test.TestIntfPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010"))
180 except Ice.ObjectNotExistException:
181 pass
182 print "ok"
184 print "testing locate exceptions...",
185 sys.stdout.flush()
186 base = communicator.stringToProxy("category/locate:default -p 12010")
187 obj = Test.TestIntfPrx.checkedCast(base)
188 testExceptions(obj, collocated)
189 print "ok"
191 print "testing finished exceptions...",
192 sys.stdout.flush()
193 base = communicator.stringToProxy("category/finished:default -p 12010")
194 obj = Test.TestIntfPrx.checkedCast(base)
195 testExceptions(obj, collocated)
196 print "ok"
198 print "testing servant locator removal...",
199 sys.stdout.flush()
200 base = communicator.stringToProxy("test/activation:default -p 12010")
201 activation = Test.TestActivationPrx.checkedCast(base)
202 activation.activateServantLocator(False)
203 try:
204 obj.ice_ping()
205 test(False)
206 except Ice.ObjectNotExistException:
207 pass
208 print "ok"
210 print "testing servant locator addition...",
211 sys.stdout.flush()
212 activation.activateServantLocator(True)
213 try:
214 obj.ice_ping()
215 except:
216 test(False)
217 print "ok"
219 return obj