This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-29844] Workflow compatible. Added new tests (workflow specific)
- Loading branch information
Showing
7 changed files
with
227 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
target | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package hudson.plugins.pmd; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.Result; | ||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class PmdWorkflowTest { | ||
|
||
@Rule | ||
public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
|
||
/** | ||
* Run a workflow job using {@link PmdPublisher} and check for success. | ||
*/ | ||
@Test | ||
public void pmdPublisherWorkflowStep() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStep"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("pmd.xml"); | ||
report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'PmdPublisher'])\n" | ||
+ "}\n", true) | ||
); | ||
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0)); | ||
PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class); | ||
assertEquals(4, result.getResult().getAnnotations().size()); | ||
} | ||
|
||
/** | ||
* Run a workflow job using {@link PmdPublisher} with a failing threshold of 0, so the given example file | ||
* "/hudson/plugins/pmd/parser/4-pmd-warnings.xml" will make the build to fail. | ||
*/ | ||
@Test | ||
public void pmdPublisherWorkflowStepSetLimits() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStepSetLimits"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("pmd.xml"); | ||
report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'PmdPublisher', pattern: '**/pmd.xml', failedTotalAll: '0', usePreviousBuildAsReference: false])\n" | ||
+ "}\n", true) | ||
); | ||
jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); | ||
PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class); | ||
assertEquals(4, result.getResult().getAnnotations().size()); | ||
} | ||
|
||
/** | ||
* Run a workflow job using {@link PmdPublisher} with a unstable threshold of 0, so the given example file | ||
* "/hudson/plugins/pmd/parser/4-pmd-warnings.xml" will make the build to fail. | ||
*/ | ||
@Test | ||
public void pmdPublisherWorkflowStepFailure() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "pmdPublisherWorkflowStepFailure"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("pmd.xml"); | ||
report.copyFrom(PmdWorkflowTest.class.getResourceAsStream("/hudson/plugins/pmd/parser/4-pmd-warnings.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'PmdPublisher', pattern: '**/pmd.xml', unstableTotalAll: '0', usePreviousBuildAsReference: false])\n" | ||
+ "}\n") | ||
); | ||
jenkinsRule.assertBuildStatus(Result.UNSTABLE, job.scheduleBuild2(0).get()); | ||
PmdResultAction result = job.getLastBuild().getAction(PmdResultAction.class); | ||
assertEquals(4, result.getResult().getAnnotations().size()); | ||
} | ||
} | ||
|