assertEquals("20 articles in blog 2", blog2Articles.size(), 20);
}
@Test
public void testDeleteBlogWithArticles() {
Blog blog1 = createBlog();
Blog blog2 = createBlog();
for (int i = 0; i < 10; i++) {
Article article = new Article();
article.setTitle("title " + i);
article.setCreationDate(new Date());
article.setText("text " + i);
article.setOpenComments(true);
article.setBlog(blog1);
articleDao.merge(article);
}
for (int i = 10; i < 30; i++) {
Article article = new Article();
article.setTitle("title " + i);
article.setCreationDate(new Date());
article.setText("text " + i);
article.setOpenComments(true);
article.setBlog(blog2);
articleDao.merge(article);
}
assertEquals("30 articles", articleDao.findAll().size(), 30);
blogDao.delete(blog1.getId());
assertEquals("20 articles", articleDao.findAll().size(), 20);
blogDao.delete(blog2.getId());
assertEquals("0 articles", articleDao.findAll().size(), 0);
}