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

1 package hudson.diagnosis;
2
3 import org.jvnet.hudson.test.HudsonTestCase;
4 import org.xml.sax.SAXException;
5 import com.gargoylesoftware.htmlunit.html.HtmlPage;
6 import com.gargoylesoftware.htmlunit.html.HtmlForm;
7 import com.gargoylesoftware.htmlunit.ElementNotFoundException;
8 import hudson.model.AdministrativeMonitor;
9 import hudson.model.ListView;
10
11 import java.net.URL;
12 import java.io.IOException;
13
14 /**
15 * @author Kohsuke Kawaguchi
16 */
17 public class TooManyJobsButNoViewTest extends HudsonTestCase {
18 private TooManyJobsButNoView mon;
19
20 @Override
21 protected void setUp() throws Exception {
22 super.setUp();
23 mon = AdministrativeMonitor.all().get(TooManyJobsButNoView.class);
24 }
25
26 /**
27 * Shouldn't be active at the beginning
28 */
29 public void testInitialState() throws Exception {
30 verifyNoForm();
31 }
32
33 private void verifyNoForm() throws IOException, SAXException {
34 HtmlPage p = new WebClient().goTo("manage");
35 try {
36 p.getFormByName(mon.id);
37 fail();
38 } catch (ElementNotFoundException e) {
39 // shouldn't find it
40 }
41 }
42
43 /**
44 * Once we have enough jobs, it should kick in
45 */
46 public void testActivated() throws Exception {
47 for( int i=0; i<=TooManyJobsButNoView.THRESHOLD; i++ )
48 createFreeStyleProject();
49
50 HtmlPage p = new WebClient().goTo("manage");
51 HtmlForm f = p.getFormByName(mon.id);
52 assertNotNull(f);
53
54 // this should take us to the new view page
55 URL url = submit(f,"yes").getWebResponse().getUrl();
56 assertTrue(url.toExternalForm(),url.toExternalForm().endsWith("/newView"));
57
58 // since we didn't create a view, if we go back, we should see the warning again
59 p = new WebClient().goTo("manage");
60 assertNotNull(p.getFormByName(mon.id));
61
62 // once we create a view, the message should disappear
63 jenkins.addView(new ListView("test"));
64
65 verifyNoForm();
66 }
67 }
68