Пример #1
0
 /** Tests that the title is set when an owning blog entry is present. */
 public void testTitleTakenFromOwningBlogEntryWhenNotSpecified() {
   BlogEntry entry = new BlogEntry(blog);
   entry.setTitle("My blog entry title");
   comment = entry.createComment(null, "", "", "", "", "", "");
   assertEquals("Re: My blog entry title", comment.getTitle());
   comment = entry.createComment("", "", "", "", "", "", "");
   assertEquals("Re: My blog entry title", comment.getTitle());
 }
Пример #2
0
  /** Tests that listeners are fired when a comment is added. */
  public void testListenersFiredWhenCommentAdded() throws Exception {
    final StringBuffer buf = new StringBuffer("123");
    final Comment comment =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");

    CommentListener listener =
        new CommentListener() {
          public void commentAdded(CommentEvent event) {
            assertEquals(comment, event.getSource());
            buf.reverse();
          }

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

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

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

    blog.getEventListenerList().addCommentListener(listener);
    service.putBlogEntry(blogEntry);
    blogEntry.addComment(comment);
    service.putBlogEntry(blogEntry);
    assertEquals("321", buf.toString());
  }
Пример #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));
  }
Пример #4
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()));
  }
Пример #5
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    blogEntry = new BlogEntry(blog);
    comment =
        blogEntry.createComment(
            "Title",
            "Body",
            "Author",
            "*****@*****.**",
            "http://www.google.com",
            "http://graph.facebook.com/user/picture",
            "127.0.0.1");
    comment.setEventsEnabled(true);
  }