/** * Tests that configuring an existing project via jenkins http rest doesn't produce duplicated * triggers and that the trigger is configured for the new project pattern. * * @throws Exception if so */ @Test @LocalData public void testReconfigureUsingRestApi() throws Exception { assertNrOfEventListeners(0); TopLevelItem testProj = j.jenkins.getItem("testProj"); String gerritProjectPattern = "someotherproject"; XmlPage xmlPage = loadConfigXmlViaHttp(testProj); Document document = xmlPage.getXmlDocument(); String xml = changeConfigXml(gerritProjectPattern, document); URL url = UrlUtils.toUrlUnsafe(j.getURL().toExternalForm() + testProj.getUrl() + "config.xml"); WebRequestSettings request = new WebRequestSettings(url, HttpMethod.POST); request.setRequestBody(xml); j.jenkins.setCrumbIssuer(null); Page page = j.createWebClient().getPage(request); j.assertGoodStatus(page); assertNrOfEventListeners(0); assertEventListenerWithSomeOtherProjectSet(gerritProjectPattern); }
private void ProcessTest(WebTest test) { HtmlPage page = null; // Orville.LOG().info(String.format("Executing test %s\n", event)); WebClient webClient = new WebClient(); webClient.setRefreshHandler(new ThreadedRefreshHandler()); webClient.getOptions().setJavaScriptEnabled(false); try { if (test.getMethod().toLowerCase().equals("post")) { WebRequest request = new WebRequest(UrlUtils.toUrlUnsafe(test.getUrlString()), HttpMethod.POST); request.setRequestParameters(new ArrayList<NameValuePair>()); for (Map.Entry<String, String> entry : test.getPostData().entrySet()) { request.getRequestParameters().add(new NameValuePair(entry.getKey(), entry.getValue())); } page = webClient.getPage(request); } else { page = webClient.getPage(test.getUrlString()); } ProcessResult(test, page.getWebResponse()); } catch (FailingHttpStatusCodeException fsc) { Orville.LOG() .warning( String.format( "Failing HTTP Status code caught executing the test command: %s\n", fsc.getMessage())); } catch (IOException ioe) { Orville.LOG() .warning( String.format( "IO Exception caught executing the test command: %s\n", ioe.getMessage())); } webClient.closeAllWindows(); }