KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > poa > Deactivate


1 package org.jacorb.test.poa;
2
3 import org.omg.CORBA.*;
4 import org.omg.PortableServer.*;
5 import org.omg.PortableServer.POAPackage.*;
6 import junit.framework.*;
7
8
9 public class Deactivate extends TestCase
10 {
11    public Deactivate (String JavaDoc name)
12    {
13       super (name);
14    }
15
16    public static Test suite()
17    {
18       TestSuite suite = new TestSuite ("Deactivation");
19
20       suite.addTest (new Deactivate ("test_deactivate"));
21
22       return suite;
23    }
24
25    public static void test_deactivate ()
26    {
27       ORB orb = null;
28       POA root, system = null;
29       byte[] id1, id2;
30
31       try
32       {
33          orb = ORB.init(new String JavaDoc[0], null);
34          root = POAHelper.narrow(orb.resolve_initial_references( "RootPOA" ));
35
36          // create POA
37
Policy policies[] = new Policy[3];
38          policies[0] = root.create_id_assignment_policy(
39             org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
40          policies[1] = root.create_id_uniqueness_policy(
41             org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
42          policies[2] = root.create_servant_retention_policy(
43             org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
44
45          system = root.create_POA("system_id", root.the_POAManager(), policies);
46       }
47       catch(AdapterAlreadyExists ex)
48       {
49          fail( "unexpected exception: " + ex );
50       }
51       catch(InvalidPolicy ex)
52       {
53          fail( "unexpected exception: " + ex );
54       }
55       catch(Exception JavaDoc ex)
56       {
57          fail( "unexpected exception: " + ex );
58       }
59
60       // create Servants
61
Test_impl servant1 = new Test_impl();
62       Test_impl servant2 = new Test_impl();
63       // first activate servants
64
try
65       {
66          id1 = system.activate_object(servant1);
67          id2 = system.activate_object(servant2);
68
69          // deactivate the servants now
70
// no request is pending
71
try
72          {
73             system.deactivate_object(id2);
74             system.deactivate_object(id1);
75
76             // now again try to deactivate
77
// I would expect ObjectNotActive Exception but didn't get one
78
try
79             {
80                system.deactivate_object(id1);
81                fail( "deactivate_object called twice, expecting ObjectNotActive exception, but didn't");
82             }
83             catch(ObjectNotActive ex)
84             {
85                System.out.println("Success - caught ObjectNotActive");
86             }
87             catch(WrongPolicy ex)
88             {
89                fail( "unexpected exception: " + ex );
90             }
91          }
92          catch(ObjectNotActive ex)
93          {
94             fail( "unexpected exception: " + ex );
95          }
96          catch(WrongPolicy ex)
97          {
98             fail( "unexpected exception: " + ex );
99          }
100       }
101       catch(ServantAlreadyActive ex)
102       {
103          fail( "unexpected exception: " + ex );
104       }
105       catch(WrongPolicy ex)
106       {
107          fail( "unexpected exception: " + ex );
108       }
109    }
110 }
111
Popular Tags