You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/09/20 05:03:56 UTC

svn commit: r448038 - in /maven/plugins/trunk/maven-dependency-plugin/src/test: java/org/apache/maven/plugin/dependency/ java/org/apache/maven/plugin/dependency/utils/ java/org/apache/maven/plugin/dependency/utils/filters/ resources/unit/copy-dependenc...

Author: brianf
Date: Tue Sep 19 20:03:55 2006
New Revision: 448038

URL: http://svn.apache.org/viewvc?view=rev&rev=448038
Log:
More mojo integration tests

Added:
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml   (with props)
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml   (with props)
Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java?view=auto&rev=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java Tue Sep 19 20:03:55 2006
@@ -0,0 +1,55 @@
+package org.apache.maven.plugin.dependency;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+public class AbstractDependencyMojoTestCase
+    extends AbstractMojoTestCase
+{
+
+    protected File testDir;
+
+    protected ArtifactStubFactory stubFactory;
+
+    public AbstractDependencyMojoTestCase()
+    {
+        super();
+    }
+
+    protected void setUp( String testDirStr, boolean createFiles )
+        throws Exception
+    {
+        // required for mojo lookups to work
+        super.setUp();
+        // pick random output location
+        Random a = new Random();
+        testDir = new File( getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar
+            + testDirStr + a.nextLong() + File.separatorChar );
+        testDir.delete();
+        assertFalse( testDir.exists() );
+
+        stubFactory = new ArtifactStubFactory( this.testDir, createFiles );
+
+    }
+
+    protected void tearDown()
+    {
+        try
+        {
+            DependencyTestUtils.removeDirectory( testDir );
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+            assertTrue( false );
+        }
+        assertFalse( testDir.exists() );
+    }
+
+}

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java?view=auto&rev=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java Tue Sep 19 20:03:55 2006
@@ -0,0 +1,58 @@
+package org.apache.maven.plugin.dependency;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.apache.maven.project.MavenProject;
+
+public class TestCopyDependenciesMojo
+    extends AbstractDependencyMojoTestCase
+{
+    protected void setUp()
+        throws Exception
+    {
+        // required for mojo lookups to work
+        super.setUp( "copy-dependencies", true );
+    }
+
+    /**
+     * tests the proper discovery and configuration of the mojo
+     * 
+     * @throws Exception
+     */
+    public void testcompileTestEnvironment()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml" );
+        CopyDependenciesMojo mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies", testPom );
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.project );
+        MavenProject project = mojo.project;
+
+        Set artifacts = this.stubFactory.getScopedArtifacts();
+        Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
+        artifacts.addAll( directArtifacts );
+
+        project.setArtifacts( artifacts );
+        project.setDependencyArtifacts( directArtifacts );
+
+        mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
+        mojo.execute();
+
+        Iterator iter = artifacts.iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            // TODO: verify there is a test for this method.
+            // TODO: create test for striping versions too
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+            assertTrue( file.exists() );
+        }
+    }
+}
\ No newline at end of file

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java?view=diff&rev=448038&r1=448037&r2=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java Tue Sep 19 20:03:55 2006
@@ -1,50 +1,24 @@
 package org.apache.maven.plugin.dependency;
 
 import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Random;
 import java.util.Set;
 
 import org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo;
-import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
 import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
-import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
-import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.project.MavenProject;
 
 public class TestResolveMojo
-    extends AbstractMojoTestCase
+    extends AbstractDependencyMojoTestCase
 {
-    File outputFolder;
     
     protected void setUp()
         throws Exception
     {
         // required for mojo lookups to work
-        super.setUp();
-        //pick random output location
-        Random a = new Random();
-        outputFolder = new File("target/markers"+a.nextLong()+"/");
-        outputFolder.delete();
-        assertFalse(outputFolder.exists());
+        super.setUp("markers",false);
     }
 
-    protected void tearDown()
-    {
-        try
-        {
-            DependencyTestUtils.removeDirectory(outputFolder);
-        }
-        catch ( IOException e )
-        {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            assertTrue(false);
-        }
-        assertFalse(outputFolder.exists());
-    }
+
     
     /**
      * tests the proper discovery and configuration of the mojo
@@ -61,10 +35,9 @@
         assertNotNull(mojo.project);
         MavenProject project = mojo.project;
               
-        ArtifactStubFactory factory = new ArtifactStubFactory(outputFolder,true);
         
-        Set artifacts = factory.getScopedArtifacts();
-        Set directArtifacts = factory.getReleaseAndSnapshotArtifacts();
+        Set artifacts = this.stubFactory.getScopedArtifacts();
+        Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
         artifacts.addAll(directArtifacts);
         
         project.setArtifacts(artifacts);

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java?view=diff&rev=448038&r1=448037&r2=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java Tue Sep 19 20:03:55 2006
@@ -20,7 +20,7 @@
 
     public ArtifactStubFactory( File workingDir, boolean createFiles )
     {
-        this.workingDir = workingDir;
+        this.workingDir = new File(workingDir,"localTestRepo");
         this.createFiles = createFiles;
     }
 

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java?view=diff&rev=448038&r1=448037&r2=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/filters/TestMarkerFileFilter.java Tue Sep 19 20:03:55 2006
@@ -29,6 +29,7 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
+import org.apache.maven.plugin.dependency.utils.DependencyTestUtils;
 import org.apache.maven.plugin.dependency.utils.SilentLog;
 import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
 import org.apache.maven.plugin.logging.Log;
@@ -56,7 +57,7 @@
         //pick random output location
         Random a = new Random();
         outputFolder = new File("target/markers"+a.nextLong()+"/");
-        outputFolder.delete();
+        DependencyTestUtils.removeDirectory(outputFolder);
         assertFalse(outputFolder.exists());
         
         this.fact = new ArtifactStubFactory(outputFolder,false);
@@ -80,7 +81,7 @@
         assertEquals(2,result.size());    
     }
     
-    public void testMarkerSnapshots () throws MojoExecutionException
+    public void testMarkerSnapshots () throws MojoExecutionException, IOException
     {
         DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(fact.getSnapshotArtifact(),outputFolder);
         handler.setMarker();
@@ -93,11 +94,11 @@
         result = filter.filter(artifacts,log);
         assertEquals(2,result.size());
         assertTrue(handler.clearMarker());
-        outputFolder.delete();
+        DependencyTestUtils.removeDirectory(outputFolder);
         assertFalse(outputFolder.exists()); 
     }
     
-    public void testMarkerRelease () throws MojoExecutionException
+    public void testMarkerRelease () throws MojoExecutionException, IOException
     {
         DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(fact.getReleaseArtifact(),outputFolder);
         handler.setMarker();
@@ -111,7 +112,7 @@
         assertEquals(2,result.size());
      
         assertTrue(handler.clearMarker());
-        outputFolder.delete();
+        DependencyTestUtils.removeDirectory(outputFolder);
         assertFalse(outputFolder.exists()); 
     }
     
@@ -139,7 +140,7 @@
         assertFalse(handler.isMarkerSet());
         snap.getFile().delete();
         release.getFile().delete();
-        outputFolder.delete();
+        DependencyTestUtils.removeDirectory(outputFolder);
         assertFalse(outputFolder.exists());    
     }
     

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml?view=auto&rev=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml Tue Sep 19 20:03:55 2006
@@ -0,0 +1,19 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+          <configuration>
+              <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+          </configuration>
+      </plugin>
+    </plugins>
+  </build>
+    <dependencies>
+        <dependency>
+          <groupId>org.apache.maven</groupId>
+          <artifactId>maven-artifact</artifactId>
+          <version>2.0.4</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-dependencies-test/plugin-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml?view=auto&rev=448038
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml Tue Sep 19 20:03:55 2006
@@ -0,0 +1,19 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+          <configuration>
+              <project implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+          </configuration>
+      </plugin>
+    </plugins>
+  </build>
+    <dependencies>
+        <dependency>
+          <groupId>org.apache.maven</groupId>
+          <artifactId>maven-artifact</artifactId>
+          <version>2.0.4</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/copy-test/plugin-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml