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

1 package org.jvnet.hudson.main;
2
3 import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertFalse;
6 import static org.junit.Assert.assertNotNull;
7 import hudson.LocalPluginManager;
8
9 import java.io.File;
10 import java.io.IOException;
11 import java.net.URL;
12
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.jvnet.hudson.test.JenkinsRule;
16 import org.jvnet.hudson.test.JenkinsRule.WebClient;
17 import org.jvnet.hudson.test.recipes.LocalData;
18 import org.jvnet.hudson.test.recipes.PresetData;
19 import org.jvnet.hudson.test.recipes.PresetData.DataSet;
20 import org.jvnet.hudson.test.recipes.WithPlugin;
21 import org.jvnet.hudson.test.recipes.WithPluginManager;
22 import org.xml.sax.SAXException;
23
24 import com.gargoylesoftware.htmlunit.html.HtmlPage;
25
26 public class UseRecipesWithJenkinsRuleTest {
27
28 @Rule
29 public JenkinsRule rule = new JenkinsRule();
30
31 @Test
32 @LocalData
33 public void testGetItemFromLocalData() {
34 assertNotNull(rule.jenkins.getItem("testJob"));
35 }
36
37 @Test
38 @WithPlugin("tasks.jpi")
39 public void testWithPlugin() {
40 assertNotNull(rule.jenkins.getPlugin("tasks"));
41 }
42
43 @Test
44 @PresetData(DataSet.ANONYMOUS_READONLY)
45 public void testPresetData() throws Exception {
46 WebClient wc = rule.createWebClient();
47 wc.assertFails("loginError", SC_UNAUTHORIZED);
48 // but not once the user logs in.
49 verifyNotError(wc.login("alice"));
50 }
51
52 @Test
53 @WithPluginManager(MyPluginManager.class)
54 public void testWithPluginManager() {
55 assertEquals(MyPluginManager.class, rule.jenkins.pluginManager.getClass());
56 }
57
58 private void verifyNotError(WebClient wc) throws IOException, SAXException {
59 HtmlPage p = wc.goTo("loginError");
60 URL url = p.getWebResponse().getUrl();
61 System.out.println(url);
62 assertFalse(url.toExternalForm().contains("login"));
63 }
64
65 public static class MyPluginManager extends LocalPluginManager {
66 public MyPluginManager(File rootDir) {
67 super(rootDir);
68 }
69 }
70 }
71