Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-30103] Tests have been reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Recena committed Aug 25, 2015
1 parent 1f4efa8 commit 0277ea7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -61,6 +61,12 @@
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<scm>
Expand Down
44 changes: 29 additions & 15 deletions src/test/java/hudson/plugins/dry/DryWorkflowTest.java
Expand Up @@ -2,18 +2,31 @@

import hudson.FilePath;
import hudson.model.Result;
import hudson.tasks.Maven;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Rule;
import org.junit.Test;
import org.junit.*;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.File;

import static org.junit.Assert.assertEquals;

/**
* In this test suite we initialize the Job workspaces with a resource (maven-project1.zip) that contains a Maven
* project with pmd-cpd configured.
*/
public class DryWorkflowTest {

@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();
@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();

private static Maven.MavenInstallation mavenInstallation;

@BeforeClass
public static void init() throws Exception {
mavenInstallation = jenkinsRule.configureMaven3();
}

/**
* Run a workflow job using {@link DryPublisher} and check for success.
Expand All @@ -22,10 +35,11 @@ public class DryWorkflowTest {
public void dryPublisherWorkflowStep() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dryPublisherWorkflowStep");
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
FilePath report = workspace.child("target").child("cpd.xml");
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
workspace.unzipFrom(getClass().getResourceAsStream("./maven-project1.zip"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " def mvnHome = tool '" + mavenInstallation.getName() + "'\n"
+ " sh \"${mvnHome}/bin/mvn clean install\"\n"
+ " step([$class: 'DryPublisher', highThreshold: 50, normalThreshold: 25])\n"
+ "}\n", true)
);
Expand All @@ -35,17 +49,17 @@ public void dryPublisherWorkflowStep() throws Exception {
}

/**
* Run a workflow job using {@link DryPublisher} with a failing threshold of 0, so the given example file
* "/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml" will make the build to fail.
* Run a workflow job using {@link DryPublisher} with a failing threshold of 0.
*/
@Test
public void dryPublisherWorkflowStepSetLimits() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dryPublisherWorkflowStepSetLimits");
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
FilePath report = workspace.child("target").child("cpd.xml");
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
workspace.unzipFrom(getClass().getResourceAsStream("./maven-project1.zip"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " def mvnHome = tool '" + mavenInstallation.getName() + "'\n"
+ " sh \"${mvnHome}/bin/mvn clean install\"\n"
+ " step([$class: 'DryPublisher', pattern: '**/cpd.xml', highThreshold: 50, normalThreshold:" +
" 25, failedTotalAll: '0', usePreviousBuildAsReference: false])\n"
+ "}\n", true)
Expand All @@ -56,20 +70,20 @@ public void dryPublisherWorkflowStepSetLimits() throws Exception {
}

/**
* Run a workflow job using {@link DryPublisher} with a unstable threshold of 0, so the given example file
* "/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml" will make the build to fail.
* Run a workflow job using {@link DryPublisher} with a unstable threshold of 0.
*/
@Test
public void dryPublisherWorkflowStepFailure() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "dryPublisherWorkflowStepFailure");
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
FilePath report = workspace.child("target").child("cpd.xml");
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
workspace.unzipFrom(getClass().getResourceAsStream("./maven-project1.zip"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " def mvnHome = tool '" + mavenInstallation.getName() + "'\n"
+ " sh \"${mvnHome}/bin/mvn clean install\"\n"
+ " step([$class: 'DryPublisher', pattern: '**/cpd.xml', highThreshold: 50, " +
"normalThreshold: 25, unstableTotalAll: '0', usePreviousBuildAsReference: false])\n"
+ "}\n")
+ "}\n", true)
);
jenkinsRule.assertBuildStatus(Result.UNSTABLE, job.scheduleBuild2(0).get());
DryResultAction result = job.getLastBuild().getAction(DryResultAction.class);
Expand Down
Binary file not shown.
18 changes: 0 additions & 18 deletions src/test/resources/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml

This file was deleted.

0 comments on commit 0277ea7

Please sign in to comment.