1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
import Test.*;
public class AllTests
{
private static void
test(boolean b)
{
if(!b)
{
throw new RuntimeException();
}
}
public static GPrx
allTests(Ice.Communicator communicator)
{
System.out.print("testing facet registration exceptions... ");
communicator.getProperties().setProperty("Ice.OA.FacetExceptionTestAdapter.Endpoints", "default");
Ice.ObjectAdapter adapter = communicator.createObjectAdapter("FacetExceptionTestAdapter");
Ice.Object obj = new EmptyI();
adapter.add(obj, communicator.stringToIdentity("d"));
adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
try
{
adapter.addFacet(obj, communicator.stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice.AlreadyRegisteredException ex)
{
}
adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
try
{
adapter.removeFacet(communicator.stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice.NotRegisteredException ex)
{
}
System.out.println("ok");
System.out.print("testing removeAllFacets... ");
Ice.Object obj1 = new EmptyI();
Ice.Object obj2 = new EmptyI();
adapter.addFacet(obj1, communicator.stringToIdentity("id1"), "f1");
adapter.addFacet(obj2, communicator.stringToIdentity("id1"), "f2");
Ice.Object obj3 = new EmptyI();
adapter.addFacet(obj1, communicator.stringToIdentity("id2"), "f1");
adapter.addFacet(obj2, communicator.stringToIdentity("id2"), "f2");
adapter.addFacet(obj3, communicator.stringToIdentity("id2"), "");
java.util.Map fm = adapter.removeAllFacets(communicator.stringToIdentity("id1"));
test(fm.size() == 2);
test(fm.get("f1") == obj1);
test(fm.get("f2") == obj2);
try
{
adapter.removeAllFacets(communicator.stringToIdentity("id1"));
test(false);
}
catch(Ice.NotRegisteredException ex)
{
}
fm = adapter.removeAllFacets(communicator.stringToIdentity("id2"));
test(fm.size() == 3);
test(fm.get("f1") == obj1);
test(fm.get("f2") == obj2);
test(fm.get("") == obj3);
System.out.println("ok");
adapter.deactivate();
System.out.print("testing stringToProxy... ");
System.out.flush();
String ref = "d:default -p 12010 -t 10000";
Ice.ObjectPrx db = communicator.stringToProxy(ref);
test(db != null);
System.out.println("ok");
System.out.print("testing checked cast... ");
System.out.flush();
DPrx d = DPrxHelper.checkedCast(db);
test(d != null);
test(d.equals(db));
System.out.println("ok");
System.out.print("testing non-facets A, B, C, and D... ");
System.out.flush();
test(d.callA().equals("A"));
test(d.callB().equals("B"));
test(d.callC().equals("C"));
test(d.callD().equals("D"));
System.out.println("ok");
System.out.print("testing facets A, B, C, and D... ");
System.out.flush();
DPrx df = DPrxHelper.checkedCast(d, "facetABCD");
test(df != null);
test(df.callA().equals("A"));
test(df.callB().equals("B"));
test(df.callC().equals("C"));
test(df.callD().equals("D"));
System.out.println("ok");
System.out.print("testing facets E and F... ");
System.out.flush();
FPrx ff = FPrxHelper.checkedCast(d, "facetEF");
test(ff != null);
test(ff.callE().equals("E"));
test(ff.callF().equals("F"));
System.out.println("ok");
System.out.print("testing facet G... ");
System.out.flush();
GPrx gf = GPrxHelper.checkedCast(ff, "facetGH");
test(gf != null);
test(gf.callG().equals("G"));
System.out.println("ok");
System.out.print("testing whether casting preserves the facet... ");
System.out.flush();
HPrx hf = HPrxHelper.checkedCast(gf);
test(hf != null);
test(hf.callG().equals("G"));
test(hf.callH().equals("H"));
System.out.println("ok");
return gf;
}
}
|