Skip to content
Permalink
Browse files

Merge pull request #11 from lkamal/master

[FIXED JENKINS-6446] added global configurations for all the six types of unittest changes (increase or descrease of passed, failed and skipped tests)
  • Loading branch information...
simschla committed Nov 3, 2013
2 parents 321ce5b + 57b4377 commit c66201634b4310a7e1bb157c36026631093b22c1
Showing with 597 additions and 310 deletions.
  1. +1 −1 pom.xml
  2. +73 −1 src/main/java/hudson/plugins/cigame/GameDescriptor.java
  3. +24 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractFailedTestsRule.java
  4. +25 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractPassedTestsRule.java
  5. +23 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractSkippedTestsRule.java
  6. +3 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractUnitTestsRule.java
  7. +42 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingFailedTestsRule.java
  8. +42 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingPassedTestsRule.java
  9. +42 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingSkippedTestsRule.java
  10. +21 −33 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingFailedTestsRule.java
  11. +24 −48 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingPassedTestsRule.java
  12. +41 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingSkippedTestsRule.java
  13. +0 −38 src/main/java/hudson/plugins/cigame/rules/unittesting/RemovedFailedTestsRule.java
  14. +0 −129 src/main/java/hudson/plugins/cigame/rules/unittesting/RemovedPassedTestsRule.java
  15. +15 −4 src/main/java/hudson/plugins/cigame/rules/unittesting/UnitTestingRuleSet.java
  16. +29 −5 src/main/resources/hudson/plugins/cigame/GamePublisher/global.jelly
  17. +9 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/global.properties
  18. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-failedTestDecreasingPoints.html
  19. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-failedTestIncreasingPoints.html
  20. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-passedTestDecreasingPoints.html
  21. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-passedTestIncreasingPoints.html
  22. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-skippedTestDecreasingPoints.html
  23. +5 −0 src/main/resources/hudson/plugins/cigame/GamePublisher/help-skippedTestIncreasingPoints.html
  24. +10 −6 src/main/resources/hudson/plugins/cigame/rules/unittesting/Messages.properties
  25. +42 −13 src/test/java/hudson/plugins/cigame/rules/unittesting/IncreasingFailedTestsRuleTest.java
  26. +61 −19 src/test/java/hudson/plugins/cigame/rules/unittesting/IncreasingPassedTestsRuleTest.java
  27. +40 −13 src/test/java/hudson/plugins/cigame/rules/unittesting/MavenMultiModuleUnitTestsTest.java
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.498</version>
<version>1.499</version>
</parent>

<artifactId>ci-game</artifactId>
@@ -19,6 +19,7 @@
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;

// Config page for the application (descriptor of the game plugin)
@Extension
public class GameDescriptor extends BuildStepDescriptor<Publisher> {

@@ -27,6 +28,13 @@

private transient RuleBook rulebook;
private boolean namesAreCaseSensitive = true;

private int passedTestIncreasingPoints = 1;
private int passedTestDecreasingPoints = 0;
private int failedTestIncreasingPoints = -1;
private int failedTestDecreasingPoints = 0;
private int skippedTestIncreasingPoints = 0;
private int skippedTestDecreasingPoints = 0;

public GameDescriptor() {
super(GamePublisher.class);
@@ -60,24 +68,27 @@ private void addRuleSetIfAvailable(RuleBook book, RuleSet ruleSet) {
}
}

// config page heading
@Override
public String getDisplayName() {
return Messages.Plugin_Title();
}

// creates a instance with form data; but this only creates empty new object
@Override
public GamePublisher newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {
return new GamePublisher();
}

// invoked when even properties are updated (global properties configured with global.jelly
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
req.bindJSON(this, json);
save();
return true;
}

public boolean getNamesAreCaseSensitive() {
return namesAreCaseSensitive;
}
@@ -90,4 +101,65 @@ public void setNamesAreCaseSensitive(boolean namesAreCaseSensitive) {
public boolean isApplicable(Class<? extends AbstractProject> arg0) {
return true;
}


public int getPassedTestIncreasingPoints() {
return passedTestIncreasingPoints;
}


public void setPassedTestIncreasingPoints(int passedTestIncreasingPoints) {
this.passedTestIncreasingPoints = passedTestIncreasingPoints;
}


public int getPassedTestDecreasingPoints() {
return passedTestDecreasingPoints;
}


public void setPassedTestDecreasingPoints(int passedTestDecreasingPoints) {
this.passedTestDecreasingPoints = passedTestDecreasingPoints;
}


public int getFailedTestIncreasingPoints() {
return failedTestIncreasingPoints;
}


public void setFailedTestIncreasingPoints(int failedTestIncreasingPoints) {
this.failedTestIncreasingPoints = failedTestIncreasingPoints;
}


public int getFailedTestDecreasingPoints() {
return failedTestDecreasingPoints;
}


public void setFailedTestDecreasingPoints(int failedTestDecreasingPoints) {
this.failedTestDecreasingPoints = failedTestDecreasingPoints;
}


public int getSkippedTestIncreasingPoints() {
return skippedTestIncreasingPoints;
}


public void setSkippedTestIncreasingPoints(int skippedTestIncreasingPoints) {
this.skippedTestIncreasingPoints = skippedTestIncreasingPoints;
}


public int getSkippedTestDecreasingPoints() {
return skippedTestDecreasingPoints;
}


public void setSkippedTestDecreasingPoints(int skippedTestDecreasingPoints) {
this.skippedTestDecreasingPoints = skippedTestDecreasingPoints;
}

}
@@ -0,0 +1,24 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of failed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractFailedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int failedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate(testResult.getFailCount() - previousTestResult.getFailCount());
}

}
@@ -0,0 +1,25 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of passed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractPassedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int passedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate((testResult.getTotalCount() - testResult.getFailCount() - testResult.getSkipCount())
- (previousTestResult.getTotalCount() - previousTestResult.getFailCount() - previousTestResult.getSkipCount()));
}

}
@@ -0,0 +1,23 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of skipped
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractSkippedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int skippedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {
return evaluate(testResult.getSkipCount() - previousTestResult.getSkipCount());
}

}
@@ -100,6 +100,9 @@ public int getSkipCount() {
prevResult = prevResult != null ? prevResult : Result.ABORTED;
result = result != null ? result : Result.ABORTED;

// if the current action is null, let's assume as a ZERO result
action = action != null ? action : ZERO_RESULT;

if ((prevResult.isBetterThan(Result.FAILURE))
&& (result.isBetterThan(Result.FAILURE))) {
return evaluate(action, prevAction);
@@ -0,0 +1,42 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of failed tests. By default 0 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingFailedTestsRule extends AbstractFailedTestsRule {

private static final int DEFAULT_POINTS = 0;

private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getFailedTestDecreasingPoints():DEFAULT_POINTS;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int failedTestDiff) {
if (failedTestDiff < 0) {
failedTestDiff = -failedTestDiff;
return new RuleResult<Integer>(failedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(failedTestDiff),
failedTestDiff);
}
return null;
}

}
@@ -0,0 +1,42 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of passed tests. By default -1 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingPassedTestsRule extends AbstractPassedTestsRule {

private static final int DEFAULT_POINTS = 1;

private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getPassedTestDecreasingPoints():DEFAULT_POINTS;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff < 0) {
passedTestDiff = -passedTestDiff;
return new RuleResult<Integer>(passedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
return null;
}

}
@@ -0,0 +1,42 @@
package hudson.plugins.cigame.rules.unittesting;

import jenkins.model.Jenkins;
import hudson.plugins.cigame.GameDescriptor;
import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of skipped tests. By default 0 marks given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingSkippedTestsRule extends AbstractSkippedTestsRule {

private static final int DEFAULT_POINTS = 0;

private int getPoints() {
GameDescriptor gameDescriptor = Jenkins.getInstance().getDescriptorByType(GameDescriptor.class);
return gameDescriptor!=null?gameDescriptor.getSkippedTestDecreasingPoints():DEFAULT_POINTS;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int skippedTestDiff) {
if (skippedTestDiff < 0) {
skippedTestDiff = -skippedTestDiff;
return new RuleResult<Integer>(skippedTestDiff * getPoints(),
Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(skippedTestDiff),
skippedTestDiff);
}
return null;
}

}

0 comments on commit c662016

Please sign in to comment.
You can’t perform that action at this time.