You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/04/07 19:59:59 UTC

cvs commit: maven-components/maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render IntegratedPluginTestCase.java XdocPluginTest.java

jvanzyl     2004/04/07 10:59:59

  Modified:    maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render
                        XdocPluginTest.java
  Added:       maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render
                        IntegratedPluginTestCase.java
  Log:
  o testing of integrated plugins is now encapsulated in a separate testcase
    just need to add some verification hooks and throw an exception if the
    operation of plugin produces invalid results. In this case not generating
    the xdocs correctly.
  
  Revision  Changes    Path
  1.4       +6 -98     maven-components/maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render/XdocPluginTest.java
  
  Index: XdocPluginTest.java
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render/XdocPluginTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XdocPluginTest.java	7 Apr 2004 17:49:55 -0000	1.3
  +++ XdocPluginTest.java	7 Apr 2004 17:59:59 -0000	1.4
  @@ -1,118 +1,26 @@
   package org.apache.maven.xdoc.render;
   
  -import org.apache.maven.plugin.Plugin;
  -import org.apache.maven.plugin.PluginExecutionRequest;
  -import org.apache.maven.plugin.PluginExecutionResponse;
  -import org.apache.maven.plugin.descriptor.GoalDescriptor;
  -import org.apache.maven.plugin.descriptor.PluginDescriptor;
  -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
  -import org.apache.maven.plugin.plexus.executor.IntegratedPluginExecutor;
  -import org.apache.maven.project.MavenProject;
  -import org.apache.maven.project.MavenProjectBuilder;
  -import org.codehaus.plexus.PlexusTestCase;
   
  -import java.io.File;
  -import java.io.InputStreamReader;
  -import java.util.Iterator;
   
   /**
    * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
    * @version $Id$
    */
   public class XdocPluginTest
  -    extends PlexusTestCase
  +    extends IntegratedPluginTestCase
   {
  -    protected static String PLUGIN_DESCRIPTOR = "META-INF/maven/plugin.xml";
  -
       public XdocPluginTest( String s )
       {
           super( s );
       }
   
  -    protected void setUp()
  -        throws Exception
  -    {
  -        super.setUp();
  -
  -        PluginDescriptor pluginDescriptor = findPluginDescriptor();
  -
  -        getContainer().addComponentDescriptor( pluginDescriptor );
  -    }
  -
  -    public void testXdocRenderer()
  -        throws Exception
  -    {
  -        MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
  -
  -        MavenProject project = builder.build( new File( basedir, "project.xml" ) );
  -
  -        Plugin plugin = (Plugin) lookup( Plugin.ROLE, "xdoc" );
  -
  -        PluginExecutionResponse response = executePlugin( plugin, "xdoc", project );
  -
  -        if ( response.exceptionOccurred() )
  -        {
  -            throw new Exception( response.getException() );
  -        }
  -    }
  -
  -    protected PluginExecutionResponse executePlugin( Plugin plugin, String goal, MavenProject project )
  -        throws Exception
  -    {
  -        IntegratedPluginExecutor executor = new IntegratedPluginExecutor();
  -
  -        PluginExecutionRequest request = createPluginExecutionRequest( goal, project );
  -
  -        request.setPlugin( plugin );
  -
  -        PluginExecutionResponse response = new PluginExecutionResponse();
  -
  -        executor.execute( request, response );
  -
  -        return response;
  -    }
  -
  -    protected PluginExecutionRequest createPluginExecutionRequest( String goal, MavenProject project )
  -        throws Exception
  +    public String getPluginId()
       {
  -        PluginDescriptor pluginDescriptor = findPluginDescriptor();
  -
  -        GoalDescriptor goalDescriptor = findGoalDescriptor( pluginDescriptor, goal );
  -
  -        PluginExecutionRequest request = new PluginExecutionRequest( pluginDescriptor, goalDescriptor, project );
  -
  -        return request;
  +        return "xdoc";
       }
   
  -    protected GoalDescriptor findGoalDescriptor( PluginDescriptor pluginDescriptor, String goal )
  +    public String getGoal()
       {
  -        GoalDescriptor goalDescriptor = null;
  -
  -        for ( Iterator iterator = pluginDescriptor.getGoals().iterator(); iterator.hasNext(); )
  -        {
  -            GoalDescriptor gd = (GoalDescriptor) iterator.next();
  -
  -            if ( gd.getName().equals( goal ) )
  -            {
  -                goalDescriptor = gd;
  -
  -                break;
  -            }
  -        }
  -
  -        return goalDescriptor;
  -    }
  -
  -    protected PluginDescriptor findPluginDescriptor()
  -        throws Exception
  -    {
  -        PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
  -
  -        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  -
  -        PluginDescriptor pluginDescriptor =
  -            builder.build( new InputStreamReader( classLoader.getResourceAsStream( PLUGIN_DESCRIPTOR ) ) );
  -
  -        return pluginDescriptor;
  +        return "xdoc";
       }
   }
  
  
  
  1.1                  maven-components/maven-plugins/maven-xdoc-plugin/src/test/java/org/apache/maven/xdoc/render/IntegratedPluginTestCase.java
  
  Index: IntegratedPluginTestCase.java
  ===================================================================
  package org.apache.maven.xdoc.render;
  
  import org.apache.maven.plugin.Plugin;
  import org.apache.maven.plugin.PluginExecutionRequest;
  import org.apache.maven.plugin.PluginExecutionResponse;
  import org.apache.maven.plugin.descriptor.GoalDescriptor;
  import org.apache.maven.plugin.descriptor.PluginDescriptor;
  import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
  import org.apache.maven.plugin.plexus.executor.IntegratedPluginExecutor;
  import org.apache.maven.project.MavenProject;
  import org.apache.maven.project.MavenProjectBuilder;
  import org.codehaus.plexus.PlexusTestCase;
  
  import java.io.File;
  import java.io.InputStreamReader;
  import java.util.Iterator;
  
  /**
   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
   * @version $Id: IntegratedPluginTestCase.java,v 1.1 2004/04/07 17:59:59 jvanzyl Exp $
   */
  public abstract class IntegratedPluginTestCase
      extends PlexusTestCase
  {
      protected static String PLUGIN_DESCRIPTOR = "META-INF/maven/plugin.xml";
  
      public IntegratedPluginTestCase( String s )
      {
          super( s );
      }
  
      public abstract String getPluginId();
  
      public abstract String getGoal();
  
      protected void setUp()
          throws Exception
      {
          super.setUp();
  
          PluginDescriptor pluginDescriptor = findPluginDescriptor();
  
          getContainer().addComponentDescriptor( pluginDescriptor );
      }
  
      public void testIntegratePlugin()
          throws Exception
      {
          MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
  
          MavenProject project = builder.build( new File( basedir, "project.xml" ) );
  
          Plugin plugin = (Plugin) lookup( Plugin.ROLE, getPluginId() );
  
          PluginExecutionResponse response = executePlugin( plugin, getGoal(), project );
  
          if ( response.exceptionOccurred() )
          {
              throw new Exception( response.getException() );
          }
      }
  
      protected PluginExecutionResponse executePlugin( Plugin plugin, String goal, MavenProject project )
          throws Exception
      {
          IntegratedPluginExecutor executor = new IntegratedPluginExecutor();
  
          PluginExecutionRequest request = createPluginExecutionRequest( goal, project );
  
          request.setPlugin( plugin );
  
          PluginExecutionResponse response = new PluginExecutionResponse();
  
          executor.execute( request, response );
  
          return response;
      }
  
      protected PluginExecutionRequest createPluginExecutionRequest( String goal, MavenProject project )
          throws Exception
      {
          PluginDescriptor pluginDescriptor = findPluginDescriptor();
  
          GoalDescriptor goalDescriptor = findGoalDescriptor( pluginDescriptor, goal );
  
          PluginExecutionRequest request = new PluginExecutionRequest( pluginDescriptor, goalDescriptor, project );
  
          return request;
      }
  
      protected GoalDescriptor findGoalDescriptor( PluginDescriptor pluginDescriptor, String goal )
      {
          GoalDescriptor goalDescriptor = null;
  
          for ( Iterator iterator = pluginDescriptor.getGoals().iterator(); iterator.hasNext(); )
          {
              GoalDescriptor gd = (GoalDescriptor) iterator.next();
  
              if ( gd.getName().equals( goal ) )
              {
                  goalDescriptor = gd;
  
                  break;
              }
          }
  
          return goalDescriptor;
      }
  
      protected PluginDescriptor findPluginDescriptor()
          throws Exception
      {
          PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
  
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  
          PluginDescriptor pluginDescriptor =
              builder.build( new InputStreamReader( classLoader.getResourceAsStream( PLUGIN_DESCRIPTOR ) ) );
  
          return pluginDescriptor;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org