mirror of https://github.com/jenkinsci/jenkins.git
				
				
				
			defined recipe annotations to do declarative test case set up
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11508 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
		
							parent
							
								
									1a2168f614
								
							
						
					
					
						commit
						dc7f18fb34
					
				|  | @ -105,12 +105,12 @@ public abstract class HudsonTestCase extends TestCase { | ||||||
|         withNewHome(); |         withNewHome(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected HudsonTestCase withNewHome() { |     public HudsonTestCase withNewHome() { | ||||||
|         homeLoader = HudsonHomeLoader.NEW; |         homeLoader = HudsonHomeLoader.NEW; | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected HudsonTestCase withExistingHome(File source) { |     public HudsonTestCase withExistingHome(File source) { | ||||||
|         homeLoader = new CopyExisting(source); |         homeLoader = new CopyExisting(source); | ||||||
|         return this; |         return this; | ||||||
|     } |     } | ||||||
|  | @ -120,7 +120,7 @@ public abstract class HudsonTestCase extends TestCase { | ||||||
|      * See https://svn.dev.java.net/svn/hudson/trunk/hudson/main/test/src/main/preset-data/ |      * See https://svn.dev.java.net/svn/hudson/trunk/hudson/main/test/src/main/preset-data/ | ||||||
|      * for available datasets and what they mean. |      * for available datasets and what they mean. | ||||||
|      */ |      */ | ||||||
|     protected HudsonTestCase withPresetData(String name) { |     public HudsonTestCase withPresetData(String name) { | ||||||
|         name = "/" + name + ".zip"; |         name = "/" + name + ".zip"; | ||||||
|         URL res = getClass().getResource(name); |         URL res = getClass().getResource(name); | ||||||
|         if(res==null)   throw new IllegalArgumentException("No such data set found: "+name); |         if(res==null)   throw new IllegalArgumentException("No such data set found: "+name); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,39 @@ | ||||||
|  | package org.jvnet.hudson.test.recipes; | ||||||
|  | 
 | ||||||
|  | import org.jvnet.hudson.test.HudsonTestCase; | ||||||
|  | 
 | ||||||
|  | import java.lang.annotation.Documented; | ||||||
|  | import static java.lang.annotation.ElementType.METHOD; | ||||||
|  | import java.lang.annotation.Retention; | ||||||
|  | import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||||||
|  | import java.lang.annotation.Target; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Runs a test case with one of the preset HUDSON_HOME data set. | ||||||
|  |  * | ||||||
|  |  * @author Kohsuke Kawaguchi | ||||||
|  |  */ | ||||||
|  | @Documented | ||||||
|  | @Recipe(@PresetData.RunnerImpl.class) | ||||||
|  | @Target(METHOD) | ||||||
|  | @Retention(RUNTIME) | ||||||
|  | public @interface PresetData { | ||||||
|  |     /** | ||||||
|  |      * One of the preset data to choose from. | ||||||
|  |      */ | ||||||
|  |     DataSet value(); | ||||||
|  | 
 | ||||||
|  |     public enum DataSet { | ||||||
|  |         /** | ||||||
|  |          * Secured Hudson that has no anonymous read access. | ||||||
|  |          * Any logged in user can do anything. | ||||||
|  |          */ | ||||||
|  |         NO_ANONYMOUS_READACCESS | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class RunnerImpl extends Recipe.Runner<PresetData> { | ||||||
|  |         public void setup(HudsonTestCase testCase, PresetData recipe) { | ||||||
|  |             testCase.withPresetData(recipe.value().name().toLowerCase().replace('_','-')); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,48 @@ | ||||||
|  | package org.jvnet.hudson.test.recipes; | ||||||
|  | 
 | ||||||
|  | import org.jvnet.hudson.test.HudsonTestCase; | ||||||
|  | 
 | ||||||
|  | import java.lang.annotation.Documented; | ||||||
|  | import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||||||
|  | import java.lang.annotation.Retention; | ||||||
|  | import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||||||
|  | import java.lang.annotation.Target; | ||||||
|  | import java.lang.annotation.Annotation; | ||||||
|  | 
 | ||||||
|  | import junit.framework.TestCase; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Meta-annotation for recipe annotations, which controls | ||||||
|  |  * the test environment set up. | ||||||
|  |  * | ||||||
|  |  * @author Kohsuke Kawaguchi | ||||||
|  |  */ | ||||||
|  | @Retention(RUNTIME) | ||||||
|  | @Documented | ||||||
|  | @Target(ANNOTATION_TYPE) | ||||||
|  | public @interface Recipe { | ||||||
|  |     /** | ||||||
|  |      * Specifies the class that sets up the test environment. | ||||||
|  |      * | ||||||
|  |      * <p> | ||||||
|  |      * When a recipe annotation is placed on a test method,  | ||||||
|  |      */ | ||||||
|  |     Class<? extends Runner> value(); | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * The code that implements the recipe semantics. | ||||||
|  |      * | ||||||
|  |      * @param <T> | ||||||
|  |      *      The recipe annotation associated with this runner. | ||||||
|  |      */ | ||||||
|  |     public abstract class Runner<T extends Annotation> { | ||||||
|  |         /** | ||||||
|  |          * Called during {@link TestCase#setUp()} to prepare the test environment. | ||||||
|  |          */ | ||||||
|  |         public void setup(HudsonTestCase testCase, T recipe) {} | ||||||
|  |         /** | ||||||
|  |          * Called during {@link TestCase#tearDown()} to shut down the test environment. | ||||||
|  |          */ | ||||||
|  |         public void tearDown(HudsonTestCase testCase, T recipe) {} | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue