mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-20 07:22:32 +00:00
implemented recipe execution
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11509 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
dc7f18fb34
commit
1ef6895137
3 files changed
+40
-5
No files matched your search
@@ -6,6 +6,8 @@ import hudson.model.Hudson;
|
||||
import hudson.model.Item;
|
||||
import junit.framework.TestCase;
|
||||
import org.jvnet.hudson.test.HudsonHomeLoader.CopyExisting;
|
||||
import org.jvnet.hudson.test.recipes.Recipe;
|
||||
import org.jvnet.hudson.test.recipes.Recipe.Runner;
|
||||
import org.kohsuke.stapler.Stapler;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.bio.SocketConnector;
|
||||
@@ -16,7 +18,11 @@ import org.xml.sax.SAXException;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Base class for all Hudson test cases.
|
||||
@@ -27,7 +33,7 @@ public abstract class HudsonTestCase extends TestCase {
|
||||
protected Hudson hudson;
|
||||
|
||||
protected final TestEnvironment env = new TestEnvironment();
|
||||
protected HudsonHomeLoader homeLoader;
|
||||
protected HudsonHomeLoader homeLoader = HudsonHomeLoader.NEW;
|
||||
/**
|
||||
* TCP/IP port that the server is listening on.
|
||||
*/
|
||||
@@ -39,6 +45,11 @@ public abstract class HudsonTestCase extends TestCase {
|
||||
*/
|
||||
protected String contextPath = "/";
|
||||
|
||||
/**
|
||||
* {@link Runnable}s to be invoked at {@link #tearDown()}.
|
||||
*/
|
||||
protected List<LenientRunnable> tearDowns = new ArrayList<LenientRunnable>();
|
||||
|
||||
protected HudsonTestCase(String name) {
|
||||
super(name);
|
||||
}
|
||||
@@ -51,6 +62,8 @@ public abstract class HudsonTestCase extends TestCase {
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
for (LenientRunnable r : tearDowns)
|
||||
r.run();
|
||||
hudson.cleanUp();
|
||||
env.dispose();
|
||||
server.stop();
|
||||
@@ -101,8 +114,20 @@ public abstract class HudsonTestCase extends TestCase {
|
||||
* <p>
|
||||
* From here, call a series of {@code withXXX} methods.
|
||||
*/
|
||||
protected void recipe() {
|
||||
withNewHome();
|
||||
protected void recipe() throws Exception {
|
||||
// look for recipe meta-annotation
|
||||
Method runMethod= getClass().getMethod(getName());
|
||||
for( final Annotation a : runMethod.getAnnotations() ) {
|
||||
Recipe r = a.getClass().getAnnotation(Recipe.class);
|
||||
if(r==null) continue;
|
||||
final Runner runner = r.value().newInstance();
|
||||
tearDowns.add(new LenientRunnable() {
|
||||
public void run() throws Exception {
|
||||
runner.tearDown(HudsonTestCase.this,a);
|
||||
}
|
||||
});
|
||||
runner.setup(this,a);
|
||||
}
|
||||
}
|
||||
|
||||
public HudsonTestCase withNewHome() {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.jvnet.hudson.test;
|
||||
|
||||
/**
|
||||
* Like {@link Runnable} but can throw any exception.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface LenientRunnable {
|
||||
public void run() throws Exception;
|
||||
}
|
||||
@@ -39,10 +39,10 @@ public @interface Recipe {
|
||||
/**
|
||||
* Called during {@link TestCase#setUp()} to prepare the test environment.
|
||||
*/
|
||||
public void setup(HudsonTestCase testCase, T recipe) {}
|
||||
public void setup(HudsonTestCase testCase, T recipe) throws Exception {}
|
||||
/**
|
||||
* Called during {@link TestCase#tearDown()} to shut down the test environment.
|
||||
*/
|
||||
public void tearDown(HudsonTestCase testCase, T recipe) {}
|
||||
public void tearDown(HudsonTestCase testCase, T recipe) throws Exception {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user