}
@Test
public void testDeleteAricleWithComments() {
Blog blog = createBlog();
Article article1 = createArticle(blog);
Article article2 = createArticle(blog);
for (int i = 0; i < 10; i++) {
Comment comment = new Comment();
comment.setContent("comment " + i);
comment.setCreationDate(new Date());
comment.setArticle(article1);
comment.setUser(createUser());
commentDao.merge(comment);
}
for (int i = 10; i < 30; i++) {
Comment comment = new Comment();
comment.setContent("comment " + i);
comment.setCreationDate(new Date());
comment.setArticle(article2);
comment.setUser(createUser());
commentDao.merge(comment);
}
assertEquals("30 comments", commentDao.findAll().size(), 30);
articleDao.delete(article1.getId());
assertEquals("20 comments", commentDao.findAll().size(), 20);
articleDao.delete(article2.getId());
assertEquals("0 comments", commentDao.findAll().size(), 0);
}