EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.maven.continuum.web.action]

COVERAGE SUMMARY FOR SOURCE FILE [SurefireReportAction.java]

nameclass, %method, %block, %line, %
SurefireReportAction.java0%   (0/1)0%   (0/19)0%   (0/277)0%   (0/71)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SurefireReportAction0%   (0/1)0%   (0/19)0%   (0/277)0%   (0/71)
SurefireReportAction (): void 0%   (0/1)0%   (0/3)0%   (0/1)
execute (): String 0%   (0/1)0%   (0/33)0%   (0/9)
getBuildId (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getDetails (List): void 0%   (0/1)0%   (0/124)0%   (0/24)
getProject (): Project 0%   (0/1)0%   (0/3)0%   (0/1)
getProjectById (int): Project 0%   (0/1)0%   (0/5)0%   (0/1)
getProjectGroupName (): String 0%   (0/1)0%   (0/7)0%   (0/1)
getProjectId (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getProjectName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getSummary (List): void 0%   (0/1)0%   (0/60)0%   (0/16)
getTestPackageList (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getTestSuites (): List 0%   (0/1)0%   (0/3)0%   (0/1)
getTestSummaryList (): List 0%   (0/1)0%   (0/3)0%   (0/1)
setBuildId (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
setProjectId (int): void 0%   (0/1)0%   (0/4)0%   (0/2)
setProjectName (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setTestPackageList (List): void 0%   (0/1)0%   (0/4)0%   (0/2)
setTestSuites (List): void 0%   (0/1)0%   (0/4)0%   (0/2)
setTestSummaryList (List): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package org.apache.maven.continuum.web.action;
2 
3/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.LinkedHashMap;
25import java.util.List;
26import java.util.Map;
27 
28import org.apache.maven.continuum.ContinuumException;
29import org.apache.maven.continuum.configuration.ConfigurationException;
30import org.apache.maven.continuum.model.project.Project;
31import org.apache.maven.continuum.reports.surefire.ReportTest;
32import org.apache.maven.continuum.reports.surefire.ReportTestSuite;
33import org.apache.maven.continuum.reports.surefire.ReportTestSuiteGenerator;
34import org.apache.maven.continuum.reports.surefire.ReportTestSuiteGeneratorException;
35import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
36 
37/**
38 * @author Edwin Punzalan
39 * @version $Id: SurefireReportAction.java 769240 2009-04-28 04:59:03Z evenisse $
40 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="surefireReport"
41 * @todo too many inner classes, maybe a continuum-reports project group ?
42 */
43public class SurefireReportAction
44    extends ContinuumActionSupport
45{
46    /**
47     * @plexus.requirement
48     */
49    private ReportTestSuiteGenerator reportTestSuiteGenerator;
50 
51    private int buildId;
52 
53    private int projectId;
54 
55    private List<ReportTestSuite> testSuites;
56 
57    private List<ReportTest> testSummaryList;
58 
59    private List<ReportTest> testPackageList;
60 
61    private String projectName;
62 
63    private Project project;
64 
65    public String execute()
66        throws ContinuumException, ConfigurationException, ReportTestSuiteGeneratorException
67    {
68        try
69        {
70            checkViewProjectGroupAuthorization( getProjectGroupName() );
71        }
72        catch ( AuthorizationRequiredException e )
73        {
74            return REQUIRES_AUTHORIZATION;
75        }
76 
77        project = getProjectById( projectId );
78 
79        testSuites = reportTestSuiteGenerator.generateReports( buildId, projectId );
80 
81        getSummary( testSuites );
82 
83        getDetails( testSuites );
84 
85        return SUCCESS;
86    }
87 
88    private void getSummary( List<ReportTestSuite> suiteList )
89    {
90        int totalTests = 0;
91 
92        int totalErrors = 0;
93 
94        int totalFailures = 0;
95 
96        float totalTime = 0.0f;
97 
98        for ( ReportTestSuite suite : suiteList )
99        {
100            totalTests += suite.getNumberOfTests();
101 
102            totalErrors += suite.getNumberOfErrors();
103 
104            totalFailures += suite.getNumberOfFailures();
105 
106            totalTime += suite.getTimeElapsed();
107        }
108 
109        ReportTest report = new ReportTest();
110        report.setTests( totalTests );
111        report.setErrors( totalErrors );
112        report.setFailures( totalFailures );
113        report.setElapsedTime( totalTime );
114 
115        testSummaryList = Collections.singletonList( report );
116    }
117 
118    private void getDetails( List<ReportTestSuite> suiteList )
119    {
120        Map<String, ReportTest> testsByPackage = new LinkedHashMap<String, ReportTest>();
121 
122        for ( ReportTestSuite suite : suiteList )
123        {
124            ReportTest report = testsByPackage.get( suite.getPackageName() );
125 
126            if ( report == null )
127            {
128                report = new ReportTest();
129 
130                report.setId( suite.getPackageName() );
131 
132                report.setName( suite.getPackageName() );
133            }
134 
135            report.setTests( report.getTests() + suite.getNumberOfTests() );
136            report.setErrors( report.getErrors() + suite.getNumberOfErrors() );
137            report.setFailures( report.getFailures() + suite.getNumberOfFailures() );
138            report.setElapsedTime( report.getElapsedTime() + suite.getTimeElapsed() );
139 
140            ReportTest reportTest = new ReportTest();
141            reportTest.setId( suite.getPackageName() + "." + suite.getName() );
142            reportTest.setName( suite.getName() );
143            reportTest.setTests( suite.getNumberOfTests() );
144            reportTest.setErrors( suite.getNumberOfErrors() );
145            reportTest.setFailures( suite.getNumberOfFailures() );
146            reportTest.setElapsedTime( suite.getTimeElapsed() );
147            reportTest.setChildren( suite.getTestCases() );
148 
149            report.getChildren().add( reportTest );
150 
151            testsByPackage.put( suite.getPackageName(), report );
152        }
153 
154        testPackageList = new ArrayList<ReportTest>( testsByPackage.values() );
155    }
156 
157    public int getBuildId()
158    {
159        return buildId;
160    }
161 
162    public void setBuildId( int buildId )
163    {
164        this.buildId = buildId;
165    }
166 
167    public Project getProject()
168    {
169        return project;
170    }
171 
172    public int getProjectId()
173    {
174        return projectId;
175    }
176 
177    public void setProjectId( int projectId )
178    {
179        this.projectId = projectId;
180    }
181 
182    public List<ReportTestSuite> getTestSuites()
183    {
184        return testSuites;
185    }
186 
187    public void setTestSuites( List<ReportTestSuite> testSuites )
188    {
189        this.testSuites = testSuites;
190    }
191 
192    public String getProjectName()
193    {
194        return projectName;
195    }
196 
197    public void setProjectName( String projectName )
198    {
199        this.projectName = projectName;
200    }
201 
202    public List<ReportTest> getTestSummaryList()
203    {
204        return testSummaryList;
205    }
206 
207    public void setTestSummaryList( List<ReportTest> testSummaryList )
208    {
209        this.testSummaryList = testSummaryList;
210    }
211 
212    public List<ReportTest> getTestPackageList()
213    {
214        return testPackageList;
215    }
216 
217    public void setTestPackageList( List<ReportTest> testPackageList )
218    {
219        this.testPackageList = testPackageList;
220    }
221 
222    public Project getProjectById( int projectId )
223        throws ContinuumException
224    {
225        return getContinuum().getProject( projectId );
226    }
227 
228    public String getProjectGroupName()
229        throws ContinuumException
230    {
231        return getProjectById( projectId ).getProjectGroup().getName();
232    }
233 
234}

[all classes][org.apache.maven.continuum.web.action]
EMMA 2.0.5312 (C) Vladimir Roubtsov