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

svn commit: r391554 - in /maven/plugins/trunk/maven-install-plugin/src/test: java/org/apache/maven/plugin/install/ java/org/apache/maven/plugin/install/stubs/ resources/unit/basic-install-test-packaging-pom/

Author: aramirez
Date: Wed Apr  5 00:22:36 2006
New Revision: 391554

URL: http://svn.apache.org/viewcvs?rev=391554&view=rev
Log:
PR:MINSTALL-16

-added test case
-added tests
-removed InstallArtifactStub2.java

Added:
    maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/
    maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml
Removed:
    maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/InstallArtifactStub2.java
Modified:
    maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
    maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub0.java
    maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub1.java

Modified: maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java?rev=391554&r1=391553&r2=391554&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java Wed Apr  5 00:22:36 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.plugin.install;
 
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,10 +17,15 @@
  */
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.install.stubs.AttachedArtifactStub0;
 import org.apache.maven.plugin.install.stubs.InstallArtifactStub;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * @author aramirez
@@ -32,6 +37,21 @@
    
    InstallArtifactStub artifact; 
    
+   public void setUp()
+       throws Exception
+   {
+       super.setUp();
+       
+       artifact = new InstallArtifactStub();
+       
+       String groupId = dotToSlashReplacer( artifact.getGroupId() );
+       
+       System.out.println( ">>>Cleaning the test artifacts in local repo..." );
+       
+       FileUtils.deleteDirectory( System.getProperty( "localRepository" ) + "/" + 
+                                  groupId + "/" + artifact.getArtifactId() );
+   }
+   
    public void testInstallTestEnvironment()
        throws Exception
    {
@@ -54,7 +74,8 @@
        assertNotNull( mojo );
 
        File file = new File( getBasedir(), 
-                             "target/test-classes/unit/basic-install-test/target/maven-install-test-1.0-SNAPSHOT.jar" );
+                             "target/test-classes/unit/basic-install-test/target/" +
+                             "maven-install-test-1.0-SNAPSHOT.jar" );
        
        artifact = ( InstallArtifactStub ) getVariableValueFromObject( mojo, "artifact" );
        
@@ -62,7 +83,7 @@
        
        mojo.execute();      
        
-       String groupId = artifact.getGroupId().replace( '.', '/' );
+       String groupId = dotToSlashReplacer( artifact.getGroupId() );
        
        String packaging = getVariableValueFromObject( mojo, "packaging" ).toString();
        
@@ -73,33 +94,41 @@
 
        assertTrue( installedArtifact.exists() );
    }
- /*  
+ 
    public void testBasicInstallWithAttachedArtifacts()
        throws Exception
    {
        File testPom = new File( getBasedir(), 
-                                "target/test-classes/unit/basic-install-test-with-attached-artifacts/plugin-config.xml" );
+                                "target/test-classes/unit/basic-install-test-with-attached-artifacts/" +
+                                "plugin-config.xml" );
        
        InstallMojo mojo = ( InstallMojo ) lookupMojo( "install", testPom );
        
        assertNotNull( mojo );
-    
+
+       List attachedArtifacts = ( ArrayList ) getVariableValueFromObject( mojo, "attachedArtifacts" );
+
        mojo.execute();
-    
-       artifact = new InstallArtifactStub();
+
+       String packaging = getVariableValueFromObject( mojo, "packaging" ).toString();
        
-       String groupId = artifact.getGroupId().replace( '.', '/' );
+       String groupId = "";
        
-       String packaging = getVariableValueFromObject( mojo, "packaging" ).toString();
+       for( Iterator iter=attachedArtifacts.iterator(); iter.hasNext(); )
+       {
+           AttachedArtifactStub0 attachedArtifact = ( AttachedArtifactStub0 ) iter.next();
        
-       File installedArtifact = new File( System.getProperty( "localRepository" ) + "/" + 
-                                          groupId + "/" + artifact.getArtifactId() + "/" +
-                                          artifact.getVersion() + "/" + artifact.getArtifactId() + "-" +
-                                          artifact.getVersion() + "." + packaging );
-    
-       assertTrue( installedArtifact.exists() );
+           groupId = dotToSlashReplacer( attachedArtifact.getGroupId() );                      
+           
+           File installedArtifact = new File( System.getProperty( "localRepository" ) + "/" + 
+                                              groupId + "/" + attachedArtifact.getArtifactId() + "/" +
+                                              attachedArtifact.getVersion() + "/" + attachedArtifact.getArtifactId() + "-" +
+                                              attachedArtifact.getVersion() + "." + packaging );
+        
+           assertTrue( installedArtifact.exists() );
+       }
    }
-     */     
+        
    public void testUpdateReleaseParamSetToTrue()
        throws Exception
    {
@@ -110,7 +139,13 @@
        
        assertNotNull( mojo );
 
+       File file = new File( getBasedir(), 
+                           "target/test-classes/unit/configured-install-test/target/" +
+                           "maven-install-test-1.0-SNAPSHOT.jar" );
+       
        artifact = ( InstallArtifactStub ) getVariableValueFromObject( mojo, "artifact" );
+       
+       artifact.setFile( file );
 
        mojo.execute();
 
@@ -131,6 +166,8 @@
        
        artifact.setFile( null );       
        
+       assertNull( artifact.getFile() );
+       
        try
        {
            mojo.execute();
@@ -141,5 +178,39 @@
        {
            //expected
        }
+   }
+   
+   public void testInstallIfPackagingIsPom()
+       throws Exception
+   {
+       File testPom = new File( getBasedir(), 
+                                "target/test-classes/unit/basic-install-test-packaging-pom/" +
+                                "plugin-config.xml" );
+       
+       InstallMojo mojo = ( InstallMojo ) lookupMojo( "install", testPom );
+       
+       assertNotNull( mojo );
+       
+       String packaging = ( String ) getVariableValueFromObject( mojo, "packaging" );
+       
+       assertEquals( "pom", packaging );
+       
+       artifact = ( InstallArtifactStub ) getVariableValueFromObject( mojo, "artifact" );
+       
+       mojo.execute();
+       
+       String groupId = dotToSlashReplacer( artifact.getGroupId() );
+       
+       File installedArtifact = new File( System.getProperty( "localRepository" ) + "/" + 
+                                          groupId + "/" + artifact.getArtifactId() + "/" +
+                                          artifact.getVersion() + "/" + artifact.getArtifactId() + "-" +
+                                          artifact.getVersion() + "." + "jar" );
+    
+       assertTrue( installedArtifact.exists() );
+   }
+   
+   private String dotToSlashReplacer( String parameter )
+   {
+       return parameter.replace( '.', '/' );
    }
 }

Modified: maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub0.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub0.java?rev=391554&r1=391553&r2=391554&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub0.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub0.java Wed Apr  5 00:22:36 2006
@@ -1,5 +1,7 @@
 package org.apache.maven.plugin.install.stubs;
 
+import java.io.File;
+
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
  *
@@ -22,5 +24,12 @@
     public String getArtifactId()
     {
         return "attached-artifact-test-0";
+    }
+    
+    public File getFile()
+    {
+        return new File( System.getProperty( "basedir" ), 
+            "target/test-classes/unit/basic-install-test-with-attached-artifacts/" +
+            "target/maven-install-test-1.0-SNAPSHOT.jar" ); 
     }
 }

Modified: maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub1.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub1.java?rev=391554&r1=391553&r2=391554&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub1.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/test/java/org/apache/maven/plugin/install/stubs/AttachedArtifactStub1.java Wed Apr  5 00:22:36 2006
@@ -17,7 +17,7 @@
  */
 
 public class AttachedArtifactStub1
-    extends InstallArtifactStub
+    extends AttachedArtifactStub0
 {   
     public String getArtifactId()
     {

Added: maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml?rev=391554&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml Wed Apr  5 00:22:36 2006
@@ -0,0 +1,16 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-install-plugin</artifactId>
+		<configuration>
+		  <pomFile>${basedir}/src/test/resources/unit/basic-install-test-packaging-pom/plugin-config.xml</pomFile>
+		  <packaging>pom</packaging>
+		  <artifact implementation="org.apache.maven.plugin.install.stubs.InstallArtifactStub" />
+		  <attachedArtifacts />
+          <localRepository>${localRepository}</localRepository>
+		</configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>