Skip to content

Commit

Permalink
[JENKINS-27208] Added a test specific for workflow compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Recena committed Sep 30, 2015
1 parent 9f8e6b8 commit 95a68a0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/hudson/plugins/logparser/LogParserPublisher.java
Expand Up @@ -2,6 +2,7 @@

import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Result;
Expand Down Expand Up @@ -33,9 +34,9 @@ public class LogParserPublisher extends Recorder implements SimpleBuildStep, Ser
public boolean unstableOnWarning;
public boolean failBuildOnError;
public boolean showGraphs;
public String parsingRulesPath;
public String parsingRulesPath = null;
public boolean useProjectRule;
public String projectRulePath;
public String projectRulePath = null;

/**
* Create new LogParserPublisher.
Expand Down Expand Up @@ -68,14 +69,14 @@ private LogParserPublisher(final boolean unstableOnWarning,
}

@DataBoundConstructor
public LogParserPublisher(final boolean useProjectRule, final String parsingRulesPath, final String projectRulePath) {
public LogParserPublisher(boolean useProjectRule, String projectRulePath, String parsingRulesPath) {
super();
if (useProjectRule) {
this.projectRulePath = projectRulePath;
this.projectRulePath = Util.fixEmpty(projectRulePath);
this.parsingRulesPath = null;
} else {
this.parsingRulesPath = Util.fixEmpty(parsingRulesPath);
this.projectRulePath = null;
this.parsingRulesPath = parsingRulesPath;
}
this.useProjectRule = useProjectRule;
}
Expand Down
@@ -0,0 +1,52 @@
package org.jenkinsci.plugins.logparser;

import hudson.FilePath;
import hudson.plugins.logparser.LogParserAction;
import hudson.plugins.logparser.LogParserPublisher;
import hudson.tasks.Maven;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.*;
import org.jvnet.hudson.test.JenkinsRule;

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.
*/
public class LogParserWorkflowTest {

@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 LogParserPublisher} and check for success.
*/
@Test
public void logParserPublisherWorkflowStep() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "logParserPublisherWorkflowStep");
FilePath workspace = jenkinsRule.jenkins.getWorkspaceFor(job);
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: 'LogParserPublisher', projectRulePath: 'logparser-rules.txt', useProjectRule: true])\n"
+ "}\n", true)
);
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
LogParserAction result = job.getLastBuild().getAction(LogParserAction.class);
assertEquals(0, result.getResult().getTotalErrors());
assertEquals(2, result.getResult().getTotalWarnings());
assertEquals(0, result.getResult().getTotalInfos());
}

}
Binary file not shown.

0 comments on commit 95a68a0

Please sign in to comment.