}
void uTestIdToServant(ORB orb, POA root)
{
org.omg.CORBA.Object obj;
POA retain;
POA defaultPOA;
byte[] id1;
byte[] id2;
byte[] tmpid;
Policy[] policies;
Test_impl def;
Test_impl servant1;
Test_impl servant2;
Servant tmpservant;
POAManager manager = root.the_POAManager();
//
// Create POA w/ RETAIN
//
policies = new Policy[ 3 ];
policies [ 0 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
policies [ 1 ] =
root.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT);
policies [ 2 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
try
{
retain = root.create_POA("retain", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Create POA w/ USE_DEFAULT_SERVANT
//
policies = new Policy[ 5 ];
policies [ 0 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
policies [ 1 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
policies [ 2 ] =
root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
policies [ 3 ] =
root.create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.TRANSIENT);
policies [ 4 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
try
{
defaultPOA = root.create_POA("default", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
def = new Test_impl(orb, "default", false);
try
{
defaultPOA.set_servant(def);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
servant1 = new Test_impl(orb, "test1", false);
servant2 = new Test_impl(orb, "test2", false);
//
// Test: ObjectNotActive exception
//
try
{
tmpid = ("bad_id").getBytes();
retain.id_to_servant(tmpid);
TEST(false); // id_to_servant should not have succeeded
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
id1 = ("test1").getBytes();
id2 = ("test2").getBytes();
try
{
retain.activate_object_with_id(id1, servant1);
retain.activate_object_with_id(id2, servant2);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectAlreadyActive ex)
{
ex.printStackTrace();
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: servant_to_id (RETAIN policy)
//
try
{
tmpservant = retain.id_to_servant(id1);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(servant1 == tmpservant);
try
{
tmpservant = retain.id_to_servant(id2);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(servant2 == tmpservant);
//
// Test: id_to_servant (USE_DEFAULT_SERVANT)
//
try
{
defaultPOA.activate_object_with_id(id1, servant1);
defaultPOA.activate_object_with_id(id2, servant2);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
tmpservant = defaultPOA.id_to_servant(id1);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(servant1 == tmpservant);
try
{
tmpservant = defaultPOA.id_to_servant(id2);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(servant2 == tmpservant);
retain.destroy(true, true);
defaultPOA.destroy(true, true);
}