Beispiel #1
0
  public void testRenamePageWithEmptyTitle() throws Exception {
    JSONObject page;
    String name = System.currentTimeMillis() + "";
    String name2 = System.currentTimeMillis() + 1 + "";

    // Create a page
    page = createOrUpdatePage(name, name, null, Status.STATUS_OK);
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("title"));

    // Fetch it and check
    page = getPage(name, Status.STATUS_OK);
    assertEquals(name, page.getString("name"));
    assertEquals(name, page.getString("title"));

    // update title
    SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI);
    WikiPageInfo pageInfo = wikiService.getWikiPage(site.getShortName(), name);
    NodeRef pageRef = pageInfo.getNodeRef();
    nodeService.setProperty(pageRef, ContentModel.PROP_TITLE, "");

    // Fetch it and check
    page = getPage(name, Status.STATUS_OK);
    JSONArray versions = page.getJSONArray("versionhistory");

    int maxVersionIndex = versions.length() - 1;
    double vNum = Double.parseDouble(versions.getJSONObject(maxVersionIndex).getString("version"));
    String newTitle = versions.getJSONObject(maxVersionIndex).getString("title");
    for (int i = versions.length() - 2; i >= 0; i--) {
      JSONObject version = versions.getJSONObject(i);
      String ver = version.getString("version");
      if (Double.parseDouble(ver) > vNum) {
        maxVersionIndex = i;
        vNum = Double.parseDouble(ver);
        newTitle = versions.getJSONObject(maxVersionIndex).getString("title");
      }
    }
    assertEquals(name, page.getString("name"));
    assertEquals("", newTitle);

    renamePage(name, name2, Status.STATUS_OK);

    // Fetch it at the new address
    page = getPage(name2, Status.STATUS_OK);
    assertEquals(name2, page.getString("name"));
    assertEquals(name2, page.getString("title"));
  }
Beispiel #2
0
  /** Listing */
  public void testOverallListing() throws Exception {
    JSONObject pages;
    JSONArray entries;

    // Initially, there are no events
    pages = getPages(null, null);
    assertEquals("Incorrect JSON: " + pages.toString(), true, pages.has("totalPages"));
    assertEquals(0, pages.getInt("totalPages"));

    // Add two links to get started with
    createOrUpdatePage(PAGE_TITLE_ONE, PAGE_CONTENTS_ONE, null, Status.STATUS_OK);
    createOrUpdatePage(PAGE_TITLE_TWO, PAGE_CONTENTS_TWO, null, Status.STATUS_OK);

    // Check again
    pages = getPages(null, null);

    // Should have two links
    assertEquals("Incorrect JSON: " + pages.toString(), true, pages.has("totalPages"));
    assertEquals(2, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(2, entries.length());
    // Sorted by newest created first
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title"));

    // Add a third, which is internal, and created by the other user
    this.authenticationComponent.setCurrentUser(USER_TWO);
    JSONObject page3 =
        createOrUpdatePage(PAGE_TITLE_THREE, PAGE_CONTENTS_THREE, null, Status.STATUS_OK);
    String name3 = PAGE_TITLE_THREE.replace(' ', '_');
    createOrUpdatePage(PAGE_TITLE_THREE, "UD" + PAGE_CONTENTS_THREE, null, Status.STATUS_OK);
    this.authenticationComponent.setCurrentUser(USER_ONE);

    // Check now, should have three links
    pages = getPages(null, null);
    assertEquals(3, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(3, entries.length());
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));

    // Ask for filtering by user
    pages = getPages(null, USER_ONE);
    assertEquals(2, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(2, entries.length());
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title"));

    pages = getPages(null, USER_TWO);
    assertEquals(1, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(1, entries.length());
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title"));

    // Ask for filtering by recently added docs
    pages = getPages("recentlyAdded", null);
    assertEquals(3, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(3, entries.length());
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));

    // Push one back into the past
    pushPageCreatedDateBack(name3, 10);

    pages = getPages("recentlyAdded", null);
    assertEquals(2, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(2, entries.length());
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(1).getString("title"));

    // Now for recently modified ones
    pages = getPages("recentlyModified", null);
    assertEquals(3, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(3, entries.length());
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(1).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));
    //       assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(2).getString("title"));

    // Change the owner+creator of one of the pages to System, ensure that
    //  this doesn't break anything in the process
    String pageTwoName = entries.getJSONObject(1).getString("name");
    WikiPageInfo pageTwo = wikiService.getWikiPage(SITE_SHORT_NAME_WIKI, pageTwoName);
    nodeService.setProperty(
        pageTwo.getNodeRef(), ContentModel.PROP_OWNER, AuthenticationUtil.SYSTEM_USER_NAME);
    nodeService.setProperty(
        pageTwo.getNodeRef(), ContentModel.PROP_CREATOR, AuthenticationUtil.SYSTEM_USER_NAME);
    nodeService.setProperty(
        pageTwo.getNodeRef(), ContentModel.PROP_MODIFIER, AuthenticationUtil.SYSTEM_USER_NAME);

    // Check the listing still works (note - order will have changed)
    pages = getPages("recentlyModified", null);
    assertEquals(3, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(3, entries.length());
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));

    // Delete User Two, who owns the 3rd page, and ensure that this
    //  doesn't break anything
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    personService.deletePerson(USER_TWO);
    this.authenticationComponent.setCurrentUser(USER_ONE);

    // Check the listing still works
    pages = getPages("recentlyModified", null);
    assertEquals(3, pages.getInt("totalPages"));

    entries = pages.getJSONArray("pages");
    assertEquals(3, entries.length());
    assertEquals(PAGE_TITLE_TWO, entries.getJSONObject(0).getString("title"));
    assertEquals(PAGE_TITLE_THREE, entries.getJSONObject(1).getString("title"));
    assertEquals(PAGE_TITLE_ONE, entries.getJSONObject(2).getString("title"));

    // Now hide the site, and remove the user from it, won't be allowed to see it
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    SiteInfo site = siteService.getSite(SITE_SHORT_NAME_WIKI);
    site.setVisibility(SiteVisibility.PRIVATE);
    siteService.updateSite(site);
    siteService.removeMembership(SITE_SHORT_NAME_WIKI, USER_ONE);
    this.authenticationComponent.setCurrentUser(USER_ONE);

    sendRequest(new GetRequest(URL_WIKI_LIST), Status.STATUS_NOT_FOUND);
  }
Beispiel #3
0
  public void testVersioning() throws Exception {
    WikiPageInfo wikiInfo;
    JSONObject page;
    JSONArray versions;
    String name;

    // Create a page
    page = createOrUpdatePage(PAGE_TITLE_TWO, PAGE_CONTENTS_ONE, null, Status.STATUS_OK);
    name = PAGE_TITLE_TWO.replace(' ', '_');
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("title"));

    // Check it was versioned by default
    wikiInfo = wikiService.getWikiPage(SITE_SHORT_NAME_WIKI, name);
    assertNotNull(wikiInfo);
    assertEquals(
        true, nodeService.hasAspect(wikiInfo.getNodeRef(), ContentModel.ASPECT_VERSIONABLE));

    // Check the JSON for versioning
    page = getPage(name, Status.STATUS_OK);
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("versionhistory"));

    versions = page.getJSONArray("versionhistory");
    assertEquals(1, versions.length());
    assertEquals("1.0", versions.getJSONObject(0).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(0).get("author"));

    // Fetch it at this version
    String content = getPageAtVersion(name, "1.0", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_ONE, content);

    // Upload a new copy without a version flag, denied
    createOrUpdatePage(PAGE_TITLE_TWO, "Changed Contents", "none", Status.STATUS_CONFLICT);

    // Upload a new copy with the appropriate version, allowed
    String PAGE_CONTENTS_CHANGED = "Changed Contents 2";
    page = createOrUpdatePage(PAGE_TITLE_TWO, PAGE_CONTENTS_CHANGED, "1.0", Status.STATUS_OK);

    page = getPage(name, Status.STATUS_OK);
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("versionhistory"));

    versions = page.getJSONArray("versionhistory");
    assertEquals(2, versions.length());
    assertEquals("1.1", versions.getJSONObject(0).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(0).get("author"));
    assertEquals("1.0", versions.getJSONObject(1).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(1).get("author"));

    // Check the version contents
    content = getPageAtVersion(name, "1.1", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_CHANGED, content);
    content = getPageAtVersion(name, "1.0", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_ONE, content);

    // Upload a new copy with the force flag, allowed
    String PAGE_CONTENTS_CHANGED3 = "Changed Contents 3";
    page = createOrUpdatePage(PAGE_TITLE_TWO, PAGE_CONTENTS_CHANGED3, "force", Status.STATUS_OK);

    page = getPage(name, Status.STATUS_OK);
    assertEquals("Incorrect JSON: " + page.toString(), true, page.has("versionhistory"));

    versions = page.getJSONArray("versionhistory");
    assertEquals(3, versions.length());
    assertEquals("1.2", versions.getJSONObject(0).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(0).get("author"));
    assertEquals("1.1", versions.getJSONObject(1).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(1).get("author"));
    assertEquals("1.0", versions.getJSONObject(2).get("version"));
    assertEquals(USER_ONE, versions.getJSONObject(2).get("author"));

    // Check the version contents
    content = getPageAtVersion(name, "1.2", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_CHANGED3, content);
    content = getPageAtVersion(name, "1.1", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_CHANGED, content);
    content = getPageAtVersion(name, "1.0", Status.STATUS_OK);
    assertEquals(PAGE_CONTENTS_ONE, content);

    // You get an empty string back for invalid versions
    content = getPageAtVersion(name, "1.4", Status.STATUS_OK);
    assertEquals("", content);
  }