Author: aramirez Date: Mon Apr 10 19:51:09 2006 New Revision: 393141 URL: http://svn.apache.org/viewcvs?rev=393141&view=rev Log: PR: MRAR-6
added tests using plugin testing harness Added: maven/plugins/trunk/maven-rar-plugin/src/test/ maven/plugins/trunk/maven-rar-plugin/src/test/java/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarArtifactStub.java maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarMavenProjectStub.java maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.jar maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.pom maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.jar maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.pom maven/plugins/trunk/maven-rar-plugin/src/test/resources/ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/plugin-config.xml maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/src/ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/src/main/ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/src/main/rar/ Modified: maven/plugins/trunk/maven-rar-plugin/pom.xml Modified: maven/plugins/trunk/maven-rar-plugin/pom.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/pom.xml?rev=393141&r1=393140&r2=393141&view=diff ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-rar-plugin/pom.xml Mon Apr 10 19:51:09 2006 @@ -25,5 +25,11 @@ <artifactId>maven-archiver</artifactId> <version>2.0.1</version> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <scope>test</scope> + <version>1.0-SNAPSHOT</version> + </dependency> </dependencies> </project> Added: maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/RarMojoTest.java Mon Apr 10 19:51:09 2006 @@ -0,0 +1,121 @@ +package org.apache.maven.plugin.rar; + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +import org.apache.maven.plugin.rar.stubs.RarMavenProjectStub; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.codehaus.plexus.archiver.zip.ZipEntry; +import org.codehaus.plexus.archiver.zip.ZipFile; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Allan Ramirez</a> + */ +public class RarMojoTest + extends AbstractMojoTestCase +{ + public void testRarTestEnvironment() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-rar-test/plugin-config.xml" ); + + RarMojo mojo = ( RarMojo ) lookupMojo( "rar", testPom ); + + assertNotNull( mojo ); + } + + public void testBasicRar() + throws Exception + { + File testPom = new File( getBasedir(), + "target/test-classes/unit/basic-rar-test/plugin-config.xml" ); + + RarMojo mojo = ( RarMojo ) lookupMojo( "rar", testPom ); + + assertNotNull( mojo ); + + String finalName = ( String ) getVariableValueFromObject( mojo, "finalName" ); + + String workDir = ( String ) getVariableValueFromObject( mojo, "workDirectory" ); + + String outputDir = ( String ) getVariableValueFromObject( mojo, "outputDirectory" ); + + mojo.execute(); + + //check the working directory + File workDirectory = new File( workDir ); + + assertTrue( workDirectory.exists() ); + + assertTrue( workDirectory.isDirectory() ); + + File[] fileNames = workDirectory.listFiles(); + + assertEquals( 2, fileNames.length ); + + assertEquals( "maven-artifact01-1.0-SNAPSHOT.jar", fileNames[0].getName() ); + + assertEquals( "maven-artifact02-1.0-SNAPSHOT.jar", fileNames[1].getName() ); + + //check the generated rar file + File rarFile = new File( outputDir, finalName + ".rar" ); + + assertTrue( rarFile.exists() ); + + //expected files/directories inside the rar file + List expectedFiles = new ArrayList(); + + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-rar-test/pom.properties" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-rar-test/pom.xml" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/maven-rar-test/" ); + expectedFiles.add( "META-INF/maven/org.apache.maven.test/" ); + expectedFiles.add( "META-INF/maven/" ); + expectedFiles.add( "META-INF/MANIFEST.MF" ); + expectedFiles.add( "META-INF/" ); + expectedFiles.add( "maven-artifact01-1.0-SNAPSHOT.jar" ); + expectedFiles.add( "maven-artifact02-1.0-SNAPSHOT.jar" ); + + ZipFile rar = new ZipFile( rarFile ); + + Enumeration entries = rar.getEntries(); + + assertTrue( entries.hasMoreElements() ); + + while( entries.hasMoreElements() ) + { + ZipEntry entry = ( ZipEntry ) entries.nextElement(); + + if( expectedFiles.contains( entry.getName() ) ) + { + expectedFiles.remove( entry.getName() ); + assertFalse( expectedFiles.contains( entry.getName() ) ); + } + else + { + fail( entry.getName() + " is not included in the expected files" ); + } + } + assertEquals( 0, expectedFiles.size() ); + } + + +} Added: maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarArtifactStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarArtifactStub.java?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarArtifactStub.java (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarArtifactStub.java Mon Apr 10 19:51:09 2006 @@ -0,0 +1,110 @@ +package org.apache.maven.plugin.rar.stubs; + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; + +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Allan Ramirez</a> + */ +public class RarArtifactStub + extends ArtifactStub +{ + private String groupId; + + private String artifactId; + + private String version; + + private String scope; + + private boolean optional; + + private File file; + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public File getFile() + { + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public boolean isOptional() + { + return optional; + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + public String getScope() + { + return scope; + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public String getId() + { + return getGroupId() + ":" + getArtifactId() + ":" + getVersion(); + } + + public String getBaseVersion() + { + return getVersion(); + } +} Added: maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarMavenProjectStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarMavenProjectStub.java?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarMavenProjectStub.java (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/java/org/apache/maven/plugin/rar/stubs/RarMavenProjectStub.java Mon Apr 10 19:51:09 2006 @@ -0,0 +1,145 @@ +package org.apache.maven.plugin.rar.stubs; + +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusTestCase; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Allan Ramirez</a> + */ +public class RarMavenProjectStub + extends MavenProject +{ + private List attachedArtifacts; + + public RarMavenProjectStub() + { + super( new Model() ); + + super.setGroupId( getGroupId() ); + super.setArtifactId( getArtifactId() ); + super.setVersion( getVersion() ); + super.setDescription( "Test description" ); + + Organization org = new Organization(); + org.setName( "organization" ); + org.setUrl( "http://www.some.org" ); + + super.setOrganization( org ); + super.setFile( getFile() ); + super.setPluginArtifacts( Collections.EMPTY_SET ); + super.setReportArtifacts( Collections.EMPTY_SET ); + super.setExtensionArtifacts( Collections.EMPTY_SET ); + super.setArtifact( getArtifact() ); + super.setRemoteArtifactRepositories( Collections.EMPTY_LIST ); + super.setPluginArtifactRepositories( Collections.EMPTY_LIST ); + super.setCollectedProjects( Collections.EMPTY_LIST ); + super.setActiveProfiles( Collections.EMPTY_LIST ); + + super.addCompileSourceRoot( getBasedir() + "/src/test/resources/unit/basic-rar-test/src/main/java" ); + super.addTestCompileSourceRoot( getBasedir() + "/src/test/resources/unit/basic-rar-test/src/test/java" ); + + super.setExecutionRoot( false ); + } + + public String getGroupId() + { + return "org.apache.maven.test"; + } + + public String getArtifactId() + { + return "maven-rar-test"; + } + + public String getVersion() + { + return "1.0-SNAPSHOT"; + } + + public File getFile() + { + return new File( getBasedir(), "src/test/resources/unit/basic-rar-test/plugin-config.xml" ); + } + + public File getBasedir() + { + return new File( PlexusTestCase.getBasedir() ); + } + + public Artifact getArtifact() + { + Artifact artifact = new RarArtifactStub(); + + artifact.setGroupId( getGroupId() ); + + artifact.setArtifactId( getArtifactId() ); + + artifact.setVersion( getVersion() ); + + return artifact; + } + + public Set getArtifacts() + { + Set artifacts = new HashSet(); + + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) ); + artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false ) ); + + return artifacts; + } + + public List getAttachedArtifacts() + { + if ( attachedArtifacts == null ) + { + attachedArtifacts = new ArrayList(); + } + return attachedArtifacts; + } + + protected Artifact createArtifact( String groupId, String artifactId, String version, boolean optional ) + { + Artifact artifact = new RarArtifactStub(); + + artifact.setGroupId( groupId ); + + artifact.setArtifactId( artifactId ); + + artifact.setVersion( version ); + + artifact.setOptional( optional ); + + artifact.setFile( new File ( getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace( '.', '/' ) + + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar" ) ) ; + + return artifact; + } +} Added: maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.jar URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.jar?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.jar (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.jar Mon Apr 10 19:51:09 2006 @@ -0,0 +1 @@ +This is not an actual jar \ No newline at end of file Added: maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.pom URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.pom?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.pom (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact01/1.0-SNAPSHOT/maven-artifact01-1.0-SNAPSHOT.pom Mon Apr 10 19:51:09 2006 @@ -0,0 +1,6 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.test</groupId> + <artifactId>maven-artifact01</artifactId> + <version>1.0-SNAPSHOT</version> +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.jar URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.jar?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.jar (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.jar Mon Apr 10 19:51:09 2006 @@ -0,0 +1 @@ +This is not an actual jar \ No newline at end of file Added: maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.pom URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.pom?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.pom (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/remote-repo/org/apache/maven/test/maven-artifact02/1.0-SNAPSHOT/maven-artifact02-1.0-SNAPSHOT.pom Mon Apr 10 19:51:09 2006 @@ -0,0 +1,6 @@ +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.test</groupId> + <artifactId>maven-artifact02</artifactId> + <version>1.0-SNAPSHOT</version> +</project> \ No newline at end of file Added: maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/plugin-config.xml?rev=393141&view=auto ============================================================================== --- maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/plugin-config.xml (added) +++ maven/plugins/trunk/maven-rar-plugin/src/test/resources/unit/basic-rar-test/plugin-config.xml Mon Apr 10 19:51:09 2006 @@ -0,0 +1,19 @@ +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-rar-plugin</artifactId> + <configuration> + <rarSourceDirectory>${basedir}/src/test/resources/unit/basic-rar-test/src/main/rar</rarSourceDirectory> + <raXmlFile>${basedir}/src/test/resources/unit/basic-rar-test/src/main/rar/META-INF/ra.xml</raXmlFile> + <includeJar>true</includeJar> + <manifestFile>${basedir}/src/main/rar/META-INF/MANIFEST.MF</manifestFile> + <workDirectory>${basedir}/target/unit/basic-rar-test/target/rar-test</workDirectory> + <outputDirectory>${basedir}/target/unit/basic-rar-test/target</outputDirectory> + <finalName>test-rar</finalName> + <project implementation="org.apache.maven.plugin.rar.stubs.RarMavenProjectStub" /> + </configuration> + </plugin> + </plugins> + </build> +</project>