Author: aramirez Date: Wed Apr 19 03:12:49 2006 New Revision: 395195 URL: http://svn.apache.org/viewcvs?rev=395195&view=rev Log: PR: MDEPLOY-30
-added tests using plugin testing harness Added: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java maven/plugins/trunk/maven-deploy-plugin/src/test/resources/ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/plugin-config.xml maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/deploy-test-file-1.0-SNAPSHOT.jar Removed: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployFileMojoTest.java Modified: maven/plugins/trunk/maven-deploy-plugin/pom.xml Modified: maven/plugins/trunk/maven-deploy-plugin/pom.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/pom.xml?rev=395195&r1=395194&r2=395195&view=diff ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-deploy-plugin/pom.xml Wed Apr 19 03:12:49 2006 @@ -31,5 +31,16 @@ <artifactId>maven-artifact</artifactId> <version>2.0</version> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <scope>test</scope> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-tools</artifactId> + <version>2.1-SNAPSHOT</version> + </dependency> </dependencies> </project> Added: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java?rev=395195&view=auto ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java (added) +++ maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java Wed Apr 19 03:12:49 2006 @@ -0,0 +1,96 @@ +package org.apache.maven.plugin.deploy; + +import java.io.File; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.plugin.deploy.DeployMojo; +import org.apache.maven.plugin.deploy.stubs.DeployArtifactStub; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.codehaus.plexus.util.FileUtils; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Allan Ramirez</a> + */ +public class DeployMojoTest + extends AbstractMojoTestCase +{ + private File remoteRepo; + + private final String LOCAL_REPO = "/target/local-repo/"; + + MavenProjectStub project = new MavenProjectStub(); + + public void setUp() + throws Exception + { + super.setUp(); + + remoteRepo = new File( getBasedir(), "target/remote-repo" ); + + remoteRepo.mkdirs(); + } + + public void testDeployTestEnvironment() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-deploy-test/plugin-config.xml" ); + + DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); + + assertNotNull( mojo ); + } + + public void testBasicDeploy() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-deploy-test/plugin-config.xml" ); + + DeployMojo mojo = ( DeployMojo ) lookupMojo( "deploy", testPom ); + + assertNotNull( mojo ); + + File file = new File( getBasedir(), + "target/test-classes/unit/basic-deploy-test/target/" + + "deploy-test-file-1.0-SNAPSHOT.jar" ); + + assertTrue( file.exists() ); + + DeployArtifactStub artifact = ( DeployArtifactStub ) getVariableValueFromObject( mojo, "artifact" ); + + String packaging = ( String ) getVariableValueFromObject( mojo, "packaging" ); + + artifact.setFile( file ); + + File deployedArtifact = new File( getBasedir(), + "target/remote-repo/" + artifact.getGroupId().replace( '.', '/' ) + + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + packaging ); + + ArtifactRepository repo = ( ArtifactRepository ) getVariableValueFromObject( mojo, "deploymentRepository" ); + + assertNotNull( repo ); + + assertEquals( "deploy-test", repo.getId() ); + assertEquals( "deploy-test", repo.getKey() ); + assertEquals( "file", repo.getProtocol() ); + assertEquals( "file://" + getBasedir() + "/target/remote-repo", repo.getUrl() ); + + mojo.execute(); + + assertTrue( "Artifact has been deployed", deployedArtifact.exists() ); + } + + public void tearDown() + throws Exception + { + super.tearDown(); + + if( remoteRepo.exists() ) + { + //FileUtils.deleteDirectory( remoteRepo ); + } + } +} Added: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java?rev=395195&view=auto ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java (added) +++ maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/ArtifactRepositoryStub.java Wed Apr 19 03:12:49 2006 @@ -0,0 +1,89 @@ +package org.apache.maven.plugin.deploy.stubs; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; + +public class ArtifactRepositoryStub + implements ArtifactRepository +{ + private boolean blacklisted; + + private ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); + + public String pathOf( Artifact artifact ) + { + return layout.pathOf( artifact ); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ) + { + return layout.pathOfRemoteRepositoryMetadata( artifactMetadata ); + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return layout.pathOfLocalRepositoryMetadata( metadata, repository ); + } + + public String getUrl() + { + return "file://" + System.getProperty( "basedir" ) + "/target/remote-repo"; + } + + public String getBasedir() + { + return System.getProperty( "basedir" ); + } + + public String getProtocol() + { + return "file"; + } + + public String getId() + { + return "deploy-test"; + } + + public ArtifactRepositoryPolicy getSnapshots() + { + return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + public ArtifactRepositoryPolicy getReleases() + { + return new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, + ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + public ArtifactRepositoryLayout getLayout() + { + return layout; + } + + public String getKey() + { + return getId(); + } + + public boolean isUniqueVersion() + { + return false; + } + + public void setBlacklisted( boolean blackListed ) + { + this.blacklisted = blackListed; + } + + public boolean isBlacklisted() + { + return blacklisted; + } + +} Added: maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java?rev=395195&view=auto ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java (added) +++ maven/plugins/trunk/maven-deploy-plugin/src/test/java/org/apache/maven/plugin/deploy/stubs/DeployArtifactStub.java Wed Apr 19 03:12:49 2006 @@ -0,0 +1,96 @@ +package org.apache.maven.plugin.deploy.stubs; + +import java.io.File; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +public class DeployArtifactStub + extends ArtifactStub +{ + private Map metadataMap; + + private File file; + + private boolean release; + + public String getArtifactId() + { + return "maven-deploy-test"; + } + + public String getGroupId() + { + return "org.apache.maven.test"; + } + + public String getVersion() + { + return "1.0-SNAPSHOT"; + } + + public String getBaseVersion() + { + return getVersion(); + } + + public void setFile( File file ) + { + this.file = file; + } + + public File getFile() + { + return file; + } + + public ArtifactHandler getArtifactHandler() + { + return new DefaultArtifactHandler() + { + public String getExtension() + { + return "jar"; + } + }; + } + + public void addMetadata( ArtifactMetadata metadata ) + { + if ( metadataMap == null ) + { + metadataMap = new HashMap(); + } + + ArtifactMetadata m = (ArtifactMetadata) metadataMap.get( metadata.getKey() ); + if ( m != null ) + { + m.merge( metadata ); + } + else + { + metadataMap.put( metadata.getKey(), metadata ); + } + } + + public Collection getMetadataList() + { + return metadataMap == null ? Collections.EMPTY_LIST : metadataMap.values(); + } + + public boolean isRelease() + { + return release; + } + + public void setRelease( boolean release ) + { + this.release = release; + } +} Added: maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/plugin-config.xml?rev=395195&view=auto ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/plugin-config.xml (added) +++ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/plugin-config.xml Wed Apr 19 03:12:49 2006 @@ -0,0 +1,18 @@ +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <pomFile>${basedir}/src/test/resources/unit/basic-deploy-test/plugin-config.xml</pomFile> + <packaging>jar</packaging> + <artifact implementation="org.apache.maven.plugin.deploy.stubs.DeployArtifactStub" /> + <attachedArtifacts /> + <localRepository>${localRepository}</localRepository> + <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub" /> + <updateReleaseInfo>false</updateReleaseInfo> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/deploy-test-file-1.0-SNAPSHOT.jar URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/deploy-test-file-1.0-SNAPSHOT.jar?rev=395195&view=auto ============================================================================== --- maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/deploy-test-file-1.0-SNAPSHOT.jar (added) +++ maven/plugins/trunk/maven-deploy-plugin/src/test/resources/unit/basic-deploy-test/target/deploy-test-file-1.0-SNAPSHOT.jar Wed Apr 19 03:12:49 2006 @@ -0,0 +1 @@ +This is not an actual jar \ No newline at end of file