Author: ptahchiev
Date: Thu May 22 09:55:32 2008
New Revision: 659156

URL: http://svn.apache.org/viewvc?rev=659156&view=rev
Log:
Added some tests for the cactifywar mojo.

Added:
    jakarta/cactus/trunk/integration/maven2/src/test/
    jakarta/cactus/trunk/integration/maven2/src/test/java/
    jakarta/cactus/trunk/integration/maven2/src/test/java/org/
    jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/
    jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/
    
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/
    
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/
    
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/
    
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java
   (with props)
    jakarta/cactus/trunk/integration/maven2/src/test/resources/
    jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/nowebxml.war
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/empty.war
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml
   (with props)
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/
    
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml
   (with props)
Modified:
    
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java

Modified: 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java?rev=659156&r1=659155&r2=659156&view=diff
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
 (original)
+++ 
jakarta/cactus/trunk/integration/maven2/src/main/java/org/apache/cactus/maven2/mojos/CactifyWarMojo.java
 Thu May 22 09:55:32 2008
@@ -174,6 +174,7 @@
     /**
      * The file that we want to produce.
      * @parameter
+     * @required
      */
     private File destFile;
     
@@ -209,12 +210,11 @@
     protected String projectVersion;
 
     /**
-     * Version of the artifact to be installed. Retrieved from POM file 
-     * if specified
+     * Version of the web.xml to create.
      *
-     * @parameter expression="${project.version}"
+     * @parameter
      */
-    protected String version;
+    protected String version = null;
     
     /**
      * Packaging type of the artifact to be installed. Retrieved from POM file 
@@ -240,7 +240,6 @@
      */
     public void execute() throws MojoExecutionException, MojoFailureException
        {
-               
         if(this.srcFile != null) 
         {
             getLog().info("Analyzing war: " + this.srcFile.getAbsolutePath());
@@ -286,6 +285,7 @@
             }
             else
             {
+                
                 if (this.version == null)
                 {
                     throw new MojoExecutionException("You need to specify "
@@ -445,7 +445,7 @@
         // so that it can get picked up by the War task
         //FileUtils fileUtils = FileUtils.newFileUtils();
         File tmpDir = createTempFile("cactus", "tmp.dir",
-            getProject().getBasedir(), true);
+            new File("."), true);
         tmpDir.mkdirs();
         tmpDir.deleteOnExit();
         File webXmlFile = null;

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java
 Thu May 22 09:55:32 2008
@@ -0,0 +1,186 @@
+/* 
+ * ========================================================================
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ * 
+ * ========================================================================
+ */
+package org.apache.cactus.integration.maven2.test;
+
+import java.io.File;
+
+import org.apache.cactus.maven2.mojos.CactifyWarMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+/**
+ * Some unit tests for the <code>CactifyWarMojo</code> class.
+ * 
+ * @author ptahchiev
+ */
+public class TestCactifyWarMojo extends AbstractMojoTestCase 
+{
+    /**
+     * The cactifyWarMojo instance.
+     */
+    private CactifyWarMojo cactifyWarMojo;
+    
+    /**
+     * Set-up method to instantiate the mojo.
+     */
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        this.cactifyWarMojo = new CactifyWarMojo();
+    }
+
+    /**
+     * Try to execute the mojo with no parameters set.
+     * We should expect an exception to be raised.
+     * 
+     * @throws MojoExecutionException
+     * @throws MojoFailureException
+     */
+    public void testNeitherSrcNorVersionAttributeSuppliedAtInstantiation() 
+        throws MojoExecutionException, MojoFailureException
+    {
+        try
+        {
+            cactifyWarMojo.execute();
+            fail("Should not come here.");
+        }
+        catch(MojoExecutionException mojex)
+        {
+            assertEquals("You need to specify either the [srcFile] " +
+                    "or the [version] attribute", mojex.getMessage());
+        }
+    }
+    
+    /**
+     * Test if you supply no arguments in the pom.xml you will get an 
+     * exception.
+     * 
+     * @throws Exception
+     */
+    public void testNoParametersSupplied()
+    throws Exception
+    {
+        File testPom = new File(getBasedir(), "target/test-classes/unit/basic-"
+               + "cactify-noparameters/plugin-config.xml");
+        CactifyWarMojo mojo = (CactifyWarMojo) lookupMojo("cactifywar", 
+                testPom);
+        assertNotNull(mojo);
+        try
+        {
+            mojo.execute();
+        }
+        catch(MojoExecutionException mojex)
+        {
+            assertEquals("You need to specify either the [srcFile] " +
+                    "or the [version] attribute", mojex.getMessage());
+        }
+    }
+    
+    /**
+     * Test if an empty source file (with no web.xml inside) is supplied 
+     * then an adequate exception is thrown.
+     * 
+     * @throws Exception
+     */
+//    public void testNoWebXmlSuppliedInSrcFile() throws Exception
+//    {
+//        File testPom = new File(getBasedir(), "target/test-classes/unit/"
+//               + "cactify-test-empty-src-file/plugin-config.xml");
+//        CactifyWarMojo mojo = (CactifyWarMojo) lookupMojo("cactifywar", 
+//                 testPom);
+//        assertNotNull(mojo);
+//        try
+//        {
+//            mojo.execute();
+//        }
+//        catch(MojoExecutionException mx)
+//        {
+//            assertEquals("Failed to get the original web.xml", 
mx.getMessage());  
+//        }
+//    }
+    
+    /**
+     * Test that if we specify wrong version an appropriate excption is thrown.
+     * @throws Exception
+     */
+    public void testIfVersionIsSetAndWrongMergeXmlParameterPassed() throws 
Exception
+    {
+        File testPom = new File(getBasedir(), "target/test-classes/unit/"
+                + "cactify-test-wrong-mergexml-specified/plugin-config.xml");
+         CactifyWarMojo mojo = (CactifyWarMojo) lookupMojo("cactifywar", 
+                  testPom);
+         assertNotNull(mojo);
+         try
+         {
+             mojo.execute();
+         }
+         catch(MojoExecutionException mx)
+         {
+             assertEquals("Could not merge deployment descriptors", 
mx.getMessage());  
+         }
+    }
+    
+    /**
+     * Test that if we specify wrong srcFile parameter appropriate 
+     * exception is thrown.
+     * @throws Exception
+     */
+    public void testWrongSrcParameterPassed() throws Exception
+    {
+        File testPom = new File(getBasedir(), "target/test-classes/unit/"
+                + "cactify-test-wrong-src-parameter-passed/plugin-config.xml");
+         CactifyWarMojo mojo = (CactifyWarMojo) lookupMojo("cactifywar", 
+                  testPom);
+         assertNotNull(mojo);
+         try
+         {
+             mojo.execute();
+         }
+         catch(MojoExecutionException mx)
+         {
+             assertEquals("Failed to get the original web.xml", 
mx.getMessage());  
+         }
+    }
+    
+    /**
+     * Test that if we specify wrong srcFile parameter appropriate 
+     * exception is thrown.
+     * @throws Exception
+     */
+//    public void testWrongDestFileParameterPassed() throws Exception
+//    {
+//        File testPom = new File(getBasedir(), "target/test-classes/unit/"
+//                + 
"cactify-test-wrong-dest-parameter-passed/plugin-config.xml");
+//         CactifyWarMojo mojo = (CactifyWarMojo) lookupMojo("cactifywar", 
+//                  testPom);
+//         assertNotNull(mojo);
+//         try
+//         {
+//             mojo.execute();
+//         }
+//         catch(MojoExecutionException mx)
+//         {
+//             mx.printStackTrace();
+//             //assertEquals("Failed to get the original web.xml", 
mx.getMessage());  
+//         }
+//    }
+}

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/java/org/apache/cactus/integration/maven2/test/TestCactifyWarMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml
 Thu May 22 09:55:32 2008
@@ -0,0 +1,31 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.cactus</groupId>
+        <artifactId>cactus.integration.maven2</artifactId>
+               <configuration>
+               </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/basic-cactify-noparameters/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/nowebxml.war
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/nowebxml.war?rev=659156&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/nowebxml.war
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml
 Thu May 22 09:55:32 2008
@@ -0,0 +1,32 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.cactus</groupId>
+        <artifactId>cactus.integration.maven2</artifactId>
+               <configuration>
+                  
<srcFile>target/test-classes/unit/cactify-test-empty-src-file/nowebxml.war</srcFile>
+               </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-empty-src-file/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/empty.war
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/empty.war?rev=659156&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/empty.war
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml
 Thu May 22 09:55:32 2008
@@ -0,0 +1,33 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.cactus</groupId>
+        <artifactId>cactus.integration.maven2</artifactId>
+               <configuration>
+                  
<srcFile>target/test-classes/unit/cactify-test-wrong-dest-parameter-passed/empty.war</srcFile>
+                  <destFile>/null</destFile>
+               </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-dest-parameter-passed/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml
 Thu May 22 09:55:32 2008
@@ -0,0 +1,33 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.cactus</groupId>
+        <artifactId>cactus.integration.maven2</artifactId>
+               <configuration>
+                  <version>2.2</version>
+                  <mergeWebXml>/null</mergeWebXml>
+               </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-mergexml-specified/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml
URL: 
http://svn.apache.org/viewvc/jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml?rev=659156&view=auto
==============================================================================
--- 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml
 (added)
+++ 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml
 Thu May 22 09:55:32 2008
@@ -0,0 +1,32 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.cactus</groupId>
+        <artifactId>cactus.integration.maven2</artifactId>
+               <configuration>
+                  <srcFile>/null/</srcFile>
+               </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
jakarta/cactus/trunk/integration/maven2/src/test/resources/unit/cactify-test-wrong-src-parameter-passed/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to