示例#1
0
  @Test
  public void testGetSortedList() throws Exception {
    User user1 = jpaUserDao.getUserById(1);
    User user2 = jpaUserDao.getUserById(2);
    User user3 = jpaUserDao.getUserById(3);

    Comment comment1 = jpaCommentDao.getCommentById(1);
    Comment comment2 = jpaCommentDao.getCommentById(2);
    Comment comment3 = jpaCommentDao.getCommentById(3);

    CommentUtil commentUtil = new CommentUtil();
    commentUtil.setJpaCommentDao(jpaCommentDao);

    commentUtil.upVote(user1, comment1);
    commentUtil.upVote(user2, comment1);

    commentUtil.upVote(user2, comment3);

    commentUtil.upVote(user1, comment2);
    commentUtil.upVote(user2, comment2);
    commentUtil.upVote(user3, comment2);

    List<Comment> comments = jpaCommentDao.getAllCommentsSortedOnVotesEver();

    assertTrue(
        comments.get(0).getVotes() > comments.get(1).getVotes()
            && comments.get(1).getVotes() > comments.get(2).getVotes());
  }
示例#2
0
 @Test
 public void testDeleteComment() throws Exception {
   Comment comment = jpaCommentDao.getCommentByName("commentName1");
   entityTransactionComment.begin();
   jpaCommentDao.deleteComment(comment);
   entityTransactionComment.commit();
   Comment comment2 = jpaCommentDao.getCommentByName("commentName1");
   assertNull(comment2);
 }
示例#3
0
  @Test
  public void testUpdateComment() throws Exception {
    Comment comment = jpaCommentDao.getCommentById(1);
    comment.setName("updatedName");
    Comment returnedComment = jpaCommentDao.updateComment(comment);
    Comment updatedComment = jpaCommentDao.getCommentById(1);

    assertEquals(returnedComment.getName(), "updatedName");
    assertEquals(updatedComment.getName(), "updatedName");
  }
示例#4
0
  @Test
  public void testFindNewsByComment() throws Exception {
    Comment comment = jpaCommentDao.getCommentById(1);

    List<Comment> commentList = new ArrayList();
    commentList.add(comment);

    News news = jpaNewsDao.getNewsById(1);
    news.setComments(commentList);

    Comment commentWithNews = jpaCommentDao.getCommentById(1);

    assertEquals(news, commentWithNews.getNews());
  }
示例#5
0
 @Test
 public void testCreateComment() throws Exception {
   Comment comment = new Comment("Comment name", "Article name");
   entityTransactionComment.begin();
   Comment returned = jpaCommentDao.createComment(comment);
   entityTransactionComment.commit();
   assertEquals(4, returned.getCommentId());
 }
示例#6
0
  @Test
  public void testCommentContainsComments() throws Exception {
    Comment parentComment = jpaCommentDao.getCommentById(1);

    Comment childComment1 = jpaCommentDao.getCommentById(2);
    Comment childComment2 = jpaCommentDao.getCommentById(3);

    parentComment.addComment(childComment1);
    parentComment.addComment(childComment2);

    entityTransactionComment.begin();
    jpaCommentDao.updateComment(parentComment);
    entityTransactionComment.commit();

    Comment newCom = jpaCommentDao.getCommentById(1);

    assertEquals(2, newCom.getComments().size());
  }
示例#7
0
  @Test
  public void testGetSortedListOnDate() throws Exception {
    Comment comment1 = new Comment("Some1", "comment1");
    Comment comment2 = new Comment("Some2", "comment2");
    Comment comment3 = new Comment("Some3", "comment3");

    entityTransactionComment.begin();
    jpaCommentDao.createComment(comment2);
    jpaCommentDao.createComment(comment1);
    jpaCommentDao.createComment(comment3);
    entityTransactionComment.commit();

    List<Comment> comments = jpaCommentDao.getAllCommentsSortedOnDate();

    assertEquals(comments.get(3).getName(), "Some2");
    assertEquals(comments.get(4).getName(), "Some1");
    assertEquals(comments.get(5).getName(), "Some3");
  }
示例#8
0
 @Test
 public void testGetCommentByName() throws Exception {
   Comment comment = jpaCommentDao.getCommentByName("commentName1");
   assertEquals(1, comment.getCommentId());
 }
示例#9
0
 @Test
 public void testGetAllComment() throws Exception {
   List<Comment> list = jpaCommentDao.getAllComment();
   assertEquals(3, list.size());
 }
示例#10
0
 @Test
 public void testCommentHaveUser() throws Exception {
   Comment comment = jpaCommentDao.getCommentById(1);
   assertEquals(User.class, comment.getUser().getClass());
 }
示例#11
0
 @Test
 public void testGetCommentById() throws Exception {
   Comment comment = jpaCommentDao.getCommentById(1);
   assertEquals(comment.getName(), "commentName1");
 }