예제 #1
0
  /** Tests that listeners are fired when a comment is rejected. */
  public void testListenersFiredWhenCommentRejected() throws Exception {
    final StringBuffer buf = new StringBuffer("123");
    final Comment comment =
        blogEntry.createComment(
            "title", "body", "author", "email", "website", "avatar", "127.0.0.1");
    blogEntry.addComment(comment);
    comment.setPending();
    service.putBlogEntry(blogEntry);

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

          public void commentRemoved(CommentEvent event) {}

          public void commentApproved(CommentEvent event) {}

          public void commentRejected(CommentEvent event) {
            assertEquals(comment, event.getSource());
            buf.reverse();
          }
        };

    blog.getEventListenerList().addCommentListener(listener);
    comment.setRejected();
    service.putBlogEntry(blogEntry);
    assertEquals("321", buf.toString());
  }
예제 #2
0
  /**
   * Tests that listeners are not fired when a cloned comment is approved. Why? Because manipulating
   * comments from a blog entry decorator will generate excess events if not disabled.
   */
  public void testListenersNotFiredWhenCommentApprovedOnClone() {
    comment.setPending();
    comment = (Comment) comment.clone();

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

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

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

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

    blog.getEventListenerList().addCommentListener(listener);
    comment.setApproved();
  }
예제 #3
0
  /** Tests that a CommentEvent can be vetoed. */
  public void commentEventCanBeVetoed() {
    // create 2 listeners, veto the event in the first and
    // fail if the second receives the event

    comment.setPending();

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

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

          public void commentApproved(CommentEvent event) {
            event.veto();
          }

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

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

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

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

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

    blog.getEventListenerList().addCommentListener(listener1);
    blog.getEventListenerList().addCommentListener(listener2);

    comment.setApproved();
  }
예제 #4
0
  /** Tests the various states for a comment. */
  public void testStates() {
    // the default is approved
    assertEquals(State.APPROVED, comment.getState());
    assertTrue(comment.isApproved());
    assertFalse(comment.isPending());
    assertFalse(comment.isRejected());

    comment.setPending();
    assertEquals(State.PENDING, comment.getState());
    assertFalse(comment.isApproved());
    assertTrue(comment.isPending());
    assertFalse(comment.isRejected());

    comment.setRejected();
    assertEquals(State.REJECTED, comment.getState());
    assertFalse(comment.isApproved());
    assertFalse(comment.isPending());
    assertTrue(comment.isRejected());
  }
예제 #5
0
  /** Tests that listeners are not fired when a comment is marked as pending. */
  public void testListenersFiredWhenCommentMarkedAsPending() {

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

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

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

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

    blog.getEventListenerList().addCommentListener(listener);
    comment.setPending();
  }