1 package org.jacorb.test.poa; 2 3 22 23 import junit.framework.*; 24 import junit.extensions.TestSetup; 25 import org.jacorb.test.common.ORBSetup; 26 import org.jacorb.test.orb.BasicServerImpl; 27 import org.omg.PortableServer.POA ; 28 import org.omg.PortableServer.POAHelper ; 29 30 import org.omg.PortableServer.*; 31 import org.omg.PortableServer.POAPackage.*; 32 import org.omg.CORBA.*; 33 34 41 public class POAActivateTest extends TestCase 42 { 43 46 private static org.omg.CORBA.ORB orb = null; 47 48 49 54 public POAActivateTest (String name) 55 { 56 super (name); 57 } 58 59 60 65 public static Test suite () 66 { 67 TestSuite suite = new TestSuite ("POA Activation/Deactivation Tests"); 68 Setup setup = new Setup( suite ); 69 ORBSetup osetup = new ORBSetup( setup ); 70 71 suite.addTest (new POAActivateTest ("testActivateDeactivate1")); 72 suite.addTest (new POAActivateTest ("testActivateDeactivate2")); 73 suite.addTest (new POAActivateTest ("testActivateDeactivate3")); 74 75 return osetup; 76 } 77 78 79 84 public void testActivateDeactivate1 () 85 { 86 try 87 { 88 POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 89 90 poa.the_POAManager().activate(); 91 92 BasicServerImpl soi = new BasicServerImpl(); 93 94 for (int count=0;count<100;count++) 95 { 96 poa.activate_object( soi); 98 poa.deactivate_object(poa.servant_to_id(soi)); 100 } 101 } 102 catch( Exception e ) 103 { 104 fail( "unexpected exception: " + e ); 105 } 106 } 107 108 109 113 public void testActivateDeactivate2 () 114 { 115 try 116 { 117 POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 118 119 poa.the_POAManager().activate(); 120 121 BasicServerImpl soi = new BasicServerImpl(); 122 123 byte []id = poa.servant_to_id( soi ); 125 126 for (int count=0;count<100;count++) 127 { 128 poa.deactivate_object(id); 129 poa.activate_object_with_id(id, soi); 130 } 131 } 132 catch( Exception e ) 133 { 134 fail( "unexpected exception: " + e ); 135 } 136 } 137 138 139 143 public void testActivateDeactivate3 () 144 { 145 try 146 { 147 POA rootPoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 148 149 Policy policies[] = new Policy[3]; 151 policies[0] = rootPoa.create_id_assignment_policy( 152 org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID); 153 policies[1] = rootPoa.create_id_uniqueness_policy( 154 org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); 155 policies[2] = rootPoa.create_servant_retention_policy( 156 org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); 157 158 POA poa = rootPoa.create_POA("system_id", rootPoa.the_POAManager(), policies); 159 160 BasicServerImpl soi = new BasicServerImpl(); 161 162 byte [] id = poa.activate_object(soi); 163 164 for (int count=0;count<100;count++) 165 { 166 poa.deactivate_object(id); 167 poa.activate_object_with_id( id, soi); 168 } 169 } 170 catch( Exception e ) 171 { 172 e.printStackTrace(); 173 fail( "unexpected exception: " + e ); 174 } 175 } 176 177 178 179 180 183 private static class Setup extends TestSetup 184 { 185 190 public Setup (Test test) 191 { 192 super (test); 193 } 194 195 198 protected void setUp () 199 { 200 org.omg.CORBA.Object obj = null; 201 202 orb = ORBSetup.getORB (); 203 } 204 205 208 protected void tearDown () 209 { 210 } 211 } 212 } 213 | Popular Tags |