File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\main\java\org\jvnet\hudson\test\GroovyHudsonTestCase.java.html

1 package org.jvnet.hudson.test;
2
3 import org.kohsuke.stapler.StaplerRequest;
4 import org.kohsuke.stapler.StaplerResponse;
5 import groovy.lang.Closure;
6 import hudson.model.AbstractBuild;
7 import hudson.model.BuildListener;
8 import hudson.tasks.Builder;
9 import hudson.Launcher;
10
11 import java.util.concurrent.Callable;
12 import java.io.IOException;
13
14 /**
15 * {@link HudsonTestCase} with more convenience methods for Groovy.
16 *
17 * @author Kohsuke Kawaguchi
18 */
19 public abstract class GroovyHudsonTestCase extends HudsonTestCase {
20 /**
21 * Executes the given closure on the server, in the context of an HTTP request.
22 * This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}.
23 *
24 * <p>
25 * The closure will get the request and response as parameters.
26 */
27 public Object executeOnServer(final Closure c) throws Exception {
28 return executeOnServer(new Callable<Object>() {
29 public Object call() throws Exception {
30 return c.call();
31 }
32 });
33 }
34
35 /**
36 * Wraps a closure as a {@link Builder}.
37 */
38 public Builder builder(final Closure c) {
39 return new TestBuilder() {
40 public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
41 Object r = c.call(new Object[]{build,launcher,listener});
42 if (r instanceof Boolean) return (Boolean)r;
43 return true;
44 }
45 };
46 }
47 }
48