@Test
 public void api() throws Exception {
   MatrixProject project = j.createMatrixProject();
   project.setAxes(new AxisList(new Axis("FOO", "abc", "def"), new Axis("BAR", "uvw", "xyz")));
   XmlPage xml = j.createWebClient().goToXml(project.getUrl() + "api/xml");
   assertEquals(4, xml.getByXPath("//matrixProject/activeConfiguration").size());
 }
 // TODO: change doctype type to "DocType"
 public XMLDocument jsxFunction_createDocument(
     final String namespaceURI, final String qualifiedName, final Object doctype) {
   final XMLDocument document = new XMLDocument(getWindow().getWebWindow());
   document.setParentScope(getParentScope());
   document.setPrototype(getPrototype(document.getClass()));
   if (qualifiedName != null && qualifiedName.length() != 0) {
     final XmlPage page = document.getDomNodeOrDie();
     page.appendChild(page.createXmlElementNS(namespaceURI, qualifiedName));
   }
   return document;
 }
Beispiel #3
0
 /*  19:    */ public Page createPage(WebResponse webResponse, WebWindow webWindow)
     /*  20:    */ throws IOException
       /*  21:    */ {
   /*  22:100 */ String contentType =
       determineContentType(
           webResponse.getContentType().toLowerCase(), webResponse.getContentAsStream());
   /*  23:    */
   /*  24:    */
   /*  25:    */
   /*  26:104 */ String pageType = determinePageType(contentType);
   /*  27:    */ Page newPage;
   /*  28:    */ Page newPage;
   /*  29:105 */ if ("html".equals(pageType))
   /*  30:    */ {
     /*  31:106 */ newPage = createHtmlPage(webResponse, webWindow);
     /*  32:    */ }
   /*  33:    */ else
   /*  34:    */ {
     /*  35:    */ Page newPage;
     /*  36:108 */ if ("javascript".equals(pageType))
     /*  37:    */ {
       /*  38:109 */ newPage = createJavaScriptPage(webResponse, webWindow);
       /*  39:    */ }
     /*  40:    */ else
     /*  41:    */ {
       /*  42:    */ Page newPage;
       /*  43:111 */ if ("xml".equals(pageType))
       /*  44:    */ {
         /*  45:112 */ XmlPage xml = createXmlPage(webResponse, webWindow);
         /*  46:113 */ DomElement doc = xml.getDocumentElement();
         /*  47:    */ Page newPage;
         /*  48:114 */ if ((doc != null)
             && ("http://www.w3.org/1999/xhtml".equals(doc.getNamespaceURI()))) {
           /*  49:115 */ newPage = createXHtmlPage(webResponse, webWindow);
           /*  50:    */ } else {
           /*  51:118 */ newPage = xml;
           /*  52:    */ }
         /*  53:    */ }
       /*  54:    */ else
       /*  55:    */ {
         /*  56:    */ Page newPage;
         /*  57:121 */ if ("text".equals(pageType)) {
           /*  58:122 */ newPage = createTextPage(webResponse, webWindow);
           /*  59:    */ } else {
           /*  60:125 */ newPage = createUnexpectedPage(webResponse, webWindow);
           /*  61:    */ }
         /*  62:    */ }
       /*  63:    */ }
     /*  64:    */ }
   /*  65:127 */ return newPage;
   /*  66:    */ }
  /**
   * Returns the element with the specified ID, as long as it is an HTML element; <tt>null</tt>
   * otherwise.
   *
   * @param id the ID to search for
   * @return the element with the specified ID, as long as it is an HTML element; <tt>null</tt>
   *     otherwise
   */
  public Object jsxFunction_getElementById(final String id) {
    final XmlPage xmlPage = (XmlPage) getDomNodeOrDie();
    final Object domElement = xmlPage.getFirstByXPath("//*[@id = \"" + id + "\"]");
    if (domElement == null) {
      return null;
    }

    if (domElement instanceof HtmlElement) {
      return ((HtmlElement) domElement).getScriptObject();
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("getElementById(" + id + "): no HTML DOM node found with this ID");
    }
    return null;
  }
 /**
  * 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);
 }
 /**
  * Test search server.
  *
  * @throws FailingHttpStatusCodeException the failing http status code exception
  * @throws MalformedURLException the malformed url exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @Test
 public void testSearchServer()
     throws FailingHttpStatusCodeException, MalformedURLException, IOException {
   final Properties settings = new Properties();
   settings.load(ApplicationStartupTest.class.getResourceAsStream("/test.properties"));
   final WebClient webClient = new WebClient();
   final Page page =
       webClient.getPage(
           "http://localhost:"
               + settings.getProperty("cargo.port")
               + settings.getProperty("search.context")
               + "/product/select?q=*:*");
   assertEquals(HTTP_STATUS_OK, page.getWebResponse().getStatusCode());
   assertTrue(page instanceof XmlPage);
   XmlPage xmlPage = (XmlPage) page;
   assertTrue(xmlPage.hasChildNodes());
   webClient.closeAllWindows();
 }
  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();
  }