/** * Loads a configuration page and submits it without any modifications, to * perform a round-trip configuration test. * <p> * See http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test#UnitTest-Configurationroundtriptesting */ public <P extends Item> P configRoundtrip(P job) throws Exception { submit(createWebClient().getPage(job, "configure").getFormByName("config")); return job; }
/** * Hits the Hudson system configuration and submits without any modification. */ public void configRoundtrip() throws Exception { submit(createWebClient().goTo("configure").getFormByName("config")); }
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; } });
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; }
/** * Loads the config.xml for the job via http. * I.e. http://jenkinshost/job/thejob/config.xml * * @param job the job * @return the xml page * @throws IOException if so * @throws SAXException if so */ XmlPage loadConfigXmlViaHttp(TopLevelItem job) throws IOException, SAXException { return j.createWebClient().goToXml(job.getUrl() + "config.xml"); }
private void copyViaHttp(Folder f, JenkinsRule.WebClient wc, String fromName, String toName) throws Exception { // Taken from https://github.com/jenkinsci/jenkins/blob/80aa2c8e4093df270193402c3933f3f1f16271da/test/src/test/java/hudson/jobs/CreateItemTest.java#L68 r.jenkins.setCrumbIssuer(null); URL apiURL = new URL( r.jenkins.getRootUrl().toString() + "/" + f.getUrl().toString() + "createItem?mode=copy&from=" + URLEncoder.encode(fromName, "UTF-8") + "&name=" + URLEncoder.encode(toName, "UTF-8")); WebRequest request = new WebRequest(apiURL, HttpMethod.POST); request.setEncodingType(null); assertEquals("Copy Job request has failed", 200, r.createWebClient() .getPage(request).getWebResponse().getStatusCode()); }
@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 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(); }
@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>")); }
@Test @Issue("SECURITY-724") public void shouldNotBeAbleToSearchUsingDynamic() throws Exception { String uuid = "12345678-1234-1234-1234-123456789012"; JenkinsRule.WebClient wc = j.createWebClient(); checkUrl(wc, "subversion/" + uuid + "/search/"); checkUrl(wc, "subversion/" + uuid + "/search/?q=a"); }
@Test @Issue("SECURITY-724") public void shouldNotBeAbleToSearch() throws Exception { JenkinsRule.WebClient wc = j.createWebClient(); checkUrl(wc, "subversion/search/"); checkUrl(wc, "subversion/search/?q=a"); }
@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); }
@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); }
@Test public void notAddChildren() throws Exception { JenkinsRule.WebClient client = r.createWebClient(); SampleComputedFolder s = r.jenkins.createProject(SampleComputedFolder.class, "s"); assertEquals(client.getPage(s).getByXPath("//a[contains(text(), \"New Item\")]").size(), 0); s.kids.add("A"); s.recompute(Result.SUCCESS); assertEquals(client.getPage(s).getByXPath("//a[contains(text(), \"New Item\")]").size(), 0); }
private JSONObject callStepsToJson(String jenkinsFileContent) throws IOException { JenkinsRule.WebClient wc = j.createWebClient(); WebRequest req = new WebRequest(new URL(wc.getContextPath() + ModelConverterAction.PIPELINE_CONVERTER_URL + "/stepsToJson"), HttpMethod.POST); assertNotNull(jenkinsFileContent); NameValuePair pair = new NameValuePair("jenkinsfile", jenkinsFileContent); req.setRequestParameters(Collections.singletonList(pair)); String rawResult = wc.getPage(req).getWebResponse().getContentAsString(); assertNotNull(rawResult); return JSONObject.fromObject(rawResult); } }
private JSONObject callStepToJenkinsFile(String jsonFileName) throws IOException { JenkinsRule.WebClient wc = j.createWebClient(); WebRequest req = new WebRequest(new URL(wc.getContextPath() + ModelConverterAction.PIPELINE_CONVERTER_URL + "/stepsToJenkinsfile"), HttpMethod.POST); String simpleJson = fileContentsFromResources(jsonFileName); assertNotNull(simpleJson); NameValuePair pair = new NameValuePair("json", simpleJson); req.setRequestParameters(Collections.singletonList(pair)); String rawResult = wc.getPage(req).getWebResponse().getContentAsString(); assertNotNull(rawResult); return JSONObject.fromObject(rawResult); }
/** * 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 HtmlPage restartFromStageInUI(@Nonnull WorkflowRun original, @Nonnull String stageName) throws Exception { RestartDeclarativePipelineAction action = original.getAction(RestartDeclarativePipelineAction.class); assertNotNull(action); assertTrue(action.isRestartEnabled()); HtmlPage page = j.createWebClient().getPage(original, action.getUrlName()); HtmlForm form = page.getFormByName("restart"); HtmlSelect select = form.getSelectByName("stageName"); select.getOptionByValue(stageName).setSelected(true); return j.submit(form); }
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); }
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()); }