Exemplo n.º 1
0
 /**
  * Add a comment to the comment set.
  *
  * @param comment the comment node.
  * @throws IllegalArgumentException if comment is {@code null}
  */
 public void addComment(Comment comment) {
   assertNotNull(comment);
   if (comments == null) {
     comments = new TreeSet<Comment>(new AstNode.PositionComparator());
   }
   comments.add(comment);
   comment.setParent(this);
 }
Exemplo n.º 2
0
  public void testNestedCommentsAreUnindexedWhenParentDeleted() throws Exception {
    BlogService service = new BlogService();
    Comment comment2 =
        blogEntry.createComment(
            "Title",
            "Body",
            "Author",
            "*****@*****.**",
            "http://www.google.com",
            "http://graph.facebook.com/user/picture",
            "127.0.0.1");
    Comment comment3 =
        blogEntry.createComment(
            "Title",
            "Body",
            "Author",
            "*****@*****.**",
            "http://www.google.com",
            "http://graph.facebook.com/user/picture",
            "127.0.0.1");

    service.putBlogEntry(blogEntry);
    blogEntry.addComment(comment);

    comment2.setParent(comment);
    blogEntry.addComment(comment2);
    service.putBlogEntry(blogEntry);

    comment3.setParent(comment);
    blogEntry.addComment(comment3);
    service.putBlogEntry(blogEntry);

    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment.getGuid()));
    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment2.getGuid()));
    assertTrue(blog.getResponseIndex().getPendingResponses().contains(comment3.getGuid()));

    blogEntry.removeComment(comment.getId());
    service.putBlogEntry(blogEntry);

    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment.getGuid()));
    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment2.getGuid()));
    assertFalse(blog.getResponseIndex().getPendingResponses().contains(comment3.getGuid()));
  }
Exemplo n.º 3
0
  /** Tests that comment listeners are fired when a blog entry is removed. */
  public void testListenersFiredForCommentsWhenBlogEntryRemoved() throws Exception {
    final Comment comment1 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    final Comment comment2 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    final Comment comment3 =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");

    blogEntry.addComment(comment1);
    blogEntry.addComment(comment2);
    service.putBlogEntry(blogEntry);

    comment3.setParent(comment2);
    blogEntry.addComment(comment3);
    service.putBlogEntry(blogEntry);

    final List comments = new ArrayList();

    CommentListener listener =
        new CommentListener() {
          public void commentAdded(CommentEvent event) {
            fail();
          }

          public void commentRemoved(CommentEvent event) {
            comments.add(event.getSource());
          }

          public void commentApproved(CommentEvent event) {
            fail();
          }

          public void commentRejected(CommentEvent event) {
            fail();
          }
        };

    blog.getEventListenerList().addCommentListener(listener);
    service.removeBlogEntry(blogEntry);

    assertEquals(comment1, comments.get(0));
    assertEquals(comment2, comments.get(1));
    assertEquals(comment3, comments.get(2));
  }
Exemplo n.º 4
0
 /** Tests that the number of parents is correct when comments are nested. */
 public void testNumberOfParentsIsCorrectWhenNested() {
   comment.setParent(new BlogEntry(blog).createComment("", "", "", "", "", "", ""));
   assertEquals(1, comment.getNumberOfParents());
 }