1
// **********************************************************************
3
// Copyright (c) 2003-2007 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
// **********************************************************************
17
throw new RuntimeException();
21
public static Test.MyClassPrx
22
allTests(Ice.Communicator communicator, java.io.PrintStream out)
24
out.print("testing stringToProxy... ");
26
String ref = communicator.getProperties().getPropertyWithDefault("Test.Proxy",
27
"test:default -p 12010 -t 10000");
28
Ice.ObjectPrx base = communicator.stringToProxy(ref);
31
Ice.ObjectPrx b1 = communicator.stringToProxy("test");
32
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
33
b1.ice_getAdapterId().length() == 0 && b1.ice_getFacet().length() == 0);
34
b1 = communicator.stringToProxy("test ");
35
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
36
b1.ice_getFacet().length() == 0);
37
b1 = communicator.stringToProxy(" test ");
38
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
39
b1.ice_getFacet().length() == 0);
40
b1 = communicator.stringToProxy(" test");
41
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
42
b1.ice_getFacet().length() == 0);
43
b1 = communicator.stringToProxy("'test -f facet'");
44
test(b1.ice_getIdentity().name.equals("test -f facet") && b1.ice_getIdentity().category.length() == 0 &&
45
b1.ice_getFacet().length() == 0);
48
b1 = communicator.stringToProxy("\"test -f facet'");
51
catch(Ice.ProxyParseException ex)
54
b1 = communicator.stringToProxy("\"test -f facet\"");
55
test(b1.ice_getIdentity().name.equals("test -f facet") && b1.ice_getIdentity().category.length() == 0 &&
56
b1.ice_getFacet().length() == 0);
57
b1 = communicator.stringToProxy("\"test -f facet@test\"");
58
test(b1.ice_getIdentity().name.equals("test -f facet@test") && b1.ice_getIdentity().category.length() == 0 &&
59
b1.ice_getFacet().length() == 0);
60
b1 = communicator.stringToProxy("\"test -f facet@test @test\"");
61
test(b1.ice_getIdentity().name.equals("test -f facet@test @test") && b1.ice_getIdentity().category.length() == 0 &&
62
b1.ice_getFacet().length() == 0);
65
b1 = communicator.stringToProxy("test test");
68
catch(Ice.ProxyParseException ex)
71
b1 = communicator.stringToProxy("test\\040test");
72
test(b1.ice_getIdentity().name.equals("test test") && b1.ice_getIdentity().category.length() == 0);
75
b1 = communicator.stringToProxy("test\\777");
78
catch(Ice.IdentityParseException ex)
81
b1 = communicator.stringToProxy("test\\40test");
82
test(b1.ice_getIdentity().name.equals("test test"));
84
// Test some octal and hex corner cases.
85
b1 = communicator.stringToProxy("test\\4test");
86
test(b1.ice_getIdentity().name.equals("test\4test"));
87
b1 = communicator.stringToProxy("test\\04test");
88
test(b1.ice_getIdentity().name.equals("test\4test"));
89
b1 = communicator.stringToProxy("test\\004test");
90
test(b1.ice_getIdentity().name.equals("test\4test"));
91
b1 = communicator.stringToProxy("test\\1114test");
92
test(b1.ice_getIdentity().name.equals("test\1114test"));
94
b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test");
95
test(b1.ice_getIdentity().name.equals("test\b\f\n\r\t\'\"\\test") && b1.ice_getIdentity().category.length() == 0);
97
b1 = communicator.stringToProxy("category/test");
98
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") &&
99
b1.ice_getAdapterId().length() == 0);
101
b1 = communicator.stringToProxy("test@adapter");
102
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
103
b1.ice_getAdapterId().equals("adapter"));
106
b1 = communicator.stringToProxy("id@adapter test");
109
catch(Ice.ProxyParseException ex)
112
b1 = communicator.stringToProxy("category/test@adapter");
113
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") &&
114
b1.ice_getAdapterId().equals("adapter"));
115
b1 = communicator.stringToProxy("category/test@adapter:tcp");
116
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") &&
117
b1.ice_getAdapterId().equals("adapter:tcp"));
118
b1 = communicator.stringToProxy("'category 1/test'@adapter");
119
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category 1") &&
120
b1.ice_getAdapterId().equals("adapter"));
121
b1 = communicator.stringToProxy("'category/test 1'@adapter");
122
test(b1.ice_getIdentity().name.equals("test 1") && b1.ice_getIdentity().category.equals("category") &&
123
b1.ice_getAdapterId().equals("adapter"));
124
b1 = communicator.stringToProxy("'category/test'@'adapter 1'");
125
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") &&
126
b1.ice_getAdapterId().equals("adapter 1"));
127
b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@adapter");
128
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category /test@foo") &&
129
b1.ice_getAdapterId().equals("adapter"));
130
b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@\"adapter:tcp\"");
131
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category /test@foo") &&
132
b1.ice_getAdapterId().equals("adapter:tcp"));
134
b1 = communicator.stringToProxy("id -f facet");
135
test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 &&
136
b1.ice_getFacet().equals("facet"));
137
b1 = communicator.stringToProxy("id -f 'facet x'");
138
test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 &&
139
b1.ice_getFacet().equals("facet x"));
140
b1 = communicator.stringToProxy("id -f \"facet x\"");
141
test(b1.ice_getIdentity().name.equals("id") && b1.ice_getIdentity().category.length() == 0 &&
142
b1.ice_getFacet().equals("facet x"));
145
b1 = communicator.stringToProxy("id -f \"facet x");
148
catch(Ice.ProxyParseException ex)
153
b1 = communicator.stringToProxy("id -f \'facet x");
156
catch(Ice.ProxyParseException ex)
159
b1 = communicator.stringToProxy("test -f facet:tcp");
160
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
161
b1.ice_getFacet().equals("facet") && b1.ice_getAdapterId().length() == 0);
162
b1 = communicator.stringToProxy("test -f \"facet:tcp\"");
163
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
164
b1.ice_getFacet().equals("facet:tcp") && b1.ice_getAdapterId().length() == 0);
165
b1 = communicator.stringToProxy("test -f facet@test");
166
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
167
b1.ice_getFacet().equals("facet") && b1.ice_getAdapterId().equals("test"));
168
b1 = communicator.stringToProxy("test -f 'facet@test'");
169
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
170
b1.ice_getFacet().equals("facet@test") && b1.ice_getAdapterId().length() == 0);
171
b1 = communicator.stringToProxy("test -f 'facet@test'@test");
172
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
173
b1.ice_getFacet().equals("facet@test") && b1.ice_getAdapterId().equals("test"));
176
b1 = communicator.stringToProxy("test -f facet@test @test");
179
catch(Ice.ProxyParseException ex)
182
b1 = communicator.stringToProxy("test");
183
test(b1.ice_isTwoway());
184
b1 = communicator.stringToProxy("test -t");
185
test(b1.ice_isTwoway());
186
b1 = communicator.stringToProxy("test -o");
187
test(b1.ice_isOneway());
188
b1 = communicator.stringToProxy("test -O");
189
test(b1.ice_isBatchOneway());
190
b1 = communicator.stringToProxy("test -d");
191
test(b1.ice_isDatagram());
192
b1 = communicator.stringToProxy("test -D");
193
test(b1.ice_isBatchDatagram());
194
b1 = communicator.stringToProxy("test");
195
test(!b1.ice_isSecure());
196
b1 = communicator.stringToProxy("test -s");
197
test(b1.ice_isSecure());
201
b1 = communicator.stringToProxy("test:tcp@adapterId");
204
catch(Ice.EndpointParseException ex)
207
// This is an unknown endpoint warning, not a parse exception.
211
// b1 = communicator.stringToProxy("test -f the:facet:tcp");
214
//catch(Ice.EndpointParseException ex)
219
b1 = communicator.stringToProxy("test::tcp");
222
catch(Ice.EndpointParseException ex)
227
out.print("testing propertyToProxy... ");
229
Ice.Properties prop = communicator.getProperties();
230
String propertyPrefix = "Foo.Proxy";
231
prop.setProperty(propertyPrefix, "test:default -p 12010 -t 10000");
232
b1 = communicator.propertyToProxy(propertyPrefix);
233
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
234
b1.ice_getAdapterId().length() == 0 && b1.ice_getFacet().length() == 0);
236
// These two properties don't do anything to direct proxies so
237
// first we test that.
238
String property = propertyPrefix + ".Locator";
239
test(b1.ice_getLocator() == null);
240
prop.setProperty(property, "locator:default -p 10000");
241
b1 = communicator.propertyToProxy(propertyPrefix);
242
test(b1.ice_getLocator() == null);
243
prop.setProperty(property, "");
246
property = propertyPrefix + ".LocatorCacheTimeout";
247
test(b1.ice_getLocatorCacheTimeout() == 0);
248
prop.setProperty(property, "1");
249
b1 = communicator.propertyToProxy(propertyPrefix);
250
test(b1.ice_getLocatorCacheTimeout() == 0);
251
prop.setProperty(property, "");
254
// Now retest with an indirect proxy.
255
prop.setProperty(propertyPrefix, "test");
256
property = propertyPrefix + ".Locator";
257
prop.setProperty(property, "locator:default -p 10000");
258
b1 = communicator.propertyToProxy(propertyPrefix);
259
test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.equals("locator"));
260
prop.setProperty(property, "");
263
property = propertyPrefix + ".LocatorCacheTimeout";
264
test(b1.ice_getLocatorCacheTimeout() == -1);
265
prop.setProperty(property, "1");
266
b1 = communicator.propertyToProxy(propertyPrefix);
267
test(b1.ice_getLocatorCacheTimeout() == 1);
268
prop.setProperty(property, "");
270
// This cannot be tested so easily because the property is cached
271
// on communicator initialization.
273
//prop.setProperty("Ice.Default.LocatorCacheTimeout", "60");
274
//b1 = communicator.propertyToProxy(propertyPrefix);
275
//test(b1.ice_getLocatorCacheTimeout() == 60);
276
//prop.setProperty("Ice.Default.LocatorCacheTimeout", "");
278
prop.setProperty(propertyPrefix, "test:default -p 12010 -t 10000");
281
property = propertyPrefix + ".Router";
282
test(b1.ice_getRouter() == null);
283
prop.setProperty(property, "router:default -p 10000");
284
b1 = communicator.propertyToProxy(propertyPrefix);
285
test(b1.ice_getRouter() != null && b1.ice_getRouter().ice_getIdentity().name.equals("router"));
286
prop.setProperty(property, "");
289
property = propertyPrefix + ".PreferSecure";
290
test(!b1.ice_isPreferSecure());
291
prop.setProperty(property, "1");
292
b1 = communicator.propertyToProxy(propertyPrefix);
293
test(b1.ice_isPreferSecure());
294
prop.setProperty(property, "");
296
property = propertyPrefix + ".ConnectionCached";
297
test(b1.ice_isConnectionCached());
298
prop.setProperty(property, "0");
299
b1 = communicator.propertyToProxy(propertyPrefix);
300
test(!b1.ice_isConnectionCached());
301
prop.setProperty(property, "");
303
property = propertyPrefix + ".EndpointSelection";
304
test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
305
prop.setProperty(property, "Random");
306
b1 = communicator.propertyToProxy(propertyPrefix);
307
test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
308
prop.setProperty(property, "Ordered");
309
b1 = communicator.propertyToProxy(propertyPrefix);
310
test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
311
prop.setProperty(property, "");
313
property = propertyPrefix + ".CollocationOptimization";
314
test(b1.ice_isCollocationOptimized());
315
prop.setProperty(property, "0");
316
b1 = communicator.propertyToProxy(propertyPrefix);
317
test(!b1.ice_isCollocationOptimized());
318
prop.setProperty(property, "");
320
property = propertyPrefix + ".ThreadPerConnection";
321
test(!b1.ice_isThreadPerConnection());
322
prop.setProperty(property, "1");
323
b1 = communicator.propertyToProxy(propertyPrefix);
324
test(b1.ice_isThreadPerConnection());
325
prop.setProperty(property, "");
330
out.print("testing ice_getCommunicator... ");
332
test(base.ice_getCommunicator() == communicator);
335
out.print("testing proxy methods... ");
337
test(communicator.identityToString(
338
base.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()).equals("other"));
339
test(base.ice_facet("facet").ice_getFacet().equals("facet"));
340
test(base.ice_adapterId("id").ice_getAdapterId().equals("id"));
341
test(base.ice_twoway().ice_isTwoway());
342
test(base.ice_oneway().ice_isOneway());
343
test(base.ice_batchOneway().ice_isBatchOneway());
344
test(base.ice_datagram().ice_isDatagram());
345
test(base.ice_batchDatagram().ice_isBatchDatagram());
346
test(base.ice_secure(true).ice_isSecure());
347
test(!base.ice_secure(false).ice_isSecure());
348
//test(base.ice_collocationOptimized(true).ice_isCollocationOptimized());
349
//test(!base.ice_collocationOptimized(false).ice_isCollocationOptimized());
352
out.print("testing proxy comparison... ");
355
test(communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo")));
356
test(!communicator.stringToProxy("foo").equals(communicator.stringToProxy("foo2")));
358
Ice.ObjectPrx compObj = communicator.stringToProxy("foo");
360
test(compObj.ice_facet("facet").equals(compObj.ice_facet("facet")));
361
test(!compObj.ice_facet("facet").equals(compObj.ice_facet("facet1")));
363
test(compObj.ice_oneway().equals(compObj.ice_oneway()));
364
test(!compObj.ice_oneway().equals(compObj.ice_twoway()));
366
test(compObj.ice_secure(true).equals(compObj.ice_secure(true)));
367
test(!compObj.ice_secure(false).equals(compObj.ice_secure(true)));
369
//test(compObj.ice_collocationOptimized(true).equals(compObj.ice_collocationOptimized(true)));
370
//test(!compObj.ice_collocationOptimized(false).equals(compObj.ice_collocationOptimized(true)));
372
//test(compObj.ice_connectionCached(true).equals(compObj.ice_connectionCached(true)));
373
//test(!compObj.ice_connectionCached(false).equals(compObj.ice_connectionCached(true)));
375
//test(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals(
376
//compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random)));
377
//test(!compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).equals(
378
//compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)));
380
//test(compObj.ice_connectionId("id2").equals(compObj.ice_connectionId("id2")));
381
//test(!compObj.ice_connectionId("id1").equals(compObj.ice_connectionId("id2")));
383
//test(compObj.ice_compress(true).equals(compObj.ice_compress(true)));
384
//test(!compObj.ice_compress(false).equals(compObj.ice_compress(true)));
386
test(compObj.ice_timeout(20).equals(compObj.ice_timeout(20)));
387
test(!compObj.ice_timeout(10).equals(compObj.ice_timeout(20)));
389
Ice.ObjectPrx compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000");
390
Ice.ObjectPrx compObj2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001");
391
test(!compObj1.equals(compObj2));
393
compObj1 = communicator.stringToProxy("foo@MyAdapter1");
394
compObj2 = communicator.stringToProxy("foo@MyAdapter2");
395
test(!compObj1.equals(compObj2));
397
//test(compObj1.ice_locatorCacheTimeout(20).equals(compObj1.ice_locatorCacheTimeout(20)));
398
//test(!compObj1.ice_locatorCacheTimeout(10).equals(compObj1.ice_locatorCacheTimeout(20)));
400
compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 1000");
401
compObj2 = communicator.stringToProxy("foo@MyAdapter1");
402
test(!compObj1.equals(compObj2));
405
// TODO: Ideally we should also test comparison of fixed proxies.
409
out.print("testing checked cast... ");
411
Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(base);
413
Test.MyDerivedClassPrx derived = Test.MyDerivedClassPrxHelper.checkedCast(cl);
414
test(derived != null);
415
test(cl.equals(base));
416
test(derived.equals(base));
417
test(cl.equals(derived));
420
out.print("testing checked cast with context... ");
423
java.util.Hashtable c = cl.getContext();
424
test(c == null || c.size() == 0);
426
c = new java.util.Hashtable();
427
c.put("one", "hello");
428
c.put("two", "world");
429
cl = Test.MyClassPrxHelper.checkedCast(base, c);
430
java.util.Hashtable c2 = cl.getContext();
431
test(IceUtil.Hashtable.equals(c, c2));