private String getConfigXml(XmlPage page) throws TransformerException {
    // {@link XmlPage#asXml} does unneccessary indentations.
    Document doc = page.getXmlDocument();
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer();

    StringWriter sw = new StringWriter();
    transformer.transform(new DOMSource(doc), new StreamResult(sw));

    return sw.toString();
  }
 /**
  * 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);
 }