diff --git a/test/src/main/java/org/jvnet/hudson/test/recipes/WithPlugin.java b/test/src/main/java/org/jvnet/hudson/test/recipes/WithPlugin.java new file mode 100644 index 0000000000000000000000000000000000000000..06101868312436e12d2b6f6c7fcd2cce512d6f22 --- /dev/null +++ b/test/src/main/java/org/jvnet/hudson/test/recipes/WithPlugin.java @@ -0,0 +1,46 @@ +package org.jvnet.hudson.test.recipes; + +import org.jvnet.hudson.test.HudsonTestCase; +import org.apache.commons.io.FileUtils; + +import java.io.File; +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; +import java.net.URL; + +/** + * Installs the specified plugin before launching Hudson. + * + * @author Kohsuke Kawaguchi + */ +@Documented +@Recipe(WithPlugin.RunnerImpl.class) +@Target(METHOD) +@Retention(RUNTIME) +public @interface WithPlugin { + /** + * Name of the plugin. + * + * For now, this has to be one of the plugins statically available in resources + * "/plugins/NAME". TODO: support retrieval through Maven repository. + */ + String value(); + + public class RunnerImpl extends Recipe.Runner { + private WithPlugin a; + + @Override + public void setup(HudsonTestCase testCase, WithPlugin recipe) throws Exception { + a = recipe; + } + + @Override + public void decorateHome(HudsonTestCase testCase, File home) throws Exception { + URL res = getClass().getClassLoader().getResource("plugins/" + a.value()); + FileUtils.copyURLToFile(res,new File(home,"plugins/"+a.value())); + } + } +} diff --git a/test/src/test/java/hudson/PluginManagerTest.java b/test/src/test/java/hudson/PluginManagerTest.java index 0b8c89506b7e5434b4a4265a5a7d4ca1473734c0..6bc8079c9a343cc193a86cdffd943cdfa57eae36 100644 --- a/test/src/test/java/hudson/PluginManagerTest.java +++ b/test/src/test/java/hudson/PluginManagerTest.java @@ -1,6 +1,7 @@ package hudson; import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.recipes.WithPlugin; import org.apache.commons.io.FileUtils; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlForm; @@ -26,4 +27,9 @@ public class PluginManagerTest extends HudsonTestCase { assertTrue( new File(hudson.getRootDir(),"plugins/tasks.hpi").exists() ); } + + @WithPlugin("tasks.hpi") + public void testWithRecipe() throws Exception { + assertNotNull(hudson.getPlugin("tasks")); + } }