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
recena committed Aug 24, 2015
1 parent d6d0924 commit b3a3fc1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
target
target/
work/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

Expand Down
22 changes: 18 additions & 4 deletions pom.xml
Expand Up @@ -25,7 +25,9 @@
</license>
<license>
<name>LGPL</name>
<comments>All icons are made by Carlitus (Carles Carbonell Bernado) and are under the LGPL.</comments>
<comments>All icons are made by Carlitus (Carles Carbonell
Bernado) and are under the LGPL.
</comments>
</license>
</licenses>

Expand All @@ -44,12 +46,12 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>-->
</dependency>
<dependency>
<groupId>de.java2html</groupId>
<artifactId>java2html</artifactId>
<version>5.0</version>
</dependency>
</dependency>-->
<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>analysis-test</artifactId>
Expand All @@ -58,7 +60,19 @@
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<artifactId>workflow-job</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow-jenkins-plugin.version}</version>
<scope>test</scope>
</dependency>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/hudson/plugins/dry/DryPublisher.java
Expand Up @@ -188,8 +188,7 @@ public Action getProjectAction(final AbstractProject<?, ?> project) {

@Override
public BuildResult perform(final Run<?, ?> build, final FilePath workspace, final PluginLogger logger) throws
InterruptedException,
IOException {
InterruptedException, IOException {
logger.log("Collecting duplicate code analysis files...");

FilesParser dryCollector = new FilesParser(PLUGIN_NAME, StringUtils.defaultIfEmpty(getPattern(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/dry/DryReporterResult.java
Expand Up @@ -55,7 +55,7 @@ public DryReporterResult(final AbstractBuild<?, ?> build, final String defaultEn
* reference builds or not
*/
public DryReporterResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
super(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
DryMavenResultAction.class);
}
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/hudson/plugins/dry/DryResult.java
Expand Up @@ -35,7 +35,7 @@ public class DryResult extends BuildResult {
* determines whether only stable builds should be used as
* reference builds or not
*
* @deprecated see {@link }
* @deprecated see {@link #DryResult(Run, String, ParserResult, boolean, boolean, Class)}
*/
@Deprecated
public DryResult(final AbstractBuild<?, ?> build, final String defaultEncoding, final ParserResult result,
Expand All @@ -60,7 +60,7 @@ public DryResult(final AbstractBuild<?, ?> build, final String defaultEncoding,
* reference builds or not
*/
public DryResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference) {
this(build, defaultEncoding, result, usePreviousBuildAsReference, useStableBuildAsReference,
DryResultAction.class);
}
Expand Down Expand Up @@ -111,21 +111,20 @@ protected DryResult(final AbstractBuild<?, ?> build, final String defaultEncodin
* the type of the result action
*/
protected DryResult(final Run<?, ?> build, final String defaultEncoding, final ParserResult result,
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final Class<? extends ResultAction<DryResult>> actionType) {
this(build, new BuildHistory(build, actionType, usePreviousBuildAsReference,
useStableBuildAsReference),
result, defaultEncoding, true);
final boolean usePreviousBuildAsReference, final boolean useStableBuildAsReference,
final Class<? extends ResultAction<DryResult>> actionType) {
this(build, new BuildHistory(build, actionType, usePreviousBuildAsReference, useStableBuildAsReference), result,
defaultEncoding, true);
}

@Deprecated
DryResult(final AbstractBuild<?, ?> build, final BuildHistory history,
final ParserResult result, final String defaultEncoding, final boolean canSerialize) {
DryResult(final AbstractBuild<?, ?> build, final BuildHistory history, final ParserResult result,
final String defaultEncoding, final boolean canSerialize) {
this((Run<?, ?>) build, history, result, defaultEncoding, canSerialize);
}

DryResult(final Run<?, ?> build, final BuildHistory history,
final ParserResult result, final String defaultEncoding, final boolean canSerialize) {
DryResult(final Run<?, ?> build, final BuildHistory history, final ParserResult result,
final String defaultEncoding, final boolean canSerialize) {
super(build, history, result, defaultEncoding);

if (canSerialize) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/dry/DryResultAction.java
Expand Up @@ -31,7 +31,8 @@ public class DryResultAction extends AbstractResultAction<DryResult> {
* @deprecated see {@link #DryResultAction(Run, HealthDescriptor, DryResult)}
*/
@Deprecated
public DryResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor, final DryResult result) {
public DryResultAction(final AbstractBuild<?, ?> owner, final HealthDescriptor healthDescriptor,
final DryResult result) {
this((Run<?, ?>) owner, healthDescriptor, result);
}

Expand Down
18 changes: 9 additions & 9 deletions src/test/java/hudson/plugins/dry/DryWorkflowTest.java
Expand Up @@ -23,27 +23,27 @@ 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.xml"));
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " step([$class: 'DryPublisher', highThreshold: 50, normalThreshold: 25])\n"
+ "}\n", true)
);
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
DryResultAction result = job.getLastBuild().getAction(DryResultAction.class);
assertEquals(0, result.getResult().getAnnotations().size());
assertEquals(2, result.getResult().getAnnotations().size());
}

/**
* Run a workflow job using {@link DryPublisher} with a failing threshold of 0, so the given example file
* "/hudson/plugins/dry/parser/cpd/cpd.xml" will make the build to fail.
* "/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml" will make the build to fail.
*/
@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/one-cpd.xml"));
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " step([$class: 'DryPublisher', pattern: '**/cpd.xml', highThreshold: 50, normalThreshold:" +
Expand All @@ -52,28 +52,28 @@ public void dryPublisherWorkflowStepSetLimits() throws Exception {
);
jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get());
DryResultAction result = job.getLastBuild().getAction(DryResultAction.class);
assertEquals(0, result.getResult().getAnnotations().size());
assertEquals(2, result.getResult().getAnnotations().size());
}

/**
* Run a workflow job using {@link DryPublisher} with a unstable threshold of 0, so the given example file
* "/hudson/plugins/dry/parser/cpd/cpd.xml" will make the build to fail.
* "/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml" will make the build to fail.
*/
@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.xml"));
report.copyFrom(getClass().getResourceAsStream("./parser/cpd/cpd-2warnings.xml"));
job.setDefinition(new CpsFlowDefinition(""
+ "node {\n"
+ " step([$class: 'DryPublisher', pattern: '**/lint-results.xml', highThreshold: 50, " +
+ " step([$class: 'DryPublisher', pattern: '**/cpd.xml', highThreshold: 50, " +
"normalThreshold: 25, unstableTotalAll: '0', usePreviousBuildAsReference: false])\n"
+ "}\n")
);
jenkinsRule.assertBuildStatus(Result.UNSTABLE, job.scheduleBuild2(0).get());
DryResultAction result = job.getLastBuild().getAction(DryResultAction.class);
assertEquals(0, result.getResult().getAnnotations().size());
assertEquals(2, result.getResult().getAnnotations().size());
}

}
18 changes: 18 additions & 0 deletions src/test/resources/hudson/plugins/dry/parser/cpd/cpd-2warnings.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd>
<duplication lines="9" tokens="65">
<file line="36"
path="/Users/recena/Development/projects/maven-helloworld/src/main/java/com/cloudbees/manticore/App.java"/>
<file line="46"
path="/Users/recena/Development/projects/maven-helloworld/src/main/java/com/cloudbees/manticore/App.java"/>
<codefragment><![CDATA[ private void quickSort(int arr[], int left, int right) {
int index = partition(arr, left, right);
if (left < index - 1) {
this.quickSort(arr, left, index - 1);
}
if (index < right) {
this.quickSort(arr, index, right);
}
}]]></codefragment>
</duplication>
</pmd-cpd>

0 comments on commit b3a3fc1

Please sign in to comment.