continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jzurb...@apache.org
Subject svn commit: r951292 - in /continuum/trunk: continuum-docs/src/site/apt/user_guides/report/ continuum-docs/src/site/resources/images/ continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ continuum-webapp-test/src/test/testng/org/apache/c...
Date Fri, 04 Jun 2010 06:19:58 GMT
Author: jzurbano
Date: Fri Jun  4 06:19:57 2010
New Revision: 951292

URL: http://svn.apache.org/viewvc?rev=951292&view=rev
Log:
[CONTINUUM-2521] builds report page
* added export to csv file
* added unit test to check the contents of the exported file
* updated selenium tests
* updated documentation
* adjusted formats in page


Modified:
    continuum/trunk/continuum-docs/src/site/apt/user_guides/report/index.apt
    continuum/trunk/continuum-docs/src/site/resources/images/projectBuildsReportResults.png
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ReportTest.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
    continuum/trunk/continuum-webapp/src/main/resources/struts.xml
    continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/viewProjectBuildsReport.jsp
    continuum/trunk/continuum-webapp/src/test/java/org/apache/continuum/web/action/ViewBuildsReportActionTest.java

Modified: continuum/trunk/continuum-docs/src/site/apt/user_guides/report/index.apt
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-docs/src/site/apt/user_guides/report/index.apt?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-docs/src/site/apt/user_guides/report/index.apt (original)
+++ continuum/trunk/continuum-docs/src/site/apt/user_guides/report/index.apt Fri Jun  4 06:19:57
2010
@@ -37,4 +37,6 @@ Project Builds Report
 
 * Project Builds Report Sample
 
+  To export the builds report to a CSV file, click the link <<Export to CSV>>
+
 [../../images/projectBuildsReportResults.png] Project Builds Report

Modified: continuum/trunk/continuum-docs/src/site/resources/images/projectBuildsReportResults.png
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-docs/src/site/resources/images/projectBuildsReportResults.png?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
Binary files - no diff available.

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ReportTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ReportTest.java?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ReportTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/ReportTest.java
Fri Jun  4 06:19:57 2010
@@ -86,8 +86,8 @@ public class ReportTest
         setFieldValue( "rowCount", "1" );
         clickButtonWithValue( "View Report" );
 
-        assertProjectBuildReportWithNoResult();
-        assertTextPresent( "Row count must be larger than 10" );
+        assertProjectBuildReportWithFieldError();
+        assertTextPresent( "Row count should be at least 10." );
     }
 
     @Test
@@ -98,7 +98,7 @@ public class ReportTest
         setFieldValue( "endDate", "05/24/2010" );
         clickButtonWithValue( "View Report" );
 
-        assertProjectBuildReportWithNoResult();
+        assertProjectBuildReportWithFieldError();
         assertTextPresent( "Start Date must be earlier than the End Date" );
     }
 

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
Fri Jun  4 06:19:57 2010
@@ -1126,6 +1126,8 @@ public abstract class AbstractContinuumT
     public void assertViewBuildsReportPage()
     {
         assertPage( "Continuum - Project Builds Report" );
+        assertTextPresent( "Project Group" );
+        assertElementPresent( "projectGroupId" );
         assertTextPresent( "Start Date" );
         assertElementPresent( "startDate" );
         assertTextPresent( "End Date" );
@@ -1137,18 +1139,22 @@ public abstract class AbstractContinuumT
         assertTextPresent( "Row Count" );
         assertElementPresent( "rowCount" );
         assertButtonWithValuePresent( "View Report" );
-        assertTextPresent( "Results" );
+        assertTextNotPresent( "Results" );
+        assertTextNotPresent( "No Results Found" );
+        assertTextNotPresent( "Export to CSV" );
     }
     
     public void assertProjectBuildReportWithResult()
     {
+        assertTextPresent( "Results" );
         assertTextPresent( "Project Group" );
-        assertTextPresent( "Project" );
+        assertTextPresent( "Project Name" );
         assertTextPresent( "Build Date" );
         assertTextPresent( "Triggered By" );
         assertTextPresent( "Build Status" );
         assertTextPresent( "Prev" );
         assertTextPresent( "Next" );
+        assertTextPresent( "Export to CSV" );
     }
 
     public void assertProjectBuildReportWithNoResult()
@@ -1156,6 +1162,18 @@ public abstract class AbstractContinuumT
         assertTextNotPresent( "Build Date" );
         assertTextNotPresent( "Prev" );
         assertTextNotPresent( "Next" );
+        assertTextNotPresent( "Export to CSV" );
+        assertTextPresent( "Results" );
         assertTextPresent( "No Results Found" );
     }
+
+    public void assertProjectBuildReportWithFieldError()
+    {
+        assertTextNotPresent( "Build Date" );
+        assertTextNotPresent( "Prev" );
+        assertTextNotPresent( "Next" );
+        assertTextNotPresent( "Export to CSV" );
+        assertTextNotPresent( "Results" );
+        assertTextNotPresent( "No Results Found" );
+    }
 }

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/continuum/web/action/ViewBuildsReportAction.java
Fri Jun  4 06:19:57 2010
@@ -19,6 +19,10 @@ package org.apache.continuum.web.action;
  * under the License.
  */
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -28,6 +32,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.apache.maven.continuum.model.project.BuildResult;
@@ -66,6 +71,10 @@ public class ViewBuildsReportAction
 
     private List<ProjectBuildsSummary> projectBuilds;
 
+    private InputStream inputStream;
+    
+    public static final String SEND_FILE = "send-file";
+
     private static final String[] datePatterns =
         new String[]{"MM/dd/yy", "MM/dd/yyyy", "MMMMM/dd/yyyy", "MMMMM/dd/yy", "dd MMMMM
yyyy", "dd/MM/yy",
             "dd/MM/yyyy", "yyyy/MM/dd", "yyyy-MM-dd", "yyyy-dd-MM", "MM-dd-yyyy", "MM-dd-yy"};
@@ -170,7 +179,7 @@ public class ViewBuildsReportAction
         if ( buildResults != null && !buildResults.isEmpty() )
         {
             projectBuilds = mapBuildResultsToProjectBuildsSummaries( buildResults );
-    
+
             int extraPage = ( projectBuilds.size() % rowCount ) != 0 ? 1 : 0;
             numPages = ( projectBuilds.size() / rowCount ) + extraPage;
     
@@ -182,18 +191,123 @@ public class ViewBuildsReportAction
             }
     
             int start = rowCount * ( page - 1 );
-            int end = ( start + rowCount ) - 1;
+            int end = ( start + rowCount );
     
             if ( end > projectBuilds.size() )
             {
-                end = projectBuilds.size() - 1;
+                end = projectBuilds.size();
             }
 
-            projectBuilds = projectBuilds.subList( start, end + 1 );
+            projectBuilds = projectBuilds.subList( start, end );
         }
 
         return SUCCESS;
     }
+    
+    /*
+     * Export Builds Report to .csv
+     */
+    public String downloadBuildsReport()
+    {
+        try
+        {
+            checkViewReportsAuthorization();
+        }
+        catch ( AuthorizationRequiredException authzE )
+        {
+            addActionError( authzE.getMessage() );
+            return REQUIRES_AUTHORIZATION;
+        }
+
+        long fromDate = 0;
+        long toDate = 0;
+
+        try
+        {
+            if ( !StringUtils.isEmpty( startDate ) )
+            {
+                fromDate = DateUtils.parseDate( startDate, datePatterns ).getTime();
+            }
+            
+            if ( !StringUtils.isEmpty( endDate ) )
+            {
+                Date toDateInDateFormat = DateUtils.parseDate( endDate, datePatterns );
+                
+                Calendar toDateCal = Calendar.getInstance();
+                toDateCal.setTime( toDateInDateFormat );
+                toDateCal.set( Calendar.HOUR_OF_DAY, 23 );
+                toDateCal.set( Calendar.MINUTE, 59 );
+                toDateCal.set( Calendar.SECOND, 59 );
+                
+                toDate = toDateCal.getTimeInMillis();
+            }
+        }
+        catch ( ParseException e )
+        {
+            addActionError( "Error parsing date(s): " + e.getMessage() );
+            return ERROR;
+        }
+
+        if ( fromDate != 0 && toDate != 0 && new Date( fromDate ).after(
new Date( toDate ) ) )
+        {
+            addFieldError( "startDate", "Start Date must be earlier than the End Date" );
+            return INPUT;
+        }
+
+        List<BuildResult> buildResults = getContinuum().getBuildResultsInRange( projectGroupId,
fromDate, toDate, buildStatus, triggeredBy );
+        List<ProjectBuildsSummary> builds = Collections.emptyList();
+        
+        StringBuffer input = new StringBuffer( "Project Group,Project Name,Build Date,Triggered
By,Build Status\n" );
+
+        if ( buildResults != null && !buildResults.isEmpty() )
+        {
+            builds = mapBuildResultsToProjectBuildsSummaries( buildResults );
+            
+            for ( ProjectBuildsSummary build : builds )
+            {
+                input.append( build.getProjectGroupName() ).append( "," );
+                input.append( build.getProjectName() ).append( "," );
+                
+                input.append( new Date( build.getBuildDate() ) ).append( "," );
+                
+                input.append( build.getBuildTriggeredBy() ).append( "," );
+                
+                String status;
+                switch ( build.getBuildState() )
+                {
+                    case 2: status = "Ok";
+                            break;
+                    case 3: status = "Failed";
+                            break;
+                    case 4: status = "Error";
+                            break;
+                    case 6: status = "Building";
+                            break;
+                    case 7: status = "Checking Out";
+                            break;
+                    case 8: status = "Updating";
+                            break;
+                    default: status = "";
+                }
+                input.append( status );
+                input.append( "\n" );
+            }
+        }
+        
+        StringReader reader = new StringReader( input.toString() );
+
+        try
+        {
+            inputStream = new ByteArrayInputStream( IOUtils.toByteArray( reader ) );
+        }
+        catch ( IOException e )
+        {
+            addActionError( "Error occurred while generating CSV file." );
+            return ERROR;
+        }
+
+        return SEND_FILE;
+    }
 
     private List<ProjectBuildsSummary> mapBuildResultsToProjectBuildsSummaries( List<BuildResult>
buildResults )
     {
@@ -312,6 +426,11 @@ public class ViewBuildsReportAction
         return numPages;
     }
 
+    public InputStream getInputStream()
+    {
+        return inputStream;
+    }
+
     private boolean isAuthorized( String projectGroupName )
     {
         try

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
Fri Jun  4 06:19:57 2010
@@ -1278,7 +1278,7 @@ projectBuilds.report.view=View Report
 projectBuilds.report.prev=Prev
 projectBuilds.report.next=Next
 projectBuilds.report.projectGroup = Project Group
-projectBuilds.report.project=Project
+projectBuilds.report.project=Project Name
 projectBuilds.report.buildDate=Build Date
 projectBuilds.report.noResult=No Results Found
 

Modified: continuum/trunk/continuum-webapp/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/struts.xml?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/struts.xml (original)
+++ continuum/trunk/continuum-webapp/src/main/resources/struts.xml Fri Jun  4 06:19:57 2010
@@ -633,6 +633,15 @@
       <result name="input">/WEB-INF/jsp/viewProjectBuildsReport.jsp</result>
       <result name="success">/WEB-INF/jsp/viewProjectBuildsReport.jsp</result>
     </action>
+    
+    <action name="downloadProjectBuildsReport" class="projectBuildsReport" method="downloadBuildsReport">
+      <result name="input">/WEB-INF/jsp/viewProjectBuildsReport.jsp</result>
+      <result name="success">/WEB-INF/jsp/viewProjectBuildsReport.jsp</result>
+      <result name="send-file" type="stream">
+        <param name="contentType">${contentType}</param>
+        <param name="contentDisposition">attachment; filename="continuum_project_builds_report.csv"</param>
+      </result>
+    </action>
   </package>
 
   <!--

Modified: continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/viewProjectBuildsReport.jsp
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/viewProjectBuildsReport.jsp?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/viewProjectBuildsReport.jsp
(original)
+++ continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/viewProjectBuildsReport.jsp
Fri Jun  4 06:19:57 2010
@@ -86,66 +86,23 @@
      	  <h3>Results</h3>
      	  <c:choose>
        	  <c:when test="${not empty projectBuilds}">
-            <c:set var="prevPageUrl">
-              <s:url action="generateProjectBuildsReport">    
-                <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
-                <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
-                <s:param name="buildStatus" value="%{#attr.buildStatus}"/>
-                <s:param name="rowCount" value="%{#attr.rowCount}"/>
-                <s:param name="startDate" value="%{#attr.startDate}"/>            
         
-                <s:param name="endDate" value="%{#attr.endDate}"/>
-                <s:param name="page" value="%{#attr.page - 1}"/>
-              </s:url>
-            </c:set>
-            <c:set var="nextPageUrl">
-              <s:url action="generateProjectBuildsReport">    
-                <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
-                <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
-                <s:param name="buildStatus" value="%{#attr.buildStatus}"/>
-                <s:param name="rowCount" value="%{#attr.rowCount}"/>
-                <s:param name="startDate" value="%{#attr.startDate}"/>            
         
-                <s:param name="endDate" value="%{#attr.endDate}"/>          
-                <s:param name="page" value="%{#attr.page + 1}"/>
-              </s:url>
-            </c:set>
-            <c:choose>
-              <c:when test="${page == 1}">                               
-                <s:text name="projectBuilds.report.prev"/>
-              </c:when>
-              <c:otherwise>
-                <a href="${prevPageUrl}">
-                  <s:text name="projectBuilds.report.prev"/>
-                </a>
-              </c:otherwise>
-            </c:choose>
-
-            <c:choose>
-              <c:when test="${numPages > 11}">
-                <c:choose>
-                  <c:when test="${(page - 5) < 0}">
-                    <c:set var="beginVal">0</c:set>
-                    <c:set var="endVal">10</c:set> 
-                  </c:when>			        
-                  <c:when test="${(page + 5) > (numPages - 1)}">
-                    <c:set var="beginVal">${(numPages - 1) - 10}</c:set>
-                    <c:set var="endVal">${numPages - 1}</c:set>
-                  </c:when>
-                  <c:otherwise>
-                    <c:set var="beginVal">${page - 5}</c:set>
-                    <c:set var="endVal">${page + 5}</c:set>
-                  </c:otherwise>
-                </c:choose>  
-              </c:when>
-              <c:otherwise>
-                <c:set var="beginVal">0</c:set>
-                <c:set var="endVal">${numPages - 1}</c:set>
-              </c:otherwise>
-            </c:choose>
-
-            <c:forEach var="i" begin="${beginVal}" end="${endVal}">      
-              <c:choose>                   			    
-                <c:when test="${i != (page - 1)}">
-                  <c:set var="specificPageUrl">
+       	    
+       	    <table>
+         	    <tr>
+           	    <td>
+             	    <%-- Pagination --%>
+                  <c:set var="prevPageUrl">
+                    <s:url action="generateProjectBuildsReport">    
+                      <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
+                      <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
+                      <s:param name="buildStatus" value="%{#attr.buildStatus}"/>
+                      <s:param name="rowCount" value="%{#attr.rowCount}"/>
+                      <s:param name="startDate" value="%{#attr.startDate}"/>      
               
+                      <s:param name="endDate" value="%{#attr.endDate}"/>
+                      <s:param name="page" value="%{#attr.page - 1}"/>
+                    </s:url>
+                  </c:set>
+                  <c:set var="nextPageUrl">
                     <s:url action="generateProjectBuildsReport">    
                       <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
                       <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
@@ -153,27 +110,89 @@
                       <s:param name="rowCount" value="%{#attr.rowCount}"/>
                       <s:param name="startDate" value="%{#attr.startDate}"/>      
               
                       <s:param name="endDate" value="%{#attr.endDate}"/>          
-                      <s:param name="page" value="%{#attr.i + 1}"/>
+                      <s:param name="page" value="%{#attr.page + 1}"/>
                     </s:url>
                   </c:set>
-                  <a href="${specificPageUrl}">${i + 1}</a>
-                </c:when>
-                <c:otherwise>		
-                  <b>${i + 1}</b>   
-                </c:otherwise>				  			    
-              </c:choose>      
-            </c:forEach>
+                  <c:choose>
+                    <c:when test="${page == 1}">                               
+                      <s:text name="projectBuilds.report.prev"/>
+                    </c:when>
+                    <c:otherwise>
+                      <a href="${prevPageUrl}">
+                        <s:text name="projectBuilds.report.prev"/>
+                      </a>
+                    </c:otherwise>
+                  </c:choose>
+
+                  <c:choose>
+                    <c:when test="${numPages > 11}">
+                      <c:choose>
+                        <c:when test="${(page - 5) < 0}">
+                          <c:set var="beginVal">0</c:set>
+                          <c:set var="endVal">10</c:set> 
+                        </c:when>			        
+                        <c:when test="${(page + 5) > (numPages - 1)}">
+                          <c:set var="beginVal">${(numPages - 1) - 10}</c:set>
+                          <c:set var="endVal">${numPages - 1}</c:set>
+                        </c:when>
+                        <c:otherwise>
+                          <c:set var="beginVal">${page - 5}</c:set>
+                          <c:set var="endVal">${page + 5}</c:set>
+                        </c:otherwise>
+                      </c:choose>  
+                    </c:when>
+                    <c:otherwise>
+                      <c:set var="beginVal">0</c:set>
+                      <c:set var="endVal">${numPages - 1}</c:set>
+                    </c:otherwise>
+                  </c:choose>
+
+                  <c:forEach var="i" begin="${beginVal}" end="${endVal}">      
+                    <c:choose>                   			    
+                      <c:when test="${i != (page - 1)}">
+                        <c:set var="specificPageUrl">
+                          <s:url action="generateProjectBuildsReport">    
+                            <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
+                            <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
+                            <s:param name="buildStatus" value="%{#attr.buildStatus}"/>
+                            <s:param name="rowCount" value="%{#attr.rowCount}"/>
+                            <s:param name="startDate" value="%{#attr.startDate}"/>
                     
+                            <s:param name="endDate" value="%{#attr.endDate}"/>    
     
+                            <s:param name="page" value="%{#attr.i + 1}"/>
+                          </s:url>
+                        </c:set>
+                        <a href="${specificPageUrl}">${i + 1}</a>
+                      </c:when>
+                      <c:otherwise>		
+                        <b>${i + 1}</b>   
+                      </c:otherwise>				  			    
+                    </c:choose>      
+                  </c:forEach>
 
-            <c:choose>
-              <c:when test="${page == numPages}">
-                <s:text name="projectBuilds.report.next"/>
-              </c:when>
-      	      <c:otherwise>
-                <a href="${nextPageUrl}">
-                  <s:text name="projectBuilds.report.next"/>
-                </a>
-              </c:otherwise>   
-            </c:choose>
+                  <c:choose>
+                    <c:when test="${page == numPages}">
+                      <s:text name="projectBuilds.report.next"/>
+                    </c:when>
+            	      <c:otherwise>
+                      <a href="${nextPageUrl}">
+                        <s:text name="projectBuilds.report.next"/>
+                      </a>
+                    </c:otherwise>   
+                  </c:choose>
+           	    </td>
+           	    <td>
+                  <%-- Export to CSV link --%>
+                  <s:url id="downloadProjectBuildsReportUrl" action="downloadProjectBuildsReport"
namespace="/">
+                    <s:param name="projectGroupId" value="%{#attr.projectGroupId}"/>
+                    <s:param name="triggeredBy" value="%{#attr.triggeredBy}"/>
+                    <s:param name="buildStatus" value="%{#attr.buildStatus}"/>
+                    <s:param name="startDate" value="%{#attr.startDate}"/>
+                    <s:param name="endDate" value="%{#attr.endDate}"/>
+                  </s:url>
+                  <s:a href="%{downloadProjectBuildsReportUrl}">Export to CSV</s:a>
+                </td>
+              </tr>
+            </table>
 
             <s:set name="projectBuilds" value="projectBuilds" scope="request"/>
             <ec:table items="projectBuilds"

Modified: continuum/trunk/continuum-webapp/src/test/java/org/apache/continuum/web/action/ViewBuildsReportActionTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/test/java/org/apache/continuum/web/action/ViewBuildsReportActionTest.java?rev=951292&r1=951291&r2=951292&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/test/java/org/apache/continuum/web/action/ViewBuildsReportActionTest.java
(original)
+++ continuum/trunk/continuum-webapp/src/test/java/org/apache/continuum/web/action/ViewBuildsReportActionTest.java
Fri Jun  4 06:19:57 2010
@@ -20,10 +20,14 @@ package org.apache.continuum.web.action;
  */
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.List;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.continuum.web.action.stub.ViewBuildsReportActionStub;
 import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.Continuum;
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
@@ -117,10 +121,63 @@ public class ViewBuildsReportActionTest
         continuum.verify();
     }
 
+    public void testExportToCsv()
+        throws Exception
+    {
+        Calendar cal = Calendar.getInstance();
+        cal.set( 2010, 1, 1, 1, 1, 1 );
+        
+        List<BuildResult> results = createBuildResult( cal.getTimeInMillis() );
+        
+        continuum.expects( once() ).method( "getBuildResultsInRange" ).will( returnValue(
results ) );
+        action.setProjectGroupId( 0 );
+        action.setBuildStatus( 0 );
+        action.setStartDate( "" );
+        action.setEndDate( "" );
+        action.setTriggeredBy( "" );
+        
+        String result = action.downloadBuildsReport();
+        
+        assertEquals( "send-file", result );
+        assertFileContentsEqual( IOUtils.toString( action.getInputStream() ), cal.getTime().toString()
);
+        continuum.verify();
+    }
+
     private void assertSuccessResult( String result )
     {
         assertEquals( Action.SUCCESS, result );
         assertFalse( action.hasFieldErrors() );
         assertFalse( action.hasActionErrors() );
     }
+    
+    private List<BuildResult> createBuildResult( long timeInMillis )
+    {
+        List<BuildResult> results = new ArrayList<BuildResult>();
+        
+        BuildResult result = new BuildResult();
+        
+        ProjectGroup group = new ProjectGroup();
+        group.setName( "Test Group" );
+        
+        Project project = new Project();
+        project.setName( "Test Project" );
+        project.setProjectGroup( group );
+
+        result.setProject( project );
+        result.setState( 2 );
+        result.setStartTime( timeInMillis );
+        result.setUsername( "test-admin" );
+        
+        results.add( result );
+        
+        return results;
+    }
+    
+    private void assertFileContentsEqual( String report, String buildDate )
+    {
+        String result = "Project Group,Project Name,Build Date,Triggered By,Build Status\n"
+
+                        "Test Group,Test Project," + buildDate + ",test-admin,Ok\n";
+        
+        assertTrue( report.equals( result ) );
+    }
 }



Mime
View raw message