Author: aramirez Date: Tue May 9 03:47:10 2006 New Revision: 405380 URL: http://svn.apache.org/viewcvs?rev=405380&view=rev Log: PR: MWAR-28
added test for manifest mojo Added: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarManifestMojoTest.java maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/plugin-config.xml maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/plugin-config.xml maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/plugin-config.xml maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/plugin-config.xml Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectBasicStub.java maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/SimpleWarArtifactStub.java Added: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarManifestMojoTest.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarManifestMojoTest.java?rev=405380&view=auto ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarManifestMojoTest.java (added) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarManifestMojoTest.java Tue May 9 03:47:10 2006 @@ -0,0 +1,150 @@ +package org.apache.maven.plugin.war; + +/* + * Copyright 2001-2005 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 org.apache.maven.archiver.MavenArchiveConfiguration; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.codehaus.plexus.util.FileUtils; + +import java.io.File; + +/** + * @author Allan Ramirez + */ +public class WarManifestMojoTest + extends AbstractMojoTestCase +{ + File testPom; + + WarManifestMojo mojo; + + public void testEnvironment() + throws Exception + { + loadMojo( "target/test-classes/unit/manifest/basic-manifest-test/plugin-config.xml" ); + } + + public void testBasicManifest() + throws Exception + { + loadMojo( "target/test-classes/unit/manifest/basic-manifest-test/plugin-config.xml" ); + + mojo.execute(); + + File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" ); + + File manifestDir = new File( warSourceDir, "META-INF" ); + + File manifest = new File( manifestDir, "MANIFEST.MF" ); + + assertTrue( manifest.exists() ); + } + + public void testManifestWithClasspath() + throws Exception + { + loadMojo( "target/test-classes/unit/manifest/manifest-with-classpath/plugin-config.xml" ); + + MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" ); + + mojo.execute(); + + assertTrue( config.getManifest().isAddClasspath() ); + + File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" ); + + File manifestDir = new File( warSourceDir, "META-INF" ); + + File manifest = new File( manifestDir, "MANIFEST.MF" ); + + assertTrue( manifest.exists() ); + + String content = FileUtils.fileRead( manifest ); + + int idx = content.indexOf( "Class-Path" ); + + assertTrue( idx >= 0 ); + } + + public void testManifestWithMainClass() + throws Exception + { + loadMojo( "target/test-classes/unit/manifest/manifest-with-main-class/plugin-config.xml" ); + + MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" ); + + mojo.execute(); + + assertEquals( "org.dummy.test.SomeClass", config.getManifest().getMainClass() ); + + File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" ); + + File manifestDir = new File( warSourceDir, "META-INF" ); + + File manifest = new File( manifestDir, "MANIFEST.MF" ); + + assertTrue( manifest.exists() ); + + String content = FileUtils.fileRead( manifest ); + + int idx = content.indexOf( "Main-Class" ); + + assertTrue( idx >= 0 ); + } + + public void testManifestWithOtherAttributes() + throws Exception + { + loadMojo( "target/test-classes/unit/manifest/manifest-with-other-attrs/plugin-config.xml" ); + + MavenArchiveConfiguration config = (MavenArchiveConfiguration) getVariableValueFromObject( mojo, "archive" ); + + mojo.execute(); + + assertTrue( config.getManifest().isAddExtensions() ); + + File warSourceDir = (File) getVariableValueFromObject( mojo, "warSourceDirectory" ); + + File manifestDir = new File( warSourceDir, "META-INF" ); + + File manifest = new File( manifestDir, "MANIFEST.MF" ); + + assertTrue( manifest.exists() ); + + String content = FileUtils.fileRead( manifest ); + + int idx = content.indexOf( "Specification-Title" ); + + assertTrue( idx >= 0 ); + + idx = content.indexOf( "Specification-Vendor" ); + + assertTrue( idx >= 0 ); + + idx = content.indexOf( "Implementation-Vendor" ); + } + + public void loadMojo( String pluginXml ) + throws Exception + { + testPom = new File( getBasedir(), pluginXml ); + + mojo = (WarManifestMojo) lookupMojo( "manifest", testPom ); + + assertNotNull( mojo ); + } +} Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java?rev=405380&r1=405379&r2=405380&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectArtifactsStub.java Tue May 9 03:47:10 2006 @@ -16,11 +16,13 @@ * limitations under the License. */ +import org.apache.maven.plugin.testing.stubs.ArtifactStub; + +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; -import org.apache.maven.plugin.testing.stubs.ArtifactStub; - public class MavenProjectArtifactsStub extends MavenProjectBasicStub { @@ -39,6 +41,20 @@ public Set getArtifacts() { + return artifacts; + } + + public List getRuntimeClasspathElements() + { + List artifacts = new ArrayList(); + + String basedir = System.getProperty( "basedir" ); + + artifacts.add( basedir + + "/src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact1-1.0-SNAPSHOT.jar" ); + artifacts.add( basedir + + "/src/test/resources/unit/manifest/manifest-with-classpath/sample-artifacts/maven-artifact2-1.0-SNAPSHOT.jar" ); + return artifacts; } } Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectBasicStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectBasicStub.java?rev=405380&r1=405379&r2=405380&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectBasicStub.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/MavenProjectBasicStub.java Tue May 9 03:47:10 2006 @@ -23,11 +23,10 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.apache.maven.model.Organization; /** - * Stub - * - * + * Stub */ public class MavenProjectBasicStub extends MavenProjectStub @@ -56,7 +55,7 @@ public File getBasedir() { - // create an isolated environment + // create an isolated environment // see setupTestEnvironment for details return new File( testRootDir ); } @@ -100,4 +99,21 @@ { return properties; } + + public String getDescription() + { + return "Test Description"; + } + + public Organization getOrganization() + { + return new Organization() + { + public String getName() + { + return "Test Name"; + } + }; + } + } Modified: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/SimpleWarArtifactStub.java URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/SimpleWarArtifactStub.java?rev=405380&r1=405379&r2=405380&view=diff ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/SimpleWarArtifactStub.java (original) +++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/stub/SimpleWarArtifactStub.java Tue May 9 03:47:10 2006 @@ -35,14 +35,16 @@ import java.io.File; /** - * Stub - * - * + * Stub */ public class SimpleWarArtifactStub extends AbstractArtifactStub { + private String artifactId; + + private File file; + public SimpleWarArtifactStub( String _basedir ) { super( _basedir ); @@ -55,11 +57,35 @@ public String getArtifactId() { - return "simple"; + if ( artifactId == null ) + { + return "simple"; + } + else + { + return artifactId; + } + } + + public void setArtifactId( String _artifactId ) + { + artifactId = _artifactId; } public File getFile() { - return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); + if ( file == null ) + { + return new File( basedir, "/target/test-classes/unit/sample_wars/simple.war" ); + } + else + { + return file; + } + } + + public void setFile( File _file ) + { + file = _file; } } Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/plugin-config.xml?rev=405380&view=auto ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/plugin-config.xml (added) +++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/basic-manifest-test/plugin-config.xml Tue May 9 03:47:10 2006 @@ -0,0 +1,14 @@ +<project> + <name>war-plugin-test</name> + <build> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.war.stub.MavenProjectBasicStub" /> + <warSourceDirectory>${basedir}/target/test-classes/unit/manifest/basic-manifest-test/src/main</warSourceDirectory> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/plugin-config.xml?rev=405380&view=auto ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/plugin-config.xml (added) +++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-classpath/plugin-config.xml Tue May 9 03:47:10 2006 @@ -0,0 +1,19 @@ +<project> + <name>war-plugin-test</name> + <build> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.war.stub.MavenProjectArtifactsStub" /> + <warSourceDirectory>${basedir}/target/test-classes/unit/manifest/manifest-with-classpath/src/main</warSourceDirectory> + <archive> + <manifest> + <addClasspath>true</addClasspath> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/plugin-config.xml?rev=405380&view=auto ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/plugin-config.xml (added) +++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-main-class/plugin-config.xml Tue May 9 03:47:10 2006 @@ -0,0 +1,19 @@ +<project> + <name>war-plugin-test</name> + <build> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.war.stub.MavenProjectArtifactsStub" /> + <warSourceDirectory>${basedir}/target/test-classes/unit/manifest/manifest-with-main-class/src/main</warSourceDirectory> + <archive> + <manifest> + <mainClass>org.dummy.test.SomeClass</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/plugin-config.xml URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/plugin-config.xml?rev=405380&view=auto ============================================================================== --- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/plugin-config.xml (added) +++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/manifest/manifest-with-other-attrs/plugin-config.xml Tue May 9 03:47:10 2006 @@ -0,0 +1,19 @@ +<project> + <name>war-plugin-test</name> + <build> + <plugins> + <plugin> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.war.stub.MavenProjectBasicStub" /> + <warSourceDirectory>${basedir}/target/test-classes/unit/manifest/manifest-with-other-attrs/src/main</warSourceDirectory> + <archive> + <manifest> + <addExtensions>true</addExtensions> + </manifest> + </archive> + </configuration> + </plugin> + </plugins> + </build> +</project>