User: ejort   
  Date: 02/03/15 12:26:40

  Modified:    src/main/javax/management/relation RelationService.java
                        RelationServiceMBean.java RelationTypeSupport.java
                        Role.java RoleList.java RoleUnresolved.java
                        RoleUnresolvedList.java RoleValidator.java
  Log:
  More tests, completed basic unit tests RelationService and Query
  
  Revision  Changes    Path
  1.6       +82 -6     jmx/src/main/javax/management/relation/RelationService.java
  
  Index: RelationService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/relation/RelationService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RelationService.java      11 Mar 2002 18:21:31 -0000      1.5
  +++ RelationService.java      15 Mar 2002 20:26:40 -0000      1.6
  @@ -42,11 +42,16 @@
    * <li>Unregistered mbeans should only contain relation mbeans
    * <li>Unregister notifications not working after change to MBean Filter
    * </ul>
  + * <p><b>20020312 Adrian Brock:</b>
  + * <ul>
  + * <li>Fixed wrong exception types thrown and missing exceptions
  + * <li>Allow null role list in createRelation
  + * </ul>
    *
    * @see RelationServiceMBean
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class RelationService
     extends NotificationBroadcasterSupport
  @@ -141,12 +146,13 @@
       throws IllegalArgumentException, NoSuchMethodException,
              RelationServiceNotRegisteredException, InvalidRelationIdException,
              InvalidRelationServiceException, RelationTypeNotFoundException,
  -           InvalidRoleValueException, RoleNotFoundException
  +           InvalidRoleValueException, RoleNotFoundException,
  +           InstanceNotFoundException
     {
       // Check we have a relation
  -    isActive();
       if (relation == null)
         throw new IllegalArgumentException("null relation");
  +    isActive();
   
       // Get the information we need from the relation
       ObjectName otherService = null;
  @@ -164,6 +170,10 @@
         roleList = (RoleList) server.invoke(relation, "retrieveAllRoles",
                                             new Object[0], new String[0]);
       }
  +    catch (InstanceNotFoundException e)
  +    {
  +       throw e;
  +    }
       catch (Exception e)
       {
         throw new NoSuchMethodException("Not a relation or not registered");
  @@ -200,7 +210,7 @@
       {
         String name = relationType.getRelationTypeName();
         if (typesByName.containsKey(name))
  -        throw new IllegalArgumentException("duplicate relation id");
  +        throw new InvalidRelationTypeException("duplicate relation id: " + name);
         validateRelationType(relationType);
         typesByName.put(name, relationType);
       }
  @@ -209,6 +219,9 @@
     public Integer checkRoleReading(String roleName, String relationTypeName)
       throws IllegalArgumentException, RelationTypeNotFoundException
     {
  +    if (roleName == null)
  +       throw new IllegalArgumentException("Null role name");
  +
       // Get the relation type
       RelationType relationType = retrieveRelationTypeForName(relationTypeName);
   
  @@ -235,6 +248,11 @@
                                     Boolean initFlag)
       throws IllegalArgumentException, RelationTypeNotFoundException
     {
  +    if (role == null)
  +       throw new IllegalArgumentException("Null role name");
  +    if (initFlag == null)
  +       throw new IllegalArgumentException("Null init flag");
  +
       // Get the relation type
       RelationType relationType = retrieveRelationTypeForName(relationTypeName);
   
  @@ -265,7 +283,11 @@
              RoleNotFoundException
     {
       // Take a copy of the role list
  -    RoleList copy = new RoleList(roleList);
  +    RoleList copy = null;
  +    if (roleList != null)
  +       copy = new RoleList(roleList);
  +    else
  +       copy = new RoleList();
   
       // Create a relation
       isActive();
  @@ -295,7 +317,8 @@
       synchronized (typesByName)
       {
         if (typesByName.containsKey(relationTypeName))
  -        throw new IllegalArgumentException("duplicate relation id");
  +        throw new InvalidRelationTypeException("duplicate relation id: "
  +                                               + relationTypeName);
         RelationType relationType = new RelationTypeSupport(relationTypeName,
                                                             roleInfos);
         typesByName.put(relationTypeName, relationType);
  @@ -636,6 +659,46 @@
       return relationType.getRoleInfos();
     }
   
  +  public RoleResult getRoles(String relationId, String[] roleNames)
  +    throws IllegalArgumentException, RelationNotFoundException,
  +           RelationServiceNotRegisteredException
  +  {
  +    // Get the relation object name
  +    if (roleNames == null)
  +      throw new IllegalArgumentException("null role names");
  +    isActive();
  +    Object relation = retrieveRelationForId(relationId);
  +    
  +    // Ask the relation for the role value
  +    if (relation instanceof RelationSupport)
  +    {
  +      return ((RelationSupport) relation).getRoles(roleNames);
  +    }
  +    else
  +    {
  +      ObjectName objectName = (ObjectName) relation;
  +      try
  +      {
  +        RoleResult result = (RoleResult) server.invoke(objectName, "getRoles",
  +        new Object[] { roleNames },
  +        new String[] { new String[0].getClass().getName() });
  +        return result;
  +      }
  +      catch (InstanceNotFoundException e)
  +      {
  +        throw new RelationNotFoundException(objectName.toString());
  +      }
  +      catch (MBeanException e)
  +      {
  +        throw new RuntimeException(e.toString());
  +      }
  +      catch (ReflectionException e)
  +      {
  +        throw new RuntimeException(e.toString());
  +      }
  +    }
  +  }
  +
     public Boolean hasRelation(String relationId)
       throws IllegalArgumentException
     {
  @@ -665,6 +728,8 @@
       if (relationId == null)
         throw new IllegalArgumentException("null relation id");
       Object result = relationsById.get(relationId);
  +    if (result == null)
  +       throw new RelationNotFoundException(relationId);
       if (result instanceof ObjectName)
          return (ObjectName) result;
       else
  @@ -915,6 +980,12 @@
         type = RelationNotification.RELATION_MBEAN_UPDATE;
         description = "Update of external relation.";
       }
  +    if (newRole == null)
  +       throw new IllegalArgumentException("null role");
  +
  +    if (oldRoleValue == null)
  +       throw new IllegalArgumentException("null old role value");
  +
       // Send the notification
       sendNotification(type, description, relationId, null, newRole, oldRoleValue);
     }
  @@ -1037,6 +1108,9 @@
         throw new IllegalArgumentException("null old role value");
       isActive();
   
  +    if (relationsById.containsKey(relationId) == false)
  +      throw new RelationNotFoundException("Invalid relation id: " + relationId);
  +
       // Get the role name and new Value
       String roleName = newRole.getRoleName();
       ArrayList newRoleValue = (ArrayList) newRole.getRoleValue();
  @@ -1278,6 +1352,8 @@
     private RelationType retrieveRelationTypeForName(String relationTypeName)
       throws IllegalArgumentException, RelationTypeNotFoundException
     {
  +    if (relationTypeName == null)
  +       throw new IllegalArgumentException("Null relation type name");
       // Get the relation type
       RelationType result = (RelationType) typesByName.get(relationTypeName);
       if (result == null)
  
  
  
  1.5       +29 -2     jmx/src/main/javax/management/relation/RelationServiceMBean.java
  
  Index: RelationServiceMBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/relation/RelationServiceMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RelationServiceMBean.java 1 Mar 2002 19:25:57 -0000       1.4
  +++ RelationServiceMBean.java 15 Mar 2002 20:26:40 -0000      1.5
  @@ -9,6 +9,7 @@
   import java.util.List;
   import java.util.Map;
   
  +import javax.management.InstanceNotFoundException;
   import javax.management.ObjectName;
   
   /**
  @@ -21,8 +22,15 @@
    * in their relation types/roles.<br>
    * Allowing relations to be queried.
    *
  + * <p><b>Revisions:</b>
  + * <p><b>20020312 Adrian Brock:</b>
  + * <ul>
  + * <li>Fixed wrong exception types thrown
  + * <li>Add missing method getRoles(String, String[])
  + * </ul>
  + *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public interface RelationServiceMBean
   {
  @@ -42,6 +50,8 @@
       *            Relation interface.
       * @exception RelationServiceNotRegisteredException when the relation
       *            service is not registered with the MBeanServer.
  +    * @exception InstanceNotFoundException when the relation is not
  +    *            registered in the MBeanServer.
       * @exception InvalidRelationIdException if the relation id 
       *            is already used by another relation.
       * @exception InvalidRelationServiceException if the relation service in 
  @@ -61,7 +71,8 @@
        throws IllegalArgumentException, NoSuchMethodException,
               RelationServiceNotRegisteredException, InvalidRelationIdException,
               InvalidRelationServiceException, RelationTypeNotFoundException,
  -            InvalidRoleValueException, RoleNotFoundException;
  +            InvalidRoleValueException, RoleNotFoundException,
  +            InstanceNotFoundException;
   
      /**
       * Add a relation type to the relation service. 
  @@ -329,6 +340,22 @@
       */
      public List getRoleInfos(String relationTypeName)
        throws IllegalArgumentException, RelationTypeNotFoundException;
  +
  +   /**
  +    * Retrieves selected roles for a relation.
  +    *
  +    * @param relationId the relation id
  +    * @param roleNames an array of role name
  +    * @return a RoleResult containing resolved and unresolved roles.
  +    * @exception IllegalArgumentException for a null parameter.
  +    * @exception RelationNotFoundException when the relation id does not
  +    *            exist.
  +    * @exception RelationServiceNotRegisteredException when the relation 
  +    *            service is not registered with an MBeanServer.
  +    */
  +   public RoleResult getRoles(String relationId, String[] roleNames)
  +     throws IllegalArgumentException, RelationNotFoundException,
  +            RelationServiceNotRegisteredException;
   
      /**
       * Checks whether the relation service has the passed relation id.
  
  
  
  1.4       +9 -2      jmx/src/main/javax/management/relation/RelationTypeSupport.java
  
  Index: RelationTypeSupport.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/relation/RelationTypeSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RelationTypeSupport.java  8 Feb 2002 21:17:54 -0000       1.3
  +++ RelationTypeSupport.java  15 Mar 2002 20:26:40 -0000      1.4
  @@ -15,10 +15,15 @@
    * This class can be used to implement relation types.<p>
    *
    * It holds RoleInfo objects for all roles in the relation.
  + *
  + * <p><b>Revisions:</b>
  + * <p><b>20020312 Adrian Brock:</b>
  + * <ul>
  + * <li>Fixed error handling for getRoleInfo
  + * </ul>
    * 
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
  - * @version $Revision: 1.3 $
  - *
  + * @version $Revision: 1.4 $
    */
   public class RelationTypeSupport
     implements RelationType
  @@ -108,6 +113,8 @@
     public RoleInfo getRoleInfo(String roleInfoName)
       throws RoleInfoNotFoundException
     {
  +    if (roleInfoName == null)
  +       throw new IllegalArgumentException("Null role info name");
       RoleInfo result = null;
       ArrayList temp = new ArrayList(roleInfos);
       Iterator iterator = temp.iterator();
  
  
  
  1.4       +3 -1      jmx/src/main/javax/management/relation/Role.java
  
  Index: Role.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/Role.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Role.java 8 Feb 2002 21:17:54 -0000       1.3
  +++ Role.java 15 Mar 2002 20:26:40 -0000      1.4
  @@ -17,7 +17,7 @@
    * the MBeans in the role.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class Role
     implements Serializable
  @@ -139,6 +139,8 @@
   
      /**
       * Clones the object.
  +    *
  +    * @info.todo shouldn't use the copy constructor?
       *
       * @return a copy of the role
       */
  
  
  
  1.4       +8 -2      jmx/src/main/javax/management/relation/RoleList.java
  
  Index: RoleList.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleList.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RoleList.java     8 Feb 2002 21:17:54 -0000       1.3
  +++ RoleList.java     15 Mar 2002 20:26:40 -0000      1.4
  @@ -16,8 +16,14 @@
    * I think the idea is supposed to be that only roles should be in the
    * list. But this isn't true.
    *
  + * <p><b>Revisions:</b>
  + * <p><b>20020313 Adrian Brock:</b>
  + * <ul>
  + * <li>Fix the cloning
  + * </ul>
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class RoleList
     extends ArrayList
  @@ -172,7 +178,7 @@
       */
      public Object clone()
      {
  -     return new RoleList(this);
  +       return super.clone();
      }
   }
   
  
  
  
  1.4       +3 -1      jmx/src/main/javax/management/relation/RoleUnresolved.java
  
  Index: RoleUnresolved.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleUnresolved.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RoleUnresolved.java       8 Feb 2002 21:17:54 -0000       1.3
  +++ RoleUnresolved.java       15 Mar 2002 20:26:40 -0000      1.4
  @@ -18,7 +18,7 @@
    * was passed and the problem type.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class RoleUnresolved
     implements Serializable
  @@ -145,6 +145,8 @@
   
      /**
       * Clones the object.
  +    *
  +    * @info.todo shouldn't use the copy constructor?
       */
      public Object clone()
      {
  
  
  
  1.4       +8 -2      jmx/src/main/javax/management/relation/RoleUnresolvedList.java
  
  Index: RoleUnresolvedList.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jmx/src/main/javax/management/relation/RoleUnresolvedList.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RoleUnresolvedList.java   8 Feb 2002 21:17:54 -0000       1.3
  +++ RoleUnresolvedList.java   15 Mar 2002 20:26:40 -0000      1.4
  @@ -13,8 +13,14 @@
   /**
    * A list of unresolved roles.
    *
  + * <p><b>Revisions:</b>
  + * <p><b>20020313 Adrian Brock:</b>
  + * <ul>
  + * <li>Fix the cloning
  + * </ul>
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class RoleUnresolvedList
     extends ArrayList
  @@ -171,7 +177,7 @@
       */
      public Object clone()
      {
  -     return new RoleUnresolvedList(this);
  +      return super.clone();
      }
   }
   
  
  
  
  1.3       +6 -1      jmx/src/main/javax/management/relation/RoleValidator.java
  
  Index: RoleValidator.java
  ===================================================================
  RCS file: /cvsroot/jboss/jmx/src/main/javax/management/relation/RoleValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RoleValidator.java        11 Mar 2002 18:21:31 -0000      1.2
  +++ RoleValidator.java        15 Mar 2002 20:26:40 -0000      1.3
  @@ -24,10 +24,11 @@
    * <p><b>20020311 Adrian Brock:</b>
    * <ul>
    * <li>ValidateRole always failed
  + * <li>Throws wrong exception when not writable
    * </ul>
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    *
    */
   class RoleValidator
  @@ -172,6 +173,8 @@
   
       if (status == RoleStatus.NO_ROLE_WITH_NAME)
         throw new RoleNotFoundException(role.getRoleName());
  +    if (status == RoleStatus.ROLE_NOT_WRITABLE)
  +      throw new RoleNotFoundException(role.getRoleName() + " not writable");
       else if (status != 0)
         throw new InvalidRoleValueException(role.getRoleName());
     }
  @@ -222,6 +225,8 @@
         int status = unresolved.getProblemType();
         if (status == RoleStatus.NO_ROLE_WITH_NAME)
           throw new RoleNotFoundException(unresolved.getRoleName());
  +      if (status == RoleStatus.ROLE_NOT_WRITABLE)
  +        throw new RoleNotFoundException(unresolved.getRoleName() + " not writable");
         else
           throw new InvalidRoleValueException(unresolved.getRoleName());
       }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to