/** * Makes an HTTP request, process it with the given request handler, and returns the response. */ public HtmlPage eval(final Runnable requestHandler) throws IOException, SAXException { ClosureExecuterAction cea = jenkins.getExtensionList(RootAction.class).get(ClosureExecuterAction.class); UUID id = UUID.randomUUID(); cea.add(id,requestHandler); return goTo("closures/?uuid="+id); }
@Issue({"JENKINS-26126", "JENKINS-37215"}) @Test public void doDslRef() throws Exception { JenkinsRule.WebClient wc = r.createWebClient(); String html = wc.goTo(Snippetizer.ACTION_URL + "/html").getWebResponse().getContentAsString(); assertThat("text from LoadStep/help-path.html is included", html, containsString("the Groovy file to load")); assertThat("GitSCM.submoduleCfg is mentioned as an attribute of a value of GenericSCMStep.scm", html, containsString("submoduleCfg")); assertThat("CleanBeforeCheckout is mentioned as an option", html, containsString("CleanBeforeCheckout")); assertThat("content is written to the end", html, containsString("</body></html>")); assertThat("symbols are noted for heterogeneous lists", html, containsString("<code>booleanParam</code>")); assertThat("symbols are noted for homogeneous lists", html, containsString("<code>configFile</code>")); }
public Object call() throws Exception { Descriptor d = jenkins.getDescriptor(type); WebClient wc = createWebClient(); for (String property : listProperties(properties)) { String url = d.getHelpFile(property); assertThat("Help file for the property " + property + " is missing on " + type, url, Matchers.notNullValue()); wc.goTo(url); // make sure it successfully loads } return null; } });
@Email("http://jenkins.361315.n4.nabble.com/Change-remote-API-visibility-for-CaseResult-getStdout-getStderr-td395102.html") @Test public void testRemoteApiNameOnly() throws Exception { FreeStyleBuild b = configureTestBuild("test-remoteapi"); XmlPage page = (XmlPage)rule.createWebClient().goTo("job/test-remoteapi/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/api/xml?depth=-10","application/xml"); int found = 0; found = page.getByXPath(composeXPath(MAX_VISIBILITY_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); found = page.getByXPath(composeXPath(REDUCED_VISIBILITY_FIELDS)).size(); assertTrue("Should have found 0 elements, but found " + found, found == 0); found = page.getByXPath(composeXPath(OTHER_FIELDS)).size(); assertTrue("Should have found 0 elements, but found " + found, found == 0); }
@Email("http://jenkins.361315.n4.nabble.com/Change-remote-API-visibility-for-CaseResult-getStdout-getStderr-td395102.html") @Test public void testRemoteApiNoDetails() throws Exception { FreeStyleBuild b = configureTestBuild("test-remoteapi"); XmlPage page = (XmlPage)rule.createWebClient().goTo("job/test-remoteapi/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/api/xml?depth=-1","application/xml"); int found = 0; found = page.getByXPath(composeXPath(MAX_VISIBILITY_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); found = page.getByXPath(composeXPath(REDUCED_VISIBILITY_FIELDS)).size(); assertTrue("Should have found 0 elements, but found " + found, found == 0); found = page.getByXPath(composeXPath(OTHER_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); }
public User configRoundtrip(User u) throws Exception { submit(createWebClient().goTo(u.getUrl()+"/configure").getFormByName("config")); return u; }
@Email("http://jenkins.361315.n4.nabble.com/Change-remote-API-visibility-for-CaseResult-getStdout-getStderr-td395102.html") @Test public void testRemoteApiDefaultVisibility() throws Exception { FreeStyleBuild b = configureTestBuild("test-remoteapi"); XmlPage page = (XmlPage)rule.createWebClient().goTo("job/test-remoteapi/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/api/xml","application/xml"); int found = 0; found = page.getByXPath(composeXPath(MAX_VISIBILITY_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); found = page.getByXPath(composeXPath(REDUCED_VISIBILITY_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); found = page.getByXPath(composeXPath(OTHER_FIELDS)).size(); assertTrue("Should have found an element, but found " + found, found > 0); }
/** * Hits the Hudson system configuration and submits without any modification. */ public void configRoundtrip() throws Exception { submit(createWebClient().goTo("configure").getFormByName("config")); }
private HtmlAnchor findRenameAnchor(AbstractItem item) throws Exception { JenkinsRule.WebClient w = r.createWebClient(); HtmlPage page = w.goTo(item.getUrl()); String relativeUrl = r.contextPath + "/" + item.getUrl() + item.getAction(RenameAction.class).getUrlName(); return page.getAnchorByHref(relativeUrl); }
/** * Makes sure the summary page remains text/plain (see commit 7089a81 in JENKINS-1544) but * the index page must be in text/html. */ @Issue("JENKINS-21261") @Test public void testContentType() throws Exception { configureTestBuild("foo"); WebClient wc = rule.createWebClient(); wc.goTo("job/foo/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/","text/html"); wc.goTo("job/foo/1/testReport/org.twia.vendor/VendorManagerTest/testCreateAdjustingFirm/summary","text/plain"); }
private void checkUrl(JenkinsRule.WebClient wc, String url) throws Exception { try { wc.goTo(url); fail(); } catch (FailingHttpStatusCodeException e) { WebResponse response = e.getResponse(); assertEquals(404, response.getStatusCode()); String content = response.getContentAsString(); assertFalse(content.contains("Search for")); } } }
public <C extends ComputerConnector> C configRoundtrip(C before) throws Exception { computerConnectorTester.connector = before; submit(createWebClient().goTo("self/computerConnectorTester/configure").getFormByName("config")); return (C)computerConnectorTester.connector; }
private void testSetDescription(String url, TestObject object) throws Exception { object.doSubmitDescription("description"); // test the roundtrip final WebClient wc = j.createWebClient(); HtmlPage page = wc.goTo(url); page.getAnchorByHref("editDescription").click(); wc.waitForBackgroundJavaScript(10000L); HtmlForm form = findForm(page, "submitDescription"); j.submit(form); assertEquals("description", object.getDescription()); }
@Issue("JENKINS-26126") @Test public void doDsld() throws Exception { JenkinsRule.WebClient wc = r.createWebClient(); String dsld = wc.goTo(Snippetizer.ACTION_URL + "/dsld", "text/plain").getWebResponse().getContentAsString(); assertThat("Description is included as doc", dsld, containsString("Build a job")); assertThat("Timeout step appears", dsld, containsString("name: 'timeout'")); // Verify valid groovy sntax. GroovyShell shell = new GroovyShell(r.jenkins.getPluginManager().uberClassLoader); shell.parse(dsld); }
@Issue({"JENKINS-35395", "JENKINS-38114"}) @Test public void doGlobalsRef() throws Exception { JenkinsRule.WebClient wc = r.createWebClient(); String html = wc.goTo(Snippetizer.ACTION_URL + "/globals").getWebResponse().getContentAsString(); assertThat("text from RunWrapperBinder/help.jelly is included", html, containsString("may be used to refer to the currently running build")); assertThat("text from RunWrapperBinder/help.jelly includes text from RunWrapper/help.html", html, containsString("<dt><code>buildVariables</code></dt>")); assertThat("content is written to the end", html, containsString("</body></html>")); }
public void notifyCommit(FilePath repo) throws Exception { j.jenkins.getDescriptorByType(SCMTrigger.DescriptorImpl.class).synchronousPolling = true; System.out.println(j.createWebClient().goTo("mercurial/notifyCommit?url=" + repo.toURI().toString(), "text/plain").getWebResponse().getContentAsString()); j.waitUntilNoActivity(); }
public <N extends Node> N configRoundtrip(N node) throws Exception { submit(createWebClient().goTo("computer/" + node.getNodeName() + "/configure").getFormByName("config")); return (N)jenkins.getNode(node.getNodeName()); }
/** * Accesses a page inside {@link Run}. * * @param relative * Relative URL within the build URL, like "changes". Doesn't start with '/'. Can be empty. */ public HtmlPage getPage(Run r, String relative) throws IOException, SAXException { return goTo(r.getUrl()+relative); }
public HtmlPage search(String q) throws IOException, SAXException { HtmlPage top = goTo(""); HtmlForm search = top.getFormByName("search"); search.getInputByName("q").setValueAttribute(q); return (HtmlPage)HtmlFormUtil.submit(search, null); }
@Issue("JENKINS-26126") @Test public void doGdsl() throws Exception { JenkinsRule.WebClient wc = r.createWebClient(); String gdsl = wc.goTo(Snippetizer.ACTION_URL + "/gdsl", "text/plain").getWebResponse().getContentAsString(); assertThat("Description is included as doc", gdsl, containsString("Build a job")); assertThat("Timeout step appears", gdsl, containsString("name: 'timeout'")); // Verify valid groovy syntax. GroovyShell shell = new GroovyShell(r.jenkins.getPluginManager().uberClassLoader); shell.parse(gdsl); }