public HtmlPage submit(JenkinsRule rule) throws Exception { return rule.submit(signupForm); }
/** * Hits the Hudson system configuration and submits without any modification. */ public void configRoundtrip() throws Exception { submit(createWebClient().goTo("configure").getFormByName("config")); }
/** * 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; }
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; }
public <V extends View> V configRoundtrip(V view) throws Exception { submit(createWebClient().getPage(view, "configure").getFormByName("viewConfig")); return view; }
public User configRoundtrip(User u) throws Exception { submit(createWebClient().goTo(u.getUrl()+"/configure").getFormByName("config")); return u; }
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()); }
/** * Remove Server from UI. * @param serverName the name of the Gerrit server you want to access. * @return true if the form had a button and was posted * @throws Exception if error removing server. */ private boolean removeServer(String serverName) throws Exception { URL url = new URL(j.getURL(), Functions.joinPath(serverURL, "server", serverName, "remove")); HtmlPage removalPage = j.createWebClient().getPage(url); HtmlForm form = removalPage.getFormByName(removalFormName); List<HtmlElement> buttons = form.getHtmlElementsByTagName("button"); textContent = form.getTextContent(); if (buttons.size() >= 1) { j.submit(form); return true; } else { return false; } }
@Issue("JENKINS-9143") @Test public void checkEmptyRemoteRemoved() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); List<ModuleLocation> locs = new ArrayList<>(); locs.add(new ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusion", "c")); locs.add(new ModuleLocation("", "d")); locs.add(new ModuleLocation(" ", "e")); SubversionSCM scm = new SubversionSCM( locs, new UpdateUpdater(), new Sventon(new URL("http://www.sun.com/"), "test"), "exclude", "user", "revprop", "excludeMessage",null); p.setScm(scm); r.submit(r.createWebClient().getPage(p, "configure").getFormByName("config")); ModuleLocation[] ml = ((SubversionSCM) p.getScm()).getLocations(); assertEquals(1, ml.length); assertEquals("https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusion", ml[0].remote); }
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); }
/** * Makes sure that there's no JavaScript error in the new view page. */ @Test public void newViewPage() throws Exception { Folder f = createFolder(); HtmlPage p = r.createWebClient().getPage(f, "newView"); HtmlForm fm = p.getFormByName("createItem"); fm.getInputByName("name").setValueAttribute("abcView"); for (HtmlRadioButtonInput r : fm.getRadioButtonsByName("mode")) { if (r.getValueAttribute().equals(ListView.class.getName())) r.click(); } r.submit(fm); assertSame(ListView.class, f.getView("abcView").getClass()); }
/** * Add a GerritServer with default configs from the UI. * * @param serverName the name * @throws Exception if error getting URL or getting page from URL. */ private void addNewServerWithDefaultConfigs(String serverName) throws Exception { URL url = new URL(j.getURL(), newServerURL); HtmlPage page = j.createWebClient().getPage(url); HtmlForm form = page.getFormByName(newServerFormName); form.getInputByName(inputFormName).setValueAttribute(serverName); List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName); HtmlRadioButtonInput radioButtonDefaultConfig = null; for (HtmlRadioButtonInput button : radioButtons) { if (radioButtonDefaultConfigValue.equals(button.getValueAttribute())) { radioButtonDefaultConfig = button; radioButtonDefaultConfig.setChecked(true); } } assertTrue("Failed to choose 'GerritServer with Default Configurations'", radioButtonDefaultConfig.isChecked()); j.submit(form); }
@Test public void configRoundtrip() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); SubversionSCM scm = new SubversionSCM( Arrays.asList( new ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusion", "c"), new ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusion", "d")), new UpdateUpdater(),new Sventon(new URL("http://www.sun.com/"),"test"),"exclude","user","revprop","excludeMessage",null); p.setScm(scm); r.submit(r.createWebClient().getPage(p,"configure").getFormByName("config")); verify(scm,(SubversionSCM)p.getScm()); scm = new SubversionSCM( Arrays.asList( new ModuleLocation("https://svn.jenkins-ci.org/trunk/hudson/test-projects/testSubversionExclusion", "c")), new CheckoutUpdater(),null,"","","","",null); p.setScm(scm); r.submit(r.createWebClient().getPage(p,"configure").getFormByName("config")); verify(scm,(SubversionSCM)p.getScm()); }
/** * Tests correct addListener behaviour when a project is renamed. * * @throws Exception id so. */ @LocalData @Test public void testNewProjectCreationWithReName() throws Exception { FreeStyleProject p = createGerritTriggeredJob(j, "testJob3"); HtmlForm form = j.createWebClient().getPage(p, "configure").getFormByName("config"); form.getInputByName("name").setValueAttribute("testJob33"); HtmlPage confirmPage = j.submit(form); j.submit(getFormWithAction("doRename", confirmPage.getForms())); //configRoundtrip(p); assertEquals("testJob33", p.getName()); assertNbrOfGerritEventListeners( PluginImpl.getInstance().getServer(PluginImpl.DEFAULT_SERVER_NAME)); }
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()); }
/** * Tests rename operation. */ @Test public void rename() throws Exception { Folder f = createFolder(); f.setDescription("Some view"); String oldName = f.getName(); HtmlForm cfg = r.createWebClient().getPage(f, "confirm-rename").getFormByName("config"); cfg.getInputByName("newName").setValueAttribute("newName"); for (HtmlForm form : r.submit(cfg).getForms()) { if (form.getActionAttribute().equals("confirmRename")) { r.submit(form); break; } } assertEquals("newName",f.getName()); assertEquals("Some view",f.getDescription()); assertNull(r.jenkins.getItem(oldName)); assertSame(r.jenkins.getItem("newName"),f); }
@Issue("JENKINS-48379") @Test public void simpleInput() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "simpleInput"); p.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("simpleInput"), true)); // get the build going, and wait until workflow pauses QueueTaskFuture<WorkflowRun> q = p.scheduleBuild2(0); WorkflowRun b = q.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); while (b.getAction(InputAction.class)==null) { e.waitForSuspension(); } // make sure we are pausing at the right state that reflects what we wrote in the program InputAction a = b.getAction(InputAction.class); assertEquals(1, a.getExecutions().size()); InputStepExecution is = a.getExecution("Foo"); assertEquals("Continue?", is.getInput().getMessage()); assertEquals(0, is.getInput().getParameters().size()); assertNull(is.getInput().getSubmitter()); JenkinsRule.WebClient wc = j.createWebClient(); HtmlPage page = wc.getPage(b, a.getUrlName()); j.submit(page.getFormByName(is.getId()), "proceed"); assertEquals(0, a.getExecutions().size()); q.get(); j.assertBuildStatusSuccess(j.waitForCompletion(b)); j.assertLogContains("hello", b); }
/** * Subversion externals to a file. Requires 1.6 workspace. */ @Issue("JENKINS-7539") @Test public void externalsToFile() throws Exception { Proc server = runSvnServe(getClass().getResource("HUDSON-7539.zip")); try { // enable 1.6 mode HtmlForm f = r.createWebClient().goTo("configure").getFormByName("config"); f.getSelectByName("svn.workspaceFormat").setSelectedAttribute("10",true); r.submit(f); FreeStyleProject p = r.createFreeStyleProject(); p.setScm(new SubversionSCM("svn://localhost/dir1")); FreeStyleBuild b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertTrue(b.getWorkspace().child("2").exists()); assertTrue(b.getWorkspace().child("3").exists()); assertTrue(b.getWorkspace().child("test.x").exists()); r.assertBuildStatusSuccess(p.scheduleBuild2(0)); } finally { server.kill(); } }
/** * Tests {@link ManualTriggerAction.Approval#getApprovals(net.sf.json.JSONObject, int)}. * With an last patchset * * @throws Exception if so. */ @Test public void testDoGerritSearchLastPatchSet() throws Exception { JenkinsRule.WebClient client = j.createWebClient(); HtmlPage page = client.goTo("gerrit_manual_trigger"); HtmlForm theSearch = page.getFormByName("theSearch"); page = j.submit(theSearch); HtmlTable table = page.getElementByName("searchResultTable"); HtmlTableCell verifiedCell = table.getCellAt(FIRST_RESULT_ROW, VERIFIED_COLUMN); DomNode child = verifiedCell.getFirstChild(); assertThat(child, instanceOf(HtmlImage.class)); assertEquals("-1", ((HtmlImage)child).getAltAttribute()); HtmlTableCell codeReviewCell = table.getCellAt(FIRST_RESULT_ROW, CODE_REVIEW_COLUMN); child = codeReviewCell.getFirstChild(); assertThat(child, instanceOf(HtmlImage.class)); assertEquals("2", ((HtmlImage)child).getAltAttribute()); }
/** * Tests {@link ManualTriggerAction.Approval#getApprovals(net.sf.json.JSONObject, int)}. * With an all patchsets * * @throws Exception if so. */ @Test public void testDoGerritSearchAllPatchSets() throws Exception { JenkinsRule.WebClient client = j.createWebClient(); HtmlPage page = client.goTo("gerrit_manual_trigger"); HtmlForm theSearch = page.getFormByName("theSearch"); page = theSearch.getInputByName("allPatchSets").click(); theSearch = page.getFormByName("theSearch"); page = j.submit(theSearch); HtmlTable table = page.getElementByName("searchResultTable"); HtmlTableCell verifiedCell = table.getCellAt(SECOND_RESULT_ROW, VERIFIED_COLUMN); DomNode child = verifiedCell.getFirstChild(); assertThat(child, instanceOf(HtmlImage.class)); assertEquals("-1", ((HtmlImage)child).getAltAttribute()); HtmlTableCell codeReviewCell = table.getCellAt(SECOND_RESULT_ROW, CODE_REVIEW_COLUMN); child = codeReviewCell.getFirstChild(); assertThat(child, instanceOf(HtmlImage.class)); assertEquals("2", ((HtmlImage)child).getAltAttribute()); } }