You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/05/25 08:16:33 UTC

svn commit: r409310 - in /maven/plugins/trunk/maven-war-plugin: ./ src/test/java/org/apache/maven/plugin/war/ src/test/resources/unit/warmojotest/

Author: epunzalan
Date: Wed May 24 23:16:33 2006
New Revision: 409310

URL: http://svn.apache.org/viewvc?rev=409310&view=rev
Log:
PR: MWAR-44
Submitted by: Marvin King

Added the missing test cases for the WarMojo.
Also, bumped all maven core deps to 2.0.1 and put the proper prerequisites in pom.xml

Added:
    maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java   (with props)
    maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/
    maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml   (with props)
    maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml   (with props)
Modified:
    maven/plugins/trunk/maven-war-plugin/pom.xml

Modified: maven/plugins/trunk/maven-war-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/pom.xml?rev=409310&r1=409309&r2=409310&view=diff
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-war-plugin/pom.xml Wed May 24 23:16:33 2006
@@ -9,11 +9,14 @@
   <packaging>maven-plugin</packaging>
   <name>Maven War Plugin</name>
   <version>2.0.1-SNAPSHOT</version>
+  <prerequisites>
+    <maven>2.0.1</maven>
+  </prerequisites>
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
+      <version>2.0.1</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
@@ -28,7 +31,7 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
-      <version>2.0</version>
+      <version>2.0.1</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>

Added: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java?rev=409310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java (added)
+++ maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java Wed May 24 23:16:33 2006
@@ -0,0 +1,269 @@
+package org.apache.maven.plugin.war;
+
+/*
+ * 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 org.apache.maven.plugin.war.stub.MavenProject4CopyConstructor;
+import org.apache.maven.plugin.war.stub.ProjectHelperStub;
+import org.apache.maven.plugin.war.stub.SimpleWarArtifact4CCStub;
+
+import java.io.File;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * comprehensive test on buildExplodedWebApp is done on WarExplodedMojoTest
+ * 
+ *
+ */
+public class WarMojoTest
+    extends AbstractWarMojoTest
+{
+    WarMojo mojo;
+
+    private static File pomFile = new File( getBasedir(),
+                                            "target/test-classes/unit/warmojotest/plugin-config-primary-artifact.xml" );
+
+    protected File getTestDirectory()
+    {
+        return new File( getBasedir(), "target/test-classes/unit/warmojotest" );
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        mojo = (WarMojo) lookupMojo( "war", pomFile );
+    }
+
+    public void testEnvironment()
+        throws Exception
+    {
+        // see setup
+    }
+
+    public void testSimpleWar()
+        throws Exception
+    {
+        String testId = "SimpleWar";
+        MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
+        String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
+        File webAppDirectory = new File( getTestDirectory(), testId );
+        SimpleWarArtifact4CCStub warArtifact = new SimpleWarArtifact4CCStub( getBasedir() );
+        String warName = "simple";
+        File webAppSource = createWebAppSource( testId );
+        File classesDir = createClassesDir( testId, true );
+        File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+
+        project.setArtifact( warArtifact );
+        this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+        setVariableValueToObject( mojo, "outputDirectory", outputDir );
+        setVariableValueToObject( mojo, "warName", warName );
+        mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+
+        mojo.execute();
+
+        //validate jar file
+        File expectedJarFile = new File( outputDir, "simple.war" );
+        HashSet jarContent = new HashSet();
+
+        assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
+
+        JarFile jarFile = new JarFile( expectedJarFile );
+        JarEntry entry;
+        Enumeration enumeration = jarFile.entries();
+
+        while ( enumeration.hasMoreElements() )
+        {
+            entry = (JarEntry) enumeration.nextElement();
+            jarContent.add( entry.getName() );
+        }
+
+        assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) );
+        assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) );
+        assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) );
+        assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent
+            .contains( "org/web/app/last-exile.jsp" ) );
+        assertTrue( "pom file not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+        assertTrue( "pom properties not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+    }
+
+    public void testClassifier()
+        throws Exception
+    {
+        String testId = "Classifier";
+        MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
+        String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
+        File webAppDirectory = new File( getTestDirectory(), testId );
+        SimpleWarArtifact4CCStub warArtifact = new SimpleWarArtifact4CCStub( getBasedir() );
+        ProjectHelperStub projectHelper = new ProjectHelperStub();
+        String warName = "simple";
+        File webAppSource = createWebAppSource( testId );
+        File classesDir = createClassesDir( testId, true );
+        File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+
+        project.setArtifact( warArtifact );
+        this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+        setVariableValueToObject( mojo, "projectHelper", projectHelper );
+        setVariableValueToObject( mojo, "classifier", "test-classifier" );
+        setVariableValueToObject( mojo, "outputDirectory", outputDir );
+        setVariableValueToObject( mojo, "warName", warName );
+        mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+
+        mojo.execute();
+
+        //validate jar file
+        File expectedJarFile = new File( outputDir, "simple-test-classifier.war" );
+        HashSet jarContent = new HashSet();
+
+        assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
+        assertNotNull( "artifact not attached to project", projectHelper.getArtifactFile() );
+
+        JarFile jarFile = new JarFile( expectedJarFile );
+        JarEntry entry;
+        Enumeration enumeration = jarFile.entries();
+
+        while ( enumeration.hasMoreElements() )
+        {
+            entry = (JarEntry) enumeration.nextElement();
+            jarContent.add( entry.getName() );
+        }
+
+        assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) );
+        assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) );
+        assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) );
+        assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent
+            .contains( "org/web/app/last-exile.jsp" ) );
+        assertTrue( "pom file not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+        assertTrue( "pom properties not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+    }
+
+    public void testPrimaryArtifact()
+        throws Exception
+    {
+        String testId = "PrimaryArtifact";
+        MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
+        String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
+        File webAppDirectory = new File( getTestDirectory(), testId );
+        SimpleWarArtifact4CCStub warArtifact = new SimpleWarArtifact4CCStub( getBasedir() );
+        ProjectHelperStub projectHelper = new ProjectHelperStub();
+        String warName = "simple";
+        File webAppSource = createWebAppSource( testId );
+        File classesDir = createClassesDir( testId, true );
+        File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+
+        warArtifact.setFile( new File( "error.war" ) );
+        project.setArtifact( warArtifact );
+        this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+        setVariableValueToObject( mojo, "projectHelper", projectHelper );
+        setVariableValueToObject( mojo, "outputDirectory", outputDir );
+        setVariableValueToObject( mojo, "warName", warName );
+        mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+
+        mojo.execute();
+
+        //validate jar file
+        File expectedJarFile = new File( outputDir, "simple.war" );
+        HashSet jarContent = new HashSet();
+
+        assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
+        assertTrue( "war file was not set as primary artifact", project.getArtifact().getFile().getName()
+            .equals( "simple.war" ) );
+
+        JarFile jarFile = new JarFile( expectedJarFile );
+        JarEntry entry;
+        Enumeration enumeration = jarFile.entries();
+
+        while ( enumeration.hasMoreElements() )
+        {
+            entry = (JarEntry) enumeration.nextElement();
+            jarContent.add( entry.getName() );
+        }
+
+        assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) );
+        assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) );
+        assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) );
+        assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent
+            .contains( "org/web/app/last-exile.jsp" ) );
+        assertTrue( "pom file not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+        assertTrue( "pom properties not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+    }
+
+    public void testNotPrimaryArtifact()
+        throws Exception
+    {
+        // use a different pom
+        File pom = new File( getBasedir(), "target/test-classes/unit/warmojotest/not-primary-artifact.xml" );
+        mojo = (WarMojo) lookupMojo( "war", pom );
+
+        String testId = "NotPrimaryArtifact";
+        MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
+        String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
+        File webAppDirectory = new File( getTestDirectory(), testId );
+        SimpleWarArtifact4CCStub warArtifact = new SimpleWarArtifact4CCStub( getBasedir() );
+        ProjectHelperStub projectHelper = new ProjectHelperStub();
+        String warName = "simple";
+        File webAppSource = createWebAppSource( testId );
+        File classesDir = createClassesDir( testId, true );
+        File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
+
+        warArtifact.setFile( new File( "error.war" ) );
+        project.setArtifact( warArtifact );
+        this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
+        setVariableValueToObject( mojo, "projectHelper", projectHelper );
+        setVariableValueToObject( mojo, "outputDirectory", outputDir );
+        setVariableValueToObject( mojo, "warName", warName );
+        mojo.setWebXml( new File( xmlSource, "web.xml" ) );
+
+        mojo.execute();
+
+        //validate jar file
+        File expectedJarFile = new File( outputDir, "simple.war" );
+        HashSet jarContent = new HashSet();
+
+        assertTrue( "war file not created: " + expectedJarFile.toString(), expectedJarFile.exists() );
+        assertTrue( "war file was set", project.getArtifact().getFile().getName().equals( "error.war" ) );
+
+        JarFile jarFile = new JarFile( expectedJarFile );
+        JarEntry entry;
+        Enumeration enumeration = jarFile.entries();
+
+        while ( enumeration.hasMoreElements() )
+        {
+            entry = (JarEntry) enumeration.nextElement();
+            jarContent.add( entry.getName() );
+        }
+
+        assertTrue( "manifest file not found", jarContent.contains( "META-INF/MANIFEST.MF" ) );
+        assertTrue( "web xml not found", jarContent.contains( "WEB-INF/web.xml" ) );
+        assertTrue( "web source not found: pansit.jsp", jarContent.contains( "pansit.jsp" ) );
+        assertTrue( "web source not found: org/web/app/last-exile.jsp", jarContent
+            .contains( "org/web/app/last-exile.jsp" ) );
+        assertTrue( "pom file not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml" ) );
+        assertTrue( "pom properties not found", jarContent
+            .contains( "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties" ) );
+    }
+}

Propchange: maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/WarMojoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml?rev=409310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml (added)
+++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml Wed May 24 23:16:33 2006
@@ -0,0 +1,13 @@
+<project>
+  <name>war-plugin-test</name>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-war-plugin</artifactId>
+        <configuration>
+        	  <primaryArtifact>false</primaryArtifact>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/not-primary-artifact.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml?rev=409310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml (added)
+++ maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml Wed May 24 23:16:33 2006
@@ -0,0 +1,13 @@
+<project>
+  <name>war-plugin-test</name>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-war-plugin</artifactId>
+        <configuration>
+        	  <primaryArtifact>true</primaryArtifact>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-war-plugin/src/test/resources/unit/warmojotest/plugin-config-primary-artifact.xml
------------------------------------------------------------------------------
    svn:eol-style = native