{
MBeanServer server = MBeanServerFactory.createMBeanServer();
try
{
ObjectName service = createRelationService("test:type=service", null);
RelationService rs = (RelationService) services.get(service);
createRelationTypeB(service);
createRolesB(server);
RelationSupport support = null;
ObjectName name = null;
support = new RelationSupport("id", service, server, "relationTypeB",
rolesB);
name = new ObjectName("test:type=relation");
server.registerMBean(support, name);
boolean caught = false;
try
{
rs.addRelation(null);
}
catch (IllegalArgumentException e)
{
caught = true;
}
if (caught == false)
fail("addRelation allows null relation");
caught = false;
try
{
rs.addRelation(name);
}
catch (RelationServiceNotRegisteredException e)
{
caught = true;
}
if (caught == false)
fail("addRelation allowed when not registered");
ObjectName badRelation = null;
server.registerMBean(rs, service);
badRelation = new ObjectName("test:type=bad");
server.registerMBean(new Trivial(), badRelation);
caught = false;
try
{
rs.addRelation(badRelation);
}
catch (NoSuchMethodException e)
{
caught = true;
}
if (caught == false)
fail("addRelation allowed when not a relation");
caught = false;
try
{
rs.addRelation(name);
rs.addRelation(name);
}
catch (InvalidRelationIdException e)
{
caught = true;
}
if (caught == false)
fail("addRelation allows duplicate relation ids");
rs.removeRelation("id");
server.unregisterMBean(name);
caught = false;
try
{
rs.addRelation(name);
}
catch (InstanceNotFoundException e)
{
caught = true;
}
if (caught == false)
fail("addRelation allows unregistered relation");
ObjectName service2 = createRelationService("test:type=service2", null);
RelationService rs2 = (RelationService) services.get(service);
createRelationTypeB(service2);
RelationSupport support2 = null;
ObjectName name2 = null;
support = new RelationSupport("id", service2, server, "relationTypeB",
rolesB);