Skip to content

Commit

Permalink
Merge pull request #40 from amuniz/JENKINS-30390
Browse files Browse the repository at this point in the history
[JENKINS-30390] Added test case using Analysis Collector with workflow.
  • Loading branch information
uhafner committed Oct 2, 2015
2 parents 45c104f + c0aeb6d commit b27c150
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -165,6 +165,10 @@ public ShellBuildStep addShellStep(String shell) {
* base64 and put it as a heredoc in the shell script.
*/
public void copyResource(Resource resource, String fileName) {
addShellStep(copyResourceShell(resource, fileName));
}

protected String copyResourceShell(Resource resource, String fileName) {
try (InputStream in = resource.asInputStream()) {
ByteArrayOutputStream out = new ByteArrayOutputStream();

Expand All @@ -173,8 +177,8 @@ public void copyResource(Resource resource, String fileName) {
}

// fileName can include path portion like foo/bar/zot
addShellStep(String.format("(mkdir -p %1$s || true) && rm -r %1$s && base64 --decode << ENDOFFILE | gunzip > %1$s \n%2$s\nENDOFFILE",
fileName, new String(Base64.encodeBase64Chunked(out.toByteArray()))));
return String.format("(mkdir -p %1$s || true) && rm -r %1$s && base64 --decode << ENDOFFILE | gunzip > %1$s \n%2$s\nENDOFFILE",
fileName, new String(Base64.encodeBase64Chunked(out.toByteArray())));
} catch (IOException e) {
throw new AssertionError(e);
}
Expand Down
Expand Up @@ -26,6 +26,7 @@

import com.google.inject.Injector;
import java.net.URL;
import org.jenkinsci.test.acceptance.junit.Resource;

@Describable("org.jenkinsci.plugins.workflow.job.WorkflowJob")
public class WorkflowJob extends Job {
Expand All @@ -37,4 +38,9 @@ public WorkflowJob(Injector injector, URL url, String name) {
public final Control script = control("/definition/script");
public final Control sandbox = control("/definition/sandbox");

public String copyResourceStep(String filePath) {
final Resource res = resource(filePath);
return String.format("sh '''%s'''%n", copyResourceShell(res, res.getName()));
}

}
28 changes: 27 additions & 1 deletion src/test/java/plugins/AnalysisCollectorPluginTest.java
Expand Up @@ -20,6 +20,7 @@
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.ListView;
import org.jenkinsci.test.acceptance.po.WorkflowJob;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.openqa.selenium.WebElement;
Expand All @@ -29,7 +30,6 @@
import static org.jenkinsci.test.acceptance.Matchers.*;
import static org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisPlugin.*;
import static org.jenkinsci.test.acceptance.plugins.dashboard_view.DashboardView.*;
import static org.jenkinsci.test.acceptance.po.PageObject.createRandomName;

/**
* Acceptance tests for the Static Code Analysis Collector (analysis-collector) plug-in.
Expand Down Expand Up @@ -329,6 +329,32 @@ public void should_aggregate_warnings_in_dashboard_portlet() {
assertThat(dashboard, not(hasWarningsFor(job, TASKS, TASKS_ALL)));
}

@Test
@WithPlugins("workflow-aggregator")
public void should_compute_annotations_on_workflow() {
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.script.set(
"node {\n" +
job.copyResourceStep(ANALYSIS_COLLECTOR_PLUGIN_RESOURCES + "/checkstyle-result.xml") +
job.copyResourceStep(ANALYSIS_COLLECTOR_PLUGIN_RESOURCES +"/findbugs.xml") +
" step([$class: 'FindBugsPublisher', pattern: '**/findbugs.xml'])\n" +
" step([$class: 'CheckStylePublisher'])\n" +
" step([$class: 'AnalysisPublisher'])\n" +
"}");
job.sandbox.check();
job.save();
final Build build = job.startBuild();
build.shouldSucceed();

assertThat(build, hasAction("Static Analysis Warnings"));

AnalysisCollectorAction action = new AnalysisCollectorAction(build);
action.open();

assertThat(action.getNumberOfWarnings(), is(FINDBUGS_ALL + CHECKSTYLE_ALL));
assertThat(action.getNumberOfNewWarnings(), is(FINDBUGS_ALL + CHECKSTYLE_ALL));
}

private AnalysisCollectorAction deselectPluginAndBuild(AnalysisPlugin plugin, Job job) {
job.configure();
AnalysisCollectorSettings publisher = job.getPublisher(AnalysisCollectorSettings.class);
Expand Down

0 comments on commit b27c150

Please sign in to comment.