{
MBeanServer server = MBeanServerFactory.createMBeanServer();
try
{
ObjectName service = createRelationService("test:type=service", server);
RelationService rs = (RelationService) services.get(service);
createRelationTypeB(service);
createRolesB(server);
createRelationTypeC(service);
createRolesC(server);
createRolesCZ(server);
createRolesCZZ(server);
RoleList roles = new RoleList();
roles.add(roleC1);
roles.add(roleC2);
rs.createRelation("relationId", "relationTypeC", roles);
boolean caught = false;
try
{
rs.setRole(null, roleC2);
}
catch(IllegalArgumentException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows null relation id");
caught = false;
try
{
rs.setRole("relationId", null);
}
catch(IllegalArgumentException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows null role");
caught = false;
try
{
rs.setRole("rubbish", roleC2);
}
catch(RelationNotFoundException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows invalid relation id");
caught = false;
try
{
rs.setRole("relationId", roleB1);
}
catch(RoleNotFoundException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows invalid role name");
caught = false;
try
{
rs.setRole("relationId", roleC1);
}
catch(RoleNotFoundException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows non-writable role");
caught = false;
try
{
rs.setRole("relationId", roleCZ2);
}
catch(InvalidRoleValueException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows a role below the minimum");
caught = false;
try
{
rs.setRole("relationId", roleCZZ);
}
catch(InvalidRoleValueException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows a role above the maximum");
caught = false;
try
{
rs.setRole("relationId", roleCZZZ);
}
catch(InvalidRoleValueException e)
{
caught = true;
}
if (caught == false)
fail("setRole allows a role with unregistered beans");
server.unregisterMBean(service);
caught = false;
try
{
rs.setRole("relationId", roleC2);
}
catch(RelationServiceNotRegisteredException e)
{
caught = true;
}