/** * Creates a comment to an existing activity. * * @param existingActivity the existing activity * @param posterIdentity the identity who comments * @param number the number of comments */ private void createComment( ExoSocialActivity existingActivity, Identity posterIdentity, int number) { for (int i = 0; i < number; i++) { ExoSocialActivity comment = new ExoSocialActivityImpl(); comment.setTitle("comment " + i); comment.setUserId(posterIdentity.getId()); activityManager.saveComment(existingActivity, comment); comment = activityManager.getComments(existingActivity).get(0); } }
/** * Tests {@link SecurityManager#canDeleteComment(PortalContainer, Identity, ExoSocialActivity)}. */ public void testCanDeleteComment() { createActivities(demoIdentity, demoIdentity, 1); ExoSocialActivity demoActivity = activityManager.getActivities(demoIdentity).get(0); createComment(demoActivity, demoIdentity, 1); ExoSocialActivity demoComment = activityManager.getComments(demoActivity).get(0); boolean demoDeleteDemoComment = SecurityManager.canDeleteComment(getContainer(), demoIdentity, demoComment); assertTrue("demoDeleteDemoComment must be true", demoDeleteDemoComment); // BUG #3: TODO FIX THIS boolean maryDeleteDemoComment = SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoComment); assertFalse("maryDeleteDemoComment must be false", maryDeleteDemoComment); connectIdentities(maryIdentity, demoIdentity, true); createActivities(maryIdentity, demoIdentity, 1); ExoSocialActivity maryActivity = activityManager.getActivities(demoIdentity).get(0); createComment(maryActivity, demoIdentity, 1); createComment(maryActivity, maryIdentity, 1); List<ExoSocialActivity> comments = activityManager.getComments(maryActivity); assertEquals(2, comments.size()); // BUG of ActivityManager, FIX IT and change these lines below following its changes. /* assertTrue("comments.get(0).getPostedTime() > comments.get(1).getPostedTime() must return true", comments.get(0).getPostedTime() > comments.get(1).getPostedTime()); */ assertTrue( "comments.get(0).getPostedTime() < comments.get(1).getPostedTime() must return true", comments.get(0).getPostedTime() < comments.get(1).getPostedTime()); // must > ExoSocialActivity demoCommentMaryActivity = comments.get(0); // must be 1 ExoSocialActivity maryCommentMaryActivity = comments.get(1); // must be 0 boolean demoDeleteMaryCommentMaryActivity = SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentMaryActivity); assertTrue("demoDeleteMaryCommentMaryActivity must be true", demoDeleteMaryCommentMaryActivity); boolean johnDeleteDemoCommentMaryActivity = SecurityManager.canDeleteComment(getContainer(), johnIdentity, demoCommentMaryActivity); assertFalse( "johnDeleteDemoCommentMaryActivity must be false", johnDeleteDemoCommentMaryActivity); createSpaces(1); Space createdSpace = tearDownSpaceList.get(0); Identity spaceIdentity = identityManager.getOrCreateIdentity( SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false); createActivities(spaceIdentity, spaceIdentity, 1); ExoSocialActivity spaceActivity = activityManager.getActivities(spaceIdentity).get(0); createComment(spaceActivity, maryIdentity, 1); createComment(spaceActivity, demoIdentity, 1); List<ExoSocialActivity> spaceActivityComments = activityManager.getComments(spaceActivity); ExoSocialActivity maryCommentSpaceActivity = spaceActivityComments.get(0); // must be demo's comment ExoSocialActivity demoCommentSpaceActivity = spaceActivityComments.get(1); // must be mary's comment boolean maryDeleteDemoCommentSpaceActivity = SecurityManager.canDeleteComment(getContainer(), maryIdentity, demoCommentSpaceActivity); assertFalse( "maryDeleteDemoCommentSpaceActivity must be false", maryDeleteDemoCommentSpaceActivity); boolean demoDeleteMaryCommentSpaceActivity = SecurityManager.canDeleteComment(getContainer(), demoIdentity, maryCommentSpaceActivity); assertTrue( "demoDeleteMaryCommentSpaceActivity must be true", demoDeleteMaryCommentSpaceActivity); }