/** 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); }