Skip to content

Commit

Permalink
[JENKINS-46206] Added a test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 18, 2017
1 parent 5baca37 commit 476d119
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/plugins/AbstractAnalysisTest.java
Expand Up @@ -582,6 +582,21 @@ private FreeStyleJob createFreeStyleJob() {
* @return the created pipeline
*/
protected WorkflowJob createPipelineWith(final String fileName, final String stepName) {
return createPipelineWith(fileName, stepName, StringUtils.EMPTY);
}

/**
* Creates a pipeline that enables the specified {@code stepName}. The first step of the pipeline copies the
* specified resource {@code fileName} as first instruction to the pipeline.
*
* @param fileName the name of the resource that will be copied to the pipeline (this file will be scanned for
* warnings)
* @param stepName the name of the publisher to run (as a pipeline step)
* @param additionalParameters additional parameters for the step (need to start with a comma)
* @return the created pipeline
*/
protected WorkflowJob createPipelineWith(final String fileName, final String stepName,
final String additionalParameters) {
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
String script = "node {\n"
+ job.copyResourceStep(fileName)
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/plugins/FindBugsPluginTest.java
Expand Up @@ -25,6 +25,7 @@

import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Consumer;

import org.jenkinsci.test.acceptance.junit.SmokeTest;
import org.jenkinsci.test.acceptance.junit.WithPlugins;
Expand Down Expand Up @@ -174,6 +175,28 @@ public void should_set_result_to_unstable_if_warning_found() {
buildJobAndWait(job).shouldBeUnstable();
}

/**
* Builds a pipeline project and checks if it is unstable.
*/
@Test

This comment has been minimized.

Copy link
@jglick

jglick Nov 20, 2017

Member

Does this not need to specify @WithPlugins?

This comment has been minimized.

Copy link
@uhafner

uhafner Nov 20, 2017

Author Member

Yes, thanks! I'll always run the tests with PLUGIN_DIR so these kind of bugs are hard to spot.

public void should_set_pipeline_result() {
verifyResult("unstable", Build::shouldBeUnstable);
verifyResult("failed", Build::shouldFail);
}

private void verifyResult(final String result, final Consumer<Build> buildResultCheck) {
String[] parameters = {", " + result + "TotalAll: '5'",
", " + result + "TotalHigh: '1'",
", " + result + "TotalNormal: '3'"};

for (String additionalParameters : parameters) {
WorkflowJob job = createPipelineWith(FILE_WITH_6_WARNINGS, "FindBugsPublisher",
additionalParameters);
Build build = buildJobAndWait(job);
buildResultCheck.accept(build);
}
}

/**
* Builds a maven project and checks if it failed.
*/
Expand Down

0 comments on commit 476d119

Please sign in to comment.