Package javax.management.relation

Examples of javax.management.relation.RoleInfo


  /**
   * Basic tests
   */
  public void testBasic()
  {
    RoleInfo roleInfo1 = null;
    RoleInfo roleInfo2 = null;
    RoleInfo[] roleInfos = null;
    RelationTypeSupport support = null;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      support = new RelationTypeSupport("name", roleInfos);
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Check the name
    assertEquals("name", support.getRelationTypeName());

    // Check the roleInfos
    ArrayList result = (ArrayList) support.getRoleInfos();
    assertEquals(2, result.size());

    // Check get
    try
    {
      assertEquals(roleInfo1.toString(), support.getRoleInfo("roleInfo1").toString());
      assertEquals(roleInfo2.toString(), support.getRoleInfo("roleInfo2").toString());
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
View Full Code Here


  /**
   * Error handling
   */
  public void testErrorHandling()
  {
    RoleInfo roleInfo1 = null;
    RoleInfo roleInfo2 = null;
    RoleInfo[] roleInfos = null;
    RelationTypeSupport support = null;

    boolean caught = false;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      support = new RelationTypeSupport(null, roleInfos);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null relation type name");

    caught = false;
    try
    {
      support = new RelationTypeSupport("name", null);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null role infos");

    caught = false;
    try
    {
      support = new RelationTypeSupport("name", new RoleInfo[0]);
    }
    catch (InvalidRelationTypeException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts no role infos");

    caught = false;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, null };
      support = new RelationTypeSupport("name", roleInfos);
    }
    catch (InvalidRelationTypeException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null role");

    caught = false;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1 };
      support = new RelationTypeSupport("name", roleInfos);
      support.getRoleInfo(null);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("getRoleInfo allows a null role info name");

    caught = false;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1 };
      support = new RelationTypeSupport("name", roleInfos);
      support.getRoleInfo("rubbish");
    }
    catch (RoleInfoNotFoundException e)
View Full Code Here

   * Test serialization.
   */
  public void testSerialization()
  {
    // Create the relationt type support
    RoleInfo roleInfo1 = null;
    RoleInfo roleInfo2 = null;
    RoleInfo[] roleInfos = null;
    RelationTypeSupport support = null;
    try
    {
      roleInfo1 = new RoleInfo("roleInfo1", RelationSupport.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", RelationSupport.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      support = new RelationTypeSupport("name", roleInfos);
    }
    catch (Exception e)
    {
View Full Code Here

  /**
   * Basic tests.
   */
  public void testBasic()
  {
    RoleInfo roleInfo = null;

    // Minimal Constructor
    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName());
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Did it work?
    assertEquals(roleInfo.getName(), "RoleName");
    assertEquals(roleInfo.getRefMBeanClassName(), RelationSupport.class.getName());
    assertEquals(roleInfo.isReadable(), true);
    assertEquals(roleInfo.isWritable(), true);
    assertEquals(roleInfo.getMinDegree(), 1);
    assertEquals(roleInfo.getMaxDegree(), 1);
    assertEquals(roleInfo.getDescription(), null);

    // Partial Constructor
    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                              false, false);
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Did it work?
    assertEquals(roleInfo.getName(), "RoleName");
    assertEquals(roleInfo.getRefMBeanClassName(), RelationSupport.class.getName());
    assertEquals(roleInfo.isReadable(), false);
    assertEquals(roleInfo.isWritable(), false);
    assertEquals(roleInfo.getMinDegree(), 1);
    assertEquals(roleInfo.getMaxDegree(), 1);
    assertEquals(roleInfo.getDescription(), null);

    // Full Constructor
    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                              false, false, 23, 25, "Description");
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Did it work?
    assertEquals(roleInfo.getName(), "RoleName");
    assertEquals(roleInfo.getRefMBeanClassName(), RelationSupport.class.getName());
    assertEquals(roleInfo.isReadable(), false);
    assertEquals(roleInfo.isWritable(), false);
    assertEquals(roleInfo.getMinDegree(), 23);
    assertEquals(roleInfo.getMaxDegree(), 25);
    assertEquals(roleInfo.getDescription(), "Description");
  }
View Full Code Here

  public void testErrorHandling()
  {
    boolean caught = false;
    try
    {
      new RoleInfo(null);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Copy Constructor accepts null role info");

    caught = false;
    try
    {
      new RoleInfo(null, RelationSupport.class.getName());
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null role name (1)");

    caught = false;
    try
    {
      new RoleInfo(null, RelationSupport.class.getName(), true, true);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null role name (2)");

    caught = false;
    try
    {
      new RoleInfo(null, RelationSupport.class.getName(), true, true,
                              1, 1, "blah");
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null role name (3)");

    caught = false;
    try
    {
      new RoleInfo("RoleName", null);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null class name (1)");

    caught = false;
    try
    {
      new RoleInfo("RoleName", null, true, true);
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null class name (2)");

    caught = false;
    try
    {
      new RoleInfo("RoleName", null, true, true,
                              1, 1, "blah");
    }
    catch (IllegalArgumentException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Constructor accepts null class name (3)");

    caught = false;
    try
    {
      new RoleInfo("RoleName", "Inv alid");
    }
    catch (ClassNotFoundException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught)
      fail("Constructor accepts invalid class name (1) - disabled JMX1.2");

    caught = false;
    try
    {
      new RoleInfo("RoleName", "Inv alid", true, true);
    }
    catch (ClassNotFoundException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught)
      fail("Constructor accepts invalid class name (2) - disabled JMX1.2");

    caught = false;
    try
    {
      new RoleInfo("RoleName", "Inv alid", true, true,
                              1, 1, "blah");
    }
    catch (ClassNotFoundException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught)
      fail("Constructor accepts invalid class name (3) - disabled JMX1.2");

    caught = false;
    try
    {
      new RoleInfo("RoleName", RoleInfo.class.getName());
    }
    catch (NotCompliantMBeanException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught)
      fail("Constructor accepts not compliant mbean (1) - disabled JMX1.2");

    caught = false;
    try
    {
      new RoleInfo("RoleName", RoleInfo.class.getName(), true, true);
    }
    catch (NotCompliantMBeanException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught)
      fail("Constructor accepts not compliant mbean (2) - disabled JMX1.2");

    caught = false;
    try
    {
      new RoleInfo("RoleName", RoleInfo.class.getName(), true, true,
                              1, 1, "blah");
    }
    catch (NotCompliantMBeanException e)
    {
      caught = true;
View Full Code Here

  public void testConstructorCardinality()
  {
    // It's allow by the spec?????
    try
    {
      new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, 0, 0, "Description");
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    boolean caught = false;
    try
    {
      new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, 1, 0, "Description");
    }
    catch (InvalidRoleInfoException e)
    {
      caught = true;
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    if (caught == false)
      fail("Shouldn't allow minimum of 1 and maximum of 0");

    caught = false;
    try
    {
      new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, RoleInfo.ROLE_CARDINALITY_INFINITY,
                            0, "Description");
    }
    catch (InvalidRoleInfoException e)
    {
View Full Code Here

   * Test the degree checkers.
   */
  public void testCheckDegrees()
  {
    // Create the role info
    RoleInfo roleInfo = null;

    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, 23, 25, "Description");
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    assertEquals(true, roleInfo.checkMaxDegree(0));
    assertEquals(true, roleInfo.checkMaxDegree(22));
    assertEquals(true, roleInfo.checkMaxDegree(23));
    assertEquals(true, roleInfo.checkMaxDegree(24));
    assertEquals(true, roleInfo.checkMaxDegree(25));
    assertEquals(false, roleInfo.checkMaxDegree(26));
    assertEquals(false, roleInfo.checkMaxDegree(Integer.MAX_VALUE));

    assertEquals(false, roleInfo.checkMinDegree(0));
    assertEquals(false, roleInfo.checkMinDegree(22));
    assertEquals(true, roleInfo.checkMinDegree(23));
    assertEquals(true, roleInfo.checkMinDegree(24));
    assertEquals(true, roleInfo.checkMinDegree(25));
    assertEquals(true, roleInfo.checkMinDegree(26));
    assertEquals(true, roleInfo.checkMinDegree(Integer.MAX_VALUE));

    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, 25,
                            RoleInfo.ROLE_CARDINALITY_INFINITY, "Description");
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    assertEquals(true, roleInfo.checkMaxDegree(0));
    assertEquals(true, roleInfo.checkMaxDegree(24));
    assertEquals(true, roleInfo.checkMaxDegree(25));
    assertEquals(true, roleInfo.checkMaxDegree(26));
    assertEquals(true, roleInfo.checkMaxDegree(Integer.MAX_VALUE));

    assertEquals(false, roleInfo.checkMinDegree(0));
    assertEquals(false, roleInfo.checkMinDegree(24));
    assertEquals(true, roleInfo.checkMinDegree(25));
    assertEquals(true, roleInfo.checkMinDegree(26));
    assertEquals(true, roleInfo.checkMinDegree(Integer.MAX_VALUE));

    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, RoleInfo.ROLE_CARDINALITY_INFINITY,
                            RoleInfo.ROLE_CARDINALITY_INFINITY, "Description");
    }
    catch (Exception e)
    {
      fail(e.toString());
    }
    assertEquals(true, roleInfo.checkMaxDegree(0));
    assertEquals(true, roleInfo.checkMaxDegree(26));
    assertEquals(true, roleInfo.checkMaxDegree(Integer.MAX_VALUE));

    assertEquals(true, roleInfo.checkMinDegree(0));
    assertEquals(true, roleInfo.checkMinDegree(24));
    assertEquals(true, roleInfo.checkMinDegree(Integer.MAX_VALUE));
  }
View Full Code Here

   * Test copy constructor.
   */
  public void testCopy()
  {
    // Create the role info
    RoleInfo roleInfo = null;
    RoleInfo roleInfo2 = null;

    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                            false, false, 23, 25, "Description");
      roleInfo2 = new RoleInfo(roleInfo);
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Did it work?
    assertEquals(roleInfo.getName(), roleInfo2.getName());
    assertEquals(roleInfo.getRefMBeanClassName(), roleInfo2.getRefMBeanClassName());
    assertEquals(roleInfo.isReadable(), roleInfo2.isReadable());
    assertEquals(roleInfo.isWritable(), roleInfo2.isWritable());
    assertEquals(roleInfo.getMinDegree(), roleInfo2.getMinDegree());
    assertEquals(roleInfo.getMaxDegree(), roleInfo2.getMaxDegree());
    assertEquals(roleInfo.getDescription(), roleInfo2.getDescription());
  }
View Full Code Here

   * Test serialization.
   */
  public void testSerialization()
  {
    // Create the role info
    RoleInfo roleInfo = null;
    RoleInfo roleInfo2 = null;

    try
    {
      roleInfo = new RoleInfo("RoleName", RelationSupport.class.getName(),
                              false, false, 23, 25, "Description");
      // Serialize it
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(roleInfo);
   
      // Deserialize it
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bais);
      roleInfo2 = (RoleInfo) ois.readObject();
    }
    catch (Exception e)
    {
      fail(e.toString());
    }

    // Did it work?
    assertEquals(roleInfo.getName(), roleInfo2.getName());
    assertEquals(roleInfo.getRefMBeanClassName(), roleInfo2.getRefMBeanClassName());
    assertEquals(roleInfo.isReadable(), roleInfo2.isReadable());
    assertEquals(roleInfo.isWritable(), roleInfo2.isWritable());
    assertEquals(roleInfo.getMinDegree(), roleInfo2.getMinDegree());
    assertEquals(roleInfo.getMaxDegree(), roleInfo2.getMaxDegree());
    assertEquals(roleInfo.getDescription(), roleInfo2.getDescription());
  }
View Full Code Here

   /**
    * Test add a relation type
    */
   public void testAddRelationType() throws Exception
   {
      RoleInfo roleInfo1 = null;
      RoleInfo roleInfo2 = null;
      RoleInfo[] roleInfos = null;
      RelationService rs = null;
      ArrayList result = null;
      RoleInfo result1 = null;
      RoleInfo result2 = null;
      roleInfo1 = new RoleInfo("roleInfo1", Trivial.class.getName());
      roleInfo2 = new RoleInfo("roleInfo2", Trivial.class.getName());
      roleInfos = new RoleInfo[] { roleInfo1, roleInfo2 };
      RelationTypeSupport rtsupp = new RelationTypeSupport("RelationTypeName",
                                                  roleInfos);
      rs = new RelationService(true);
      rs.addRelationType(rtsupp);
      result = (ArrayList) rs.getRoleInfos("RelationTypeName");
      result1 = rs.getRoleInfo("RelationTypeName", "roleInfo1");
      result2 = rs.getRoleInfo("RelationTypeName", "roleInfo2");

      // Check the roleInfos
      assertEquals(2, result.size());
      assertEquals(roleInfo1.toString(), result1.toString());
      assertEquals(roleInfo2.toString(), result2.toString());
   }
View Full Code Here

TOP

Related Classes of javax.management.relation.RoleInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.