Skip to content

Commit

Permalink
[FIXED JENKINS-25898] Completed tests based on the tutorial.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Dec 10, 2014
1 parent aceb0f3 commit 4e24819
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions src/test/java/plugins/WorkflowPluginTest.java
Expand Up @@ -24,14 +24,30 @@

package plugins;

import java.util.concurrent.Callable;
import javax.inject.Inject;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.jenkinsci.test.acceptance.Matchers.hasContent;
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.junit.Native;
import org.jenkinsci.test.acceptance.junit.WithPlugins;
import org.jenkinsci.test.acceptance.plugins.maven.MavenInstallation;
import org.jenkinsci.test.acceptance.po.Artifact;
import org.jenkinsci.test.acceptance.po.Build;
import org.jenkinsci.test.acceptance.po.DumbSlave;
import org.jenkinsci.test.acceptance.po.WorkflowJob;
import org.jenkinsci.test.acceptance.slave.SlaveController;
import static org.junit.Assert.*;
import org.junit.Test;

/**
* Roughly follows <a href="https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md">the tutorial</a>.
*/
@WithPlugins("workflow-aggregator@1.1")
public class WorkflowPluginTest extends AbstractJUnitTest {

@Inject private SlaveController slaveController;

@Test public void helloWorld() throws Exception {
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.script.set("echo 'hello from Workflow'");
Expand All @@ -40,4 +56,90 @@ public class WorkflowPluginTest extends AbstractJUnitTest {
job.startBuild().shouldSucceed().shouldContainsConsoleOutput("hello from Workflow");
}

@WithPlugins({"junit@1.3", "git@2.3"})
@Test public void linearFlow() throws Exception {
MavenInstallation.installMaven(jenkins, "M3", "3.1.0");
final DumbSlave slave = (DumbSlave) slaveController.install(jenkins).get();
slave.configure(new Callable<Void>() {
@Override public Void call() throws Exception {
slave.labels.set("remote");
return null;
}
});
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.script.set(
"node('remote') {\n" +
" git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" +
" def v = version()\n" +
" if (v) {\n" +
" echo \"Building version ${v}\"\n" +
" }\n" +
" def mvnHome = tool 'M3'\n" +
" sh \"${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify\"\n" +
" input 'Ready to go?'\n" +
" step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])\n" +
" step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])\n" +
"}\n" +
"def version() {\n" +
" def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'\n" +
" matcher ? matcher[0][1] : null\n" +
"}");
job.sandbox.check();
job.save();
final Build build = job.startBuild();
waitForCond(new Callable<Boolean>() {
@Override public Boolean call() throws Exception {
return build.getConsole().contains("Ready to go?");
}
});
build.shouldContainsConsoleOutput("Building version 1.0-SNAPSHOT");
jenkins.restart();
visit(build.getConsoleUrl());
clickLink("Proceed");
assertTrue(build.isSuccess() || build.isUnstable()); // tests in this project are currently designed to fail at random, so either is OK
new Artifact(build, "target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar").assertThatExists(true);
build.open();
clickLink("Test Result");
assertThat(driver, hasContent("All Tests"));
}

@WithPlugins({"parallel-test-executor@1.6", "junit@1.3", "git@2.3"})
@Native("mvn")
@Test public void parallelTests() throws Exception {
for (int i = 0; i < 3; i++) {
slaveController.install(jenkins);
}
WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
job.script.set(
"node('master') {\n" +
" git url: 'https://github.com/jenkinsci/parallel-test-executor-plugin-sample.git'\n" +
" archive 'pom.xml, src/'\n" +
"}\n" +
"def splits = splitTests([$class: 'CountDrivenParallelism', size: 3])\n" +
"def branches = [:]\n" +
"for (int i = 0; i < splits.size(); i++) {\n" +
" def exclusions = splits.get(i);\n" +
" branches[\"split${i}\"] = {\n" +
" node('!master') {\n" +
" sh 'rm -rf *'\n" +
" unarchive mapping: ['pom.xml' : '.', 'src/' : '.']\n" +
" writeFile file: 'exclusions.txt', text: exclusions.join(\"\\n\")\n" +
// Do not bother with ${tool 'M3'}; would take too long to unpack Maven on all slaves.
// TODO would be useful for ToolInstallation to support the URL installer, hosting the tool ZIP ourselves somewhere cached.
" sh 'mvn -B -Dmaven.test.failure.ignore test'\n" +
" step([$class: 'JUnitResultArchiver', testResults: 'target/surefire-reports/*.xml'])\n" +
" }\n" +
" }\n" +
"}\n" +
"parallel branches");
// TODO when staticMethod org.codehaus.groovy.runtime.ScriptBytecodeAdapter compareLessThan java.lang.Object java.lang.Object is preapproved: job.sandbox.check();
job.save();
Build build = job.startBuild();
assertTrue(build.isSuccess() || build.isUnstable()); // again this project is designed to have occasional test failures
build.shouldContainsConsoleOutput("No record available"); // first run
build = job.startBuild();
assertTrue(build.isSuccess() || build.isUnstable());
build.shouldContainsConsoleOutput("divided into 3 sets");
}

}

0 comments on commit 4e24819

Please sign in to comment.