Skip to content

Commit

Permalink
JENKINS-22546: Added initial api functions to robot result
Browse files Browse the repository at this point in the history
  • Loading branch information
japiiron committed May 28, 2014
1 parent 806648a commit 388c437
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/hudson/plugins/robot/model/RobotResult.java
Expand Up @@ -17,6 +17,7 @@

import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Api;
import hudson.model.DirectoryBrowserSupport;
import hudson.plugins.robot.RobotBuildAction;
import hudson.plugins.robot.graph.RobotGraphHelper;
Expand All @@ -36,12 +37,15 @@
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;


/**
* Class representing Robot Framework test results.
*
*/
@ExportedBean
public class RobotResult extends RobotTestObject {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -78,6 +82,7 @@ public String getName() {
* Get number of passed critical tests.
* @return
*/
@Exported
public long getCriticalPassed(){
if(overallStats == null) return criticalPassed;
if(overallStats.isEmpty()) return 0;
Expand All @@ -88,6 +93,7 @@ public long getCriticalPassed(){
* Get number of failed critical tests.
* @return
*/
@Exported
public long getCriticalFailed(){
if(overallStats == null) return criticalFailed;
if( overallStats.isEmpty()) return 0;
Expand All @@ -98,6 +104,7 @@ public long getCriticalFailed(){
* Get total number of critical tests.
* @return
*/
@Exported
public long getCriticalTotal(){
if(overallStats == null) return criticalFailed + criticalPassed;
if(overallStats.isEmpty()) return 0;
Expand All @@ -108,6 +115,7 @@ public long getCriticalTotal(){
* Get number of all passed tests.
* @return
*/
@Exported
public long getOverallPassed(){
if(overallStats == null) return passed;
if(overallStats.isEmpty()) return 0;
Expand All @@ -118,6 +126,7 @@ public long getOverallPassed(){
* Get number of all failed tests.
* @return
*/
@Exported
public long getOverallFailed(){
if(overallStats == null) return failed;
if(overallStats.isEmpty()) return 0;
Expand All @@ -128,6 +137,7 @@ public long getOverallFailed(){
* Get number of all tests.
* @return
*/
@Exported
public long getOverallTotal(){
if(overallStats == null) return failed + passed;
if(overallStats.isEmpty()) return 0;
Expand All @@ -150,6 +160,7 @@ public void setStatsByCategory(List<RobotResultStatistics> statsByCategory) {
* Get the timestamp of the original test run
* @return
*/
@Exported
public String getTimeStamp() {
return timeStamp;
}
Expand Down Expand Up @@ -183,6 +194,11 @@ public double getPassPercentage(boolean onlyCritical) {
return roundToDecimals(percentage, 1);
}

@Exported
public double getPassPercentage(){
return getPassPercentage(false);
}

private static double roundToDecimals(double value, int decimals){
BigDecimal bd = new BigDecimal(Double.toString(value));
bd = bd.setScale(decimals, BigDecimal.ROUND_DOWN);
Expand Down Expand Up @@ -235,6 +251,7 @@ public void addSuite(RobotSuiteResult suite){
* Get all top level suites
* @return Collection of suiteresults
*/
@Exported
public Collection<RobotSuiteResult> getSuites(){
if (suites != null)
return suites.values();
Expand All @@ -259,6 +276,7 @@ public List<RobotSuiteResult> getAllSuites(){
* Get all failed test cases related to result.
* @return list of test case results
*/
@Exported
public List<RobotCaseResult> getAllFailedCases(){
List<RobotCaseResult> allFailedCases = new ArrayList<RobotCaseResult>();
for(RobotSuiteResult suite : getSuites()){
Expand Down Expand Up @@ -398,4 +416,6 @@ public int getFailed() {
public int getPassed() {
return (int) getOverallPassed();
}

public Api getApi() { return new Api(this); }
}

0 comments on commit 388c437

Please sign in to comment.