Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'JENKINS-29908' of https://github.com/recena/dependency-…
…check-plugin into recena-JENKINS-29908 # Conflicts: # pom.xml
- Loading branch information
Showing
8 changed files
with
3,013 additions
and
15 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
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
79 changes: 79 additions & 0 deletions
79
src/test/java/org/jenkinsci/plugins/dependencycheck/DependencyCheckWorkflowTest.java
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,79 @@ | ||
package org.jenkinsci.plugins.dependencycheck; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.Result; | ||
import org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher; | ||
import org.jenkinsci.plugins.DependencyCheck.DependencyCheckResultAction; | ||
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.*; | ||
|
||
public class DependencyCheckWorkflowTest { | ||
|
||
@Rule | ||
public JenkinsRule jenkinsRule = new JenkinsRule(); | ||
|
||
/** | ||
* Run a workflow job using {@link org.jenkinsci.plugins.DependencyCheck.DependencyCheckPublisher} and check for success. | ||
*/ | ||
@Test | ||
public void dependencyCheckPublisherWorkflowStep() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dependencyCheckWorkPublisherWorkflowStep"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("dependency-check-report.xml"); | ||
report.copyFrom(DependencyCheckWorkflowTest.class.getResourceAsStream("/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'DependencyCheckPublisher'])\n" | ||
+ "}\n", true) | ||
); | ||
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0)); | ||
DependencyCheckResultAction result = job.getLastBuild().getAction(DependencyCheckResultAction.class); | ||
assertTrue(result.getResult().getAnnotations().size() == 2); | ||
} | ||
|
||
/** | ||
* Run a workflow job using {@link DependencyCheckPublisher} with a failing threshold of 0, so the given example file | ||
* "/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml" will make the build to fail. | ||
*/ | ||
@Test | ||
public void dependencyCheckPublisherWorkflowStepSetLimits() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dependencyCheckPublisherWorkflowStepSetLimits"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("dependency-check-report.xml"); | ||
report.copyFrom(DependencyCheckWorkflowTest.class.getResourceAsStream("/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'DependencyCheckPublisher', pattern: '**/dependency-check-report.xml', failedTotalAll: '0', usePreviousBuildAsReference: false])\n" | ||
+ "}\n", true) | ||
); | ||
jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); | ||
DependencyCheckResultAction result = job.getLastBuild().getAction(DependencyCheckResultAction.class); | ||
assertTrue(result.getResult().getAnnotations().size() == 2); | ||
} | ||
|
||
/** | ||
* Run a workflow job using {@link DependencyCheckPublisher} with a unstable threshold of 0, so the given example file | ||
* "/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml" will make the build to fail. | ||
*/ | ||
@Test | ||
public void dependencyCheckPublisherWorkflowStepFailure() throws Exception { | ||
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dependencyCheckPublisherWorkflowStepFailure"); | ||
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job); | ||
FilePath report = workspace.child("target").child("dependency-check-report.xml"); | ||
report.copyFrom(DependencyCheckWorkflowTest.class.getResourceAsStream("/org/jenkinsci/plugins/dependencycheck/parser/dependency-check-report2.xml")); | ||
job.setDefinition(new CpsFlowDefinition("" | ||
+ "node {\n" | ||
+ " step([$class: 'DependencyCheckPublisher', pattern: '**/dependency-check-report.xml', unstableTotalAll: '0', usePreviousBuildAsReference: false])\n" | ||
+ "}\n") | ||
); | ||
jenkinsRule.assertBuildStatus(Result.UNSTABLE, job.scheduleBuild2(0).get()); | ||
DependencyCheckResultAction result = job.getLastBuild().getAction(DependencyCheckResultAction.class); | ||
assertTrue(result.getResult().getAnnotations().size() == 2); | ||
} | ||
} | ||
|
Oops, something went wrong.