Java 类javax.management.relation.InvalidRelationIdException 实例源码

项目:freeVM    文件:StructureTest.java   
public Result testIdAlreadyUsed() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        rService.createRelation("relation", "relationType", unitRoles);

        /* now try to create another relation with the same name */
        /* create another relation type for clearance */
        rService.createRelationType("another relationType", rInfo);

        try {
            rService.createRelation("relation", "another relationType",
                    unitRoles);
            return failed("");
        } catch (InvalidRelationIdException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }