Skip to content

Commit

Permalink
[JENKINS-13458] Added a testcase to verify the original delta computa…
Browse files Browse the repository at this point in the history
…tion.

This test ensures that the build status is computed from the warnings delta of the current build and the reference build.
  • Loading branch information
uhafner committed Jan 3, 2015
1 parent c3ad1b9 commit 67eaa6d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 17 deletions.
Expand Up @@ -33,6 +33,7 @@ public abstract class AnalysisSettings extends PageAreaImpl implements PostBuild

protected Control canComputeNew = control("canComputeNew");
protected Control newWarningsThresholdFailed = control("canComputeNew/failedNewAll");
protected Control newWarningsThresholdUnstable = control("canComputeNew/unstableNewAll");
protected Control useDeltaValues = control("canComputeNew/useDeltaValues");

/**
Expand Down Expand Up @@ -173,6 +174,16 @@ public void setNewWarningsThresholdFailed(String threshold) {
newWarningsThresholdFailed.set(threshold);
}

/**
* Build is marked as unstable if at least these new warnings are found.
* @param threshold number of new warnings to set the build to unstable.
*/
public void setNewWarningsThresholdUnstable(String threshold) {
ensureAdvancedClicked();
canComputeNew.check(true);
newWarningsThresholdUnstable.set(threshold);
}

/**
* Detect new warnings in comparison with the last build.
* @param deltaValues compare if true
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/org/jenkinsci/test/acceptance/po/Build.java
Expand Up @@ -25,9 +25,11 @@
* @author Kohsuke Kawaguchi
*/
public class Build extends ContainerPageObject {
public enum Result {SUCCESS, UNSTABLE, FAILURE, ABORTED, NOT_BUILT}

public final Job job;

private String result;
private Result result;

private boolean success;

Expand Down Expand Up @@ -168,12 +170,12 @@ public boolean isUnstable() {

public String getResult() {
if (result != null) {
return result;
return result.name();
}

waitUntilFinished();
result = getJson().get("result").asText();
return result;
result = Result.valueOf(getJson().get("result").asText());
return result.name();
}

public Artifact getArtifact(String artifact) {
Expand All @@ -193,30 +195,35 @@ public List<Artifact> getArtifacts() {
}

public Build shouldSucceed() {
assertThat(this, resultIs("SUCCESS"));
assertThat(this, resultIs(Result.SUCCESS));
return this;
}

public Build shouldFail() {
assertThat(this, resultIs("FAILURE"));
assertThat(this, resultIs(Result.FAILURE));
return this;
}

public Build shouldAbort() {
assertThat(this, resultIs("ABORTED"));
assertThat(this, resultIs(Result.ABORTED));
return this;
}

public Build shouldBeUnstable() {
assertThat(this, resultIs("UNSTABLE"));
assertThat(this, resultIs(Result.UNSTABLE));
return this;
}

public Build shouldBe(final Result result) {
assertThat(this, resultIs(result));
return this;
}

private Matcher<Build> resultIs(final String expected) {
private Matcher<Build> resultIs(final Result expected) {
return new Matcher<Build>("Build result %s", expected) {
@Override
public boolean matchesSafely(Build item) {
return item.getResult().equals(expected);
return item.getResult().equals(expected.name());
}

@Override
Expand Down
61 changes: 54 additions & 7 deletions src/test/java/plugins/CheckStylePluginTest.java
Expand Up @@ -17,6 +17,7 @@
import org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView;
import org.jenkinsci.test.acceptance.plugins.maven.MavenModuleSet;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.Build.Result;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.ListView;
import org.jenkinsci.test.acceptance.po.Node;
Expand All @@ -38,14 +39,17 @@
@WithPlugins("checkstyle")
public class CheckStylePluginTest extends AbstractAnalysisTest {
private static final String PATTERN_WITH_776_WARNINGS = "checkstyle-result.xml";
private static final String FILE_WITH_776_WARNINGS = "/checkstyle_plugin/" + PATTERN_WITH_776_WARNINGS;
private static final String CHECKSTYLE_PLUGIN_ROOT = "/checkstyle_plugin/";
private static final String FILE_WITH_776_WARNINGS = CHECKSTYLE_PLUGIN_ROOT + PATTERN_WITH_776_WARNINGS;
private static final String FILE_FOR_2ND_RUN = "/checkstyle_plugin/forSecondRun/checkstyle-result.xml";

/**
* Checks that the plug-in sends a mail after a build has been failed. The content of the mail
* contains several tokens that should be expanded in the mail with the correct vaules.
* Checks that the plug-in sends a mail after a build has been failed. The content of the mail contains several
* tokens that should be expanded in the mail with the correct vaules.
*/
@Test @WithPlugins("email-ext") @Bug("25501")
@Test
@WithPlugins("email-ext")
@Bug("25501")
public void should_send_mail_with_expanded_tokens() {
setUpMailer();

Expand Down Expand Up @@ -227,9 +231,9 @@ private MavenModuleSet setupSimpleMavenJob(AnalysisConfigurator<CheckstyleMavenB
}

/**
* Builds an existing freestyle project using actual maven commands and checks if new warning are displayed.
* Also verifies that the warnings have links to the actual source code and the source code view shows the
* affected line.
* Builds an existing freestyle project using actual maven commands and checks if new warning are displayed. Also
* verifies that the warnings have links to the actual source code and the source code view shows the affected
* line.
*/
@Test
public void build_simple_freestyle_mavengoals_project() {
Expand Down Expand Up @@ -390,4 +394,47 @@ public void configure(CheckstyleFreestyleBuildSettings settings) {
};
return setUpFreestyleJob(buildConfigurator);
}

/**
* Creates a sequence of Freestyle builds and checks if the build result is set correctly. New warning threshold is
* set to zero, e.g. a new warning should mark a build as unstable.
* <p/>
* <ol>
* <li>Build 1: 1 new warning (SUCCESS since no reference build is set)</li>
* <li>Build 2: 2 new warnings (UNSTABLE since threshold is reached)</li>
* <li>Build 3: 1 new warning (UNSTABLE since still one warning is new based on delta with reference build)</li>
* <li>Build 4: 1 new warning (SUCCESS since no reference build is set)</li>
* </ol>
*/
@Test
public void should_set_build_status_in_build_sequence() {
FreeStyleJob job = setupJob(FILE_WITH_776_WARNINGS, FreeStyleJob.class, CheckstyleFreestyleBuildSettings.class, null);

runBuild(job, 1, Result.SUCCESS, 1);
runBuild(job, 2, Result.UNSTABLE, 2);
runBuild(job, 3, Result.UNSTABLE, 1);
runBuild(job, 4, Result.SUCCESS, 0);
}

private void runBuild(final FreeStyleJob job, final int number, final Result expectedResult, final int expectedNewWarnings) {
final String fileName = "checkstyle-result-build" + number + ".xml";
AnalysisConfigurator<CheckstyleFreestyleBuildSettings> buildConfigurator = new AnalysisConfigurator<CheckstyleFreestyleBuildSettings>() {
@Override
public void configure(CheckstyleFreestyleBuildSettings settings) {
settings.setNewWarningsThresholdUnstable("0");
settings.pattern.set(fileName);
}
};

editJob(CHECKSTYLE_PLUGIN_ROOT + fileName, false, job,
CheckstyleFreestyleBuildSettings.class, buildConfigurator);
Build lastBuild = buildJobAndWait(job).shouldBe(expectedResult);

if (expectedNewWarnings > 0) {
assertThatBuildHasCheckstyleResults(lastBuild);
lastBuild.open();
CheckstyleAction checkstyle = new CheckstyleAction(job);
assertThat(checkstyle.getNewWarningNumber(), is(expectedNewWarnings));
}
}
}
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="/mnt/hudson_workspace/workspace/HTS-CheckstyleTest/ssh-slaves/src/main/java/hudson/plugins/sshslaves/RemoteLauncher.java">
<error line="0" severity="error" message="Missing package-info.java file." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck"/>
</file>
</checkstyle>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="/mnt/hudson_workspace/workspace/HTS-CheckstyleTest/ssh-slaves/src/main/java/hudson/plugins/sshslaves/RemoteLauncher.java">
<error line="0" severity="error" message="Missing package-info.java file." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck"/>
<error line="33" column="8" severity="error" message="Unused import - hudson.Functions." source="com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck"/>
<error line="57" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck"/>
</file>
</checkstyle>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="/mnt/hudson_workspace/workspace/HTS-CheckstyleTest/ssh-slaves/src/main/java/hudson/plugins/sshslaves/RemoteLauncher.java">
<error line="57" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck"/>
</file>
</checkstyle>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="5.0">
<file name="/mnt/hudson_workspace/workspace/HTS-CheckstyleTest/ssh-slaves/src/main/java/hudson/plugins/sshslaves/RemoteLauncher.java">
</file>
</checkstyle>

0 comments on commit 67eaa6d

Please sign in to comment.