Author: jtolentino
Date: Fri Dec  8 09:59:23 2006
New Revision: 484675

URL: http://svn.apache.org/viewvc?view=rev&rev=484675
Log:
Pass configuration, generate report and test against expected result.

Added:
    
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/ResolvedIssuesExpectedResult.txt
    
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/VotesExpectedResult.txt
    
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/report-configuration-test.xml
Modified:
    
maven/sandbox/plugins/maven-swizzle-plugin/src/main/java/org/apache/maven/plugin/swizzle/ReportMojo.java
    
maven/sandbox/plugins/maven-swizzle-plugin/src/test/java/org/apache/maven/plugin/swizzle/ReportMojoTest.java

Modified: 
maven/sandbox/plugins/maven-swizzle-plugin/src/main/java/org/apache/maven/plugin/swizzle/ReportMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-swizzle-plugin/src/main/java/org/apache/maven/plugin/swizzle/ReportMojo.java?view=diff&rev=484675&r1=484674&r2=484675
==============================================================================
--- 
maven/sandbox/plugins/maven-swizzle-plugin/src/main/java/org/apache/maven/plugin/swizzle/ReportMojo.java
 (original)
+++ 
maven/sandbox/plugins/maven-swizzle-plugin/src/main/java/org/apache/maven/plugin/swizzle/ReportMojo.java
 Fri Dec  8 09:59:23 2006
@@ -20,21 +20,57 @@
 import org.apache.maven.plugin.MojoExecutionException;
 
 import org.codehaus.plexus.swizzle.JiraReport;
+import org.codehaus.plexus.swizzle.ReportConfiguration;
+import org.codehaus.plexus.swizzle.ReportGenerationException;
+
+import java.io.PrintStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
 
 /**
  * Goal which generates a swizzle report based on velocity template
- * supplied through a ReportConfiguration 
+ * supplied through a ReportConfiguration
  *
  * @goal generate
  */
 public class ReportMojo
     extends AbstractMojo
 {
+    /**
+     * @component
+     */
     private JiraReport report;
 
+    /**
+     * @parameter
+     */
+    private ReportConfiguration reportConfiguration;
+
+    /**
+     * @parameter
+     */
+    private String result;
+
     public void execute()
         throws MojoExecutionException
-    {
-        System.out.println( "This is template." );
+    {        
+        try
+        {
+            FileOutputStream out = new FileOutputStream( result );
+            PrintStream printStream = new PrintStream( out );
+
+            report.generateReport( reportConfiguration, printStream );
+        }
+        catch ( IOException fileException )
+        {
+            throw new MojoExecutionException(
+                "Problem encountered while writing the report output file: " + 
fileException.getStackTrace() );
+        }
+        catch ( ReportGenerationException reportException )
+        {
+            throw new MojoExecutionException(
+                "Problem encountered while generating the swizzle reports: " + 
reportException.getStackTrace() );
+        }
     }
+
 }

Modified: 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/java/org/apache/maven/plugin/swizzle/ReportMojoTest.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-swizzle-plugin/src/test/java/org/apache/maven/plugin/swizzle/ReportMojoTest.java?view=diff&rev=484675&r1=484674&r2=484675
==============================================================================
--- 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/java/org/apache/maven/plugin/swizzle/ReportMojoTest.java
 (original)
+++ 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/java/org/apache/maven/plugin/swizzle/ReportMojoTest.java
 Fri Dec  8 09:59:23 2006
@@ -20,6 +20,9 @@
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.FileReader;
 
 /**
  * Author: John Tolentino
@@ -37,4 +40,61 @@
 
         assertNotNull( mojo );
     }
+
+    public void testConfiguration()
+        throws Exception
+    {
+        File pom = new File( getBasedir(), 
"target/test-classes/unit/report-configuration-test.xml" );
+
+        String expected = getBasedir() + 
"/target/test-classes/unit/ResolvedIssuesExpectedResult.txt";
+        String actual = getBasedir() + 
"/target/test-classes/unit/ResolvedIssuesActualResult.txt";
+
+        File expectedFile = new File( expected );
+        File actualFile = new File( actual );
+
+        if ( actualFile.exists() )
+        {
+            actualFile.delete();
+        }
+
+        mojo = (ReportMojo) lookupMojo( "generate", pom );
+
+        assertNotNull( mojo );
+
+        mojo.execute();
+
+        assertNotNull( expected );
+        assertNotNull( actual );
+
+        assertTrue( actualFile.exists() );
+        assertTrue( expectedFile.exists() );
+
+        String expectedString = fileToString( expectedFile.getAbsolutePath() );
+        String actualString = fileToString( actualFile.getAbsolutePath() );
+
+        assertEquals( expectedString, actualString );
+
+    }
+
+    private static String fileToString( String inputFilename )
+        throws IOException
+    {
+        BufferedReader br = new BufferedReader( new FileReader( inputFilename 
) );
+        StringBuffer text = new StringBuffer();
+
+        try
+        {
+            String line;
+            while ( ( line = br.readLine() ) != null )
+            {
+                text.append( line );
+            }
+        }
+        finally
+        {
+            br.close();
+        }
+        return text.toString();
+    }
+
 }

Added: 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/ResolvedIssuesExpectedResult.txt
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/ResolvedIssuesExpectedResult.txt?view=auto&rev=484675
==============================================================================
--- 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/ResolvedIssuesExpectedResult.txt
 (added)
+++ 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/ResolvedIssuesExpectedResult.txt
 Fri Dec  8 09:59:23 2006
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<document>
+  <properties>
+    <title>Swizzle Resolved Issues Report</title>
+  </properties>
+  <body>
+    <section name="Issues Resolved for Swizzle [*]">
+      <ul>
+        <li>[SWIZZLE-1] <![CDATA[Unit Test Summary]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-6] <![CDATA[Fix the toilet]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-9] <![CDATA[Clean the pool]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-2] <![CDATA[Need Wilhemina to get some things from the 
store]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-3] <![CDATA[a loaf of bread]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-4] <![CDATA[a container of milk]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-5] <![CDATA[a stick of butter]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-8] <![CDATA[Get more colored lights for the disco 
ball]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-10] <![CDATA[Beer fridge for the garage]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-11] <![CDATA[Make sure the smoke alarms work]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-12] <![CDATA[Fix whole in the wall]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-13] <![CDATA[Test issue with attachments]]></li>
+      </ul>
+      <ul>
+        <li>[SWIZZLE-7] <![CDATA[Put a TV in the bathroom]]></li>
+      </ul>
+    </section>
+  </body>
+</document>
\ No newline at end of file

Added: 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/VotesExpectedResult.txt
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/VotesExpectedResult.txt?view=auto&rev=484675
==============================================================================
--- 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/VotesExpectedResult.txt
 (added)
+++ 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/VotesExpectedResult.txt
 Fri Dec  8 09:59:23 2006
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<document>
+  <properties>
+    <title>Project Votes Report</title>
+  </properties>
+  <body>
+    <section name="Issue Tracking Votes">
+      <table>
+        <tr>
+          <th>2</th>
+          <th>Swizzle</th>
+        </tr>
+        <tr>
+          <td>2</td>
+          <td><![CDATA[Beer fridge for the garage]]></td>
+        </tr>
+        <tr>
+          <td>0</td>
+          <td><![CDATA[Clean the pool]]></td>
+        </tr>
+        <tr>
+          <td>0</td>
+          <td><![CDATA[Make sure the smoke alarms work]]></td>
+        </tr>
+        <tr>
+          <td>0</td>
+          <td><![CDATA[Get more colored lights for the disco ball]]></td>
+        </tr>
+        <tr>
+          <td>0</td>
+          <td><![CDATA[Fix whole in the wall]]></td>
+        </tr>
+      </table>
+    </section>
+  </body>
+</document>
\ No newline at end of file

Added: 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/report-configuration-test.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/report-configuration-test.xml?view=auto&rev=484675
==============================================================================
--- 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/report-configuration-test.xml
 (added)
+++ 
maven/sandbox/plugins/maven-swizzle-plugin/src/test/resources/unit/report-configuration-test.xml
 Fri Dec  8 09:59:23 2006
@@ -0,0 +1,41 @@
+<!--
+
+Copyright 2006
+
+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>
+  <name>swizzle-plugin-test</name>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-swizzle-plugin</artifactId>
+        <configuration>
+          <reportConfiguration>
+            <jiraServerUrl>http://jira.codehaus.org</jiraServerUrl>
+            <projectKey>SWIZZLE</projectKey>
+            <projectVersion>*</projectVersion>
+            <template>org/codehaus/plexus/swizzle/ResolvedIssues.vm</template>
+          </reportConfiguration>
+          
<result>target/test-classes/unit/ResolvedIssuesActualResult.txt</result>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>


Reply via email to