cvs commit: spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks AddToPluginSetTaskTestCase.java MockProject.java PluginSetTestCase.java

Peter Donald <[email protected]> Thu, 20 Nov 2003 04:00:39 -0600
Newsgroups gmane.comp.java.spice.cvs
Message-ID <[email protected]>
pdonald     2003/11/20 04:00:39

  Modified:    sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks
                        MockProject.java PluginSetTestCase.java
  Added:       sandbox/metaclass/src/java/org/realityforge/metaclass/tools/tasks
                        AddToFilterSetTask.java
                        AddToInterceptorSetTask.java
                        AddToPluginSetTask.java
               sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks
                        AddToPluginSetTaskTestCase.java
  Log:
  Add tasks to add one pluginSet to another
  
  Revision  Changes    Path
  1.1                  spice/sandbox/metaclass/src/java/org/realityforge/metaclass/tools/tasks/AddToFilterSetTask.java
  
  Index: AddToFilterSetTask.java
  ===================================================================
  /*
   * Copyright (C) The Spice Group. All rights reserved.
   *
   * This software is published under the terms of the Spice
   * Software License version 1.1, a copy of which has been included
   * with this distribution in the LICENSE.txt file.
   */
  package org.realityforge.metaclass.tools.tasks;
  
  /**
   * Task to add one FilterSet to another.
   *
   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/11/20 10:00:38 $
   */
  public class AddToFilterSetTask
      extends AddToPluginSetTask
  {
      /**
       * Create task.
       */
      public AddToFilterSetTask()
      {
          super( FilterSet.class );
      }
  }
  
  
  
  1.1                  spice/sandbox/metaclass/src/java/org/realityforge/metaclass/tools/tasks/AddToInterceptorSetTask.java
  
  Index: AddToInterceptorSetTask.java
  ===================================================================
  /*
   * Copyright (C) The Spice Group. All rights reserved.
   *
   * This software is published under the terms of the Spice
   * Software License version 1.1, a copy of which has been included
   * with this distribution in the LICENSE.txt file.
   */
  package org.realityforge.metaclass.tools.tasks;
  
  /**
   * Task to add one InterceptorSet to another.
   *
   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/11/20 10:00:38 $
   */
  public class AddToInterceptorSetTask
      extends AddToPluginSetTask
  {
      /**
       * Create task.
       */
      public AddToInterceptorSetTask()
      {
          super( InterceptorSet.class );
      }
  }
  
  
  
  1.1                  spice/sandbox/metaclass/src/java/org/realityforge/metaclass/tools/tasks/AddToPluginSetTask.java
  
  Index: AddToPluginSetTask.java
  ===================================================================
  /*
   * Copyright (C) The Spice Group. All rights reserved.
   *
   * This software is published under the terms of the Spice
   * Software License version 1.1, a copy of which has been included
   * with this distribution in the LICENSE.txt file.
   */
  package org.realityforge.metaclass.tools.tasks;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  
  /**
   * An ant task to add one plugin set to another.
   *
   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/11/20 10:00:38 $
   */
  abstract class AddToPluginSetTask
      extends Task
  {
      /**
       * The rexpected type of plugin.
       */
      private Class m_type;
  
      /**
       * The PluginSet that will be added to.
       */
      private String m_id;
  
      /**
       * The PluginSet that will be added.
       */
      private String m_refid;
  
      /**
       * Create task.
       *
       * @param type the expected type of PluginSet.
       */
      AddToPluginSetTask( final Class type )
      {
          m_type = type;
      }
  
      /**
       * Set the id for PluginSet to add to.
       *
       * @param id the id for PluginSet to add to.
       */
      public void setId( final String id )
      {
          m_id = id;
      }
  
      /**
       * Set the id of PluginSet that will be added.
       *
       * @param refid the id of PluginSet that will be added.
       */
      public void setRefid( final String refid )
      {
          m_refid = refid;
      }
  
      /**
       * Join PluginSets.
       *
       * @throws BuildException if bad ids specified
       */
      public void execute()
          throws BuildException
      {
          validate();
          final Object idObject = getProject().getReference( m_id );
          final Object refidObject = getProject().getReference( m_refid );
  
          if( !m_type.isInstance( idObject ) )
          {
              final String message =
                  "Object referenced by id is not a " +
                  m_type.getName();
              throw new BuildException( message );
          }
          if( !m_type.isInstance( refidObject ) )
          {
              final String message =
                  "Object referenced by refid is not a " +
                  m_type.getName();
              throw new BuildException( message );
          }
  
          final PluginSet base = (PluginSet)idObject;
          final PluginSet other = (PluginSet)refidObject;
          base.addPluginSet( other );
      }
  
      /**
       * Validate correct attributes have been specified.
       */
      void validate()
      {
          if( null == m_id )
          {
              throw new BuildException( "id not specified" );
          }
          if( null == m_refid )
          {
              throw new BuildException( "refid not specified" );
          }
      }
  }
  
  
  
  1.2       +7 -5      spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks/MockProject.java
  
  Index: MockProject.java
  ===================================================================
  RCS file: /scm/cvs/spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks/MockProject.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MockProject.java	20 Nov 2003 06:42:49 -0000	1.1
  +++ MockProject.java	20 Nov 2003 10:00:39 -0000	1.2
  @@ -7,25 +7,27 @@
    */
   package org.realityforge.metaclass.tools.tasks;
   
  +import java.util.HashMap;
   import org.apache.tools.ant.Project;
   
   /**
    *
    * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2003/11/20 06:42:49 $
  + * @version $Revision: 1.2 $ $Date: 2003/11/20 10:00:39 $
    */
   class MockProject
       extends Project
   {
  -    private final Object m_reference;
  +    private final HashMap m_references = new HashMap();
   
  -    MockProject( final Object reference )
  +    void bindReference( final String key,
  +                        final Object value )
       {
  -        m_reference = reference;
  +        m_references.put( key, value );
       }
   
       public Object getReference( final String key )
       {
  -        return m_reference;
  +        return m_references.get( key );
       }
   }
  
  
  
  1.2       +7 -4      spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks/PluginSetTestCase.java
  
  Index: PluginSetTestCase.java
  ===================================================================
  RCS file: /scm/cvs/spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks/PluginSetTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluginSetTestCase.java	20 Nov 2003 06:42:50 -0000	1.1
  +++ PluginSetTestCase.java	20 Nov 2003 10:00:39 -0000	1.2
  @@ -15,7 +15,7 @@
   /**
    *
    * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2003/11/20 06:42:50 $
  + * @version $Revision: 1.2 $ $Date: 2003/11/20 10:00:39 $
    */
   public class PluginSetTestCase
       extends TestCase
  @@ -74,7 +74,8 @@
           final FilterSet set = new FilterSet();
           set.addFilter( element );
           final FilterSet parent = new FilterSet();
  -        final MockProject project = new MockProject( set );
  +        final MockProject project = new MockProject();
  +        project.bindReference( "bar", set );
           parent.setProject( project );
           parent.setRefid( new Reference( "bar" ) );
   
  @@ -89,7 +90,8 @@
           throws Exception
       {
           final FilterSet parent = new FilterSet();
  -        final MockProject project = new MockProject( new Object() );
  +        final MockProject project = new MockProject();
  +        project.bindReference( "bar", new Object() );
           parent.setProject( project );
           try
           {
  @@ -111,7 +113,8 @@
           element.setName( "foo" );
           parent.addInterceptor( element );
           parent.addInterceptorSet( new InterceptorSet() );
  -        final MockProject project = new MockProject( new Object() );
  +        final MockProject project = new MockProject();
  +        project.bindReference( "bar", new InterceptorSet() );
           parent.setProject( project );
           try
           {
  
  
  
  1.1                  spice/sandbox/metaclass/src/test/org/realityforge/metaclass/tools/tasks/AddToPluginSetTaskTestCase.java
  
  Index: AddToPluginSetTaskTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Spice Group. All rights reserved.
   *
   * This software is published under the terms of the Spice
   * Software License version 1.1, a copy of which has been included
   * with this distribution in the LICENSE.txt file.
   */
  package org.realityforge.metaclass.tools.tasks;
  
  import junit.framework.TestCase;
  import org.apache.tools.ant.BuildException;
  import java.util.Collection;
  
  /**
   *
   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/11/20 10:00:39 $
   */
  public class AddToPluginSetTaskTestCase
      extends TestCase
  {
      public void testNullId()
          throws Exception
      {
          final AddToFilterSetTask task = new AddToFilterSetTask();
          task.setId( null );
          task.setRefid( "boo" );
          try
          {
              task.validate();
          }
          catch( final BuildException e )
          {
              return;
          }
          fail( "Expected to fail due to null id" );
      }
  
      public void testNullRefid()
          throws Exception
      {
          final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
          task.setId( "blah" );
          task.setRefid( null );
          try
          {
              task.validate();
          }
          catch( final BuildException e )
          {
              return;
          }
          fail( "Expected to fail due to null id" );
      }
  
      public void testBadTypeofID()
          throws Exception
      {
          final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
          final MockProject project = new MockProject();
          project.bindReference( "myid", new FilterSet() );
          project.bindReference( "myrefid", new InterceptorSet() );
          task.setProject( project );
          task.setId( "myid" );
          task.setRefid( "myrefid" );
          try
          {
              task.execute();
          }
          catch( final BuildException e )
          {
              return;
          }
          fail( "Expected to fail due to id referencing bad type" );
      }
  
      public void testBadTypeofRefID()
          throws Exception
      {
          final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
          final MockProject project = new MockProject();
          project.bindReference( "myid", new InterceptorSet() );
          project.bindReference( "myrefid", new FilterSet() );
          task.setProject( project );
          task.setId( "myid" );
          task.setRefid( "myrefid" );
          try
          {
              task.execute();
          }
          catch( final BuildException e )
          {
              return;
          }
          fail( "Expected to fail due to refid referencing bad type" );
      }
  
      public void testSuccess()
          throws Exception
      {
          final AddToInterceptorSetTask task = new AddToInterceptorSetTask();
          final MockProject project = new MockProject();
          final InterceptorSet id = new InterceptorSet();
          project.bindReference( "myid", id );
          final InterceptorSet refid = new InterceptorSet();
          final PluginElement element = new PluginElement();
          element.setName( "foo" );
          refid.addInterceptor( element );
          project.bindReference( "myrefid", refid );
          task.setProject( project );
          task.setId( "myid" );
          task.setRefid( "myrefid" );
          task.execute();
  
          final Collection collection = id.toPlugins();
          assertEquals( "plugins.length", 1, collection.size() );
          assertEquals( "plugins(0)",
                        element,
                        collection.iterator().next() );
      }
  }