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());
  }
Beispiel #2
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();
  }
  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());
  }
Beispiel #4
0
 public void testPrevalidateConfig() throws Exception {
     PersistedList<UpdateSite> sites = jenkins.getUpdateCenter().getSites();
     sites.clear();
     URL url = PluginManagerTest.class.getResource("/plugins/tasks-update-center.json");
     UpdateSite site = new UpdateSite(UpdateCenter.ID_DEFAULT, url.toString());
     sites.add(site);
     assertEquals(FormValidation.ok(), site.updateDirectly(false).get());
     assertNotNull(site.getData());
     assertEquals(Collections.emptyList(), jenkins.getPluginManager().prevalidateConfig(new StringInputStream("<whatever><runant plugin=\"[email protected]\"/></whatever>")));
     assertNull(jenkins.getPluginManager().getPlugin("tasks"));
     List<Future<UpdateCenterJob>> jobs = jenkins.getPluginManager().prevalidateConfig(new StringInputStream("<whatever><tasks plugin=\"[email protected]\"/></whatever>"));
     assertEquals(1, jobs.size());
     UpdateCenterJob job = jobs.get(0).get(); // blocks for completion
     assertEquals("InstallationJob", job.getType());
     UpdateCenter.InstallationJob ijob = (UpdateCenter.InstallationJob) job;
     assertEquals("tasks", ijob.plugin.name);
     assertNotNull(jenkins.getPluginManager().getPlugin("tasks"));
     // TODO restart scheduled (SuccessButRequiresRestart) after upgrade or Support-Dynamic-Loading: false
     // TODO dependencies installed or upgraded too
     // TODO required plugin installed but inactive
 }