public void testDoConfigure() throws Exception {
    UpdateSite target = new UpdateSite("test1", "http://example.com/test/update-center.json");

    // Multiple update site.
    Jenkins.getInstance().getUpdateCenter().getSites().clear();
    Jenkins.getInstance().getUpdateCenter().getSites().add(target);

    String originalId = target.getId();

    WebClient wc = new WebClient();

    HtmlPage editSitePage = wc.goTo(String.format("%s/%s", UpdateSitesManager.URL, target.getId()));

    HtmlForm editSiteForm = editSitePage.getFormByName("editSiteForm");
    assertNotNull("There must be editSiteForm", editSiteForm);

    String newId = "newId";
    String newUrl = "http://localhost/update-center.json";
    editSiteForm.getInputByName("_.id").setValueAttribute(newId);
    editSiteForm.getInputByName("_.url").setValueAttribute(newUrl);
    submit(editSiteForm);

    UpdateSite site = null;
    for (UpdateSite s : Jenkins.getInstance().getUpdateCenter().getSites()) {
      if (newId.equals(s.getId())) {
        site = s;
      }
      assertFalse("id must be updated(old one must not remain)", originalId.equals(s.getId()));
    }
    assertNotNull("id must be updated", site);
    assertEquals("url must be updated", newUrl, site.getUrl());
  }
  public void testDoDelete() throws Exception {
    UpdateSite target = new UpdateSite("test1", "http://example.com/test/update-center.json");

    Jenkins.getInstance().getUpdateCenter().getSites().clear();
    Jenkins.getInstance().getUpdateCenter().getSites().add(target);

    int initialSize = Jenkins.getInstance().getUpdateCenter().getSites().size();

    WebClient wc = new WebClient();

    HtmlPage deleteSitePage =
        wc.goTo(String.format("%s/%s/delete", UpdateSitesManager.URL, target.getId()));
    assertEquals(
        "UpdateSite must not be deleted yet.",
        initialSize,
        Jenkins.getInstance().getUpdateCenter().getSites().size());

    HtmlForm deleteSiteForm = deleteSitePage.getFormByName("deleteSiteForm");
    assertNotNull("There must be deleteSiteForm", deleteSiteForm);

    submit(deleteSiteForm);
    assertEquals(
        "UpdateSite must be deleted.",
        initialSize - 1,
        Jenkins.getInstance().getUpdateCenter().getSites().size());
  }
Esempio n. 3
0
  /** Bare-minimum configuration mechanism to change the update center. */
  public HttpResponse doSiteConfigure(@QueryParameter String site) throws IOException {
    Jenkins hudson = Jenkins.getInstance();
    hudson.checkPermission(CONFIGURE_UPDATECENTER);
    UpdateCenter uc = hudson.getUpdateCenter();
    PersistedList<UpdateSite> sites = uc.getSites();
    for (UpdateSite s : sites) {
      if (s.getId().equals(UpdateCenter.ID_DEFAULT)) sites.remove(s);
    }
    sites.add(new UpdateSite(UpdateCenter.ID_DEFAULT, site));

    return HttpResponses.redirectToContextRoot();
  }