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

1 package hudson;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.net.URL;
6
7 import javax.servlet.ServletContext;
8
9 import org.jvnet.hudson.test.HudsonTestCase;
10 import org.jvnet.hudson.test.recipes.WithPlugin;
11 import org.xml.sax.SAXException;
12
13 import com.gargoylesoftware.htmlunit.html.HtmlForm;
14 import com.gargoylesoftware.htmlunit.html.HtmlPage;
15 import org.apache.commons.io.FileUtils;
16
17 public class PluginManagerTest2 extends HudsonTestCase {
18 @Override
19 protected void setUp() throws Exception {
20 setPluginManager(null); // use a fresh instance
21 super.setUp();
22 }
23
24 private ServletContext servletContext;
25
26 // need to keep the ServletContext to use in the actual test
27 protected ServletContext createWebServer() throws Exception {
28 servletContext=super.createWebServer();
29 return servletContext;
30 }
31
32 @WithPlugin("tasks.jpi")
33 public void testPinned() throws Exception {
34 PluginWrapper tasks = jenkins.getPluginManager().getPlugin("tasks");
35 assertFalse("tasks shouldn't be bundled",tasks.isBundled());
36 assertFalse("tasks shouldn't be pinned before update",tasks.isPinned());
37 uploadPlugin("tasks.jpi", false);
38 assertFalse("tasks shouldn't be pinned after update",tasks.isPinned());
39
40 PluginWrapper cvs = jenkins.getPluginManager().getPlugin("cvs");
41 assertTrue("cvs should be bundled",cvs.isBundled());
42 assertFalse("cvs shouldn't be pinned before update",cvs.isPinned());
43 uploadPlugin("cvs.hpi", true);
44 assertTrue("cvs should be pinned after update",cvs.isPinned());
45 }
46
47 private void uploadPlugin(String pluginName, boolean useServerRoot) throws IOException, SAXException, Exception {
48 HtmlPage page = new WebClient().goTo("pluginManager/advanced");
49 HtmlForm f = page.getFormByName("uploadPlugin");
50 File plugin;
51 if(useServerRoot) {
52 String pluginsPath=servletContext.getRealPath("WEB-INF/plugins");
53 plugin = new File(pluginsPath+"/"+pluginName);
54 } else {
55 File dir = env.temporaryDirectoryAllocator.allocate();
56 plugin = new File(dir, pluginName);
57 URL resource = getClass().getClassLoader().getResource("plugins/"+pluginName);
58 FileUtils.copyURLToFile(resource,plugin);
59 }
60 f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath());
61 submit(f);
62 }
63
64 }
65