assertEquals("20 articles in user 2", blogContributionDao.findByUser(user2).size(), 20);
}
@Test
public void testDeleteBlog() {
Blog blog1 = createBlog();
Blog blog2 = createBlog();
for (int i = 0; i < 10; i++) {
BlogContribution bc = new BlogContribution();
bc.setCreationDate(new Date());
bc.setBlog(blog1);
bc.setUser(createUser());
blogContributionDao.merge(bc);
}
for (int i = 10; i < 30; i++) {
BlogContribution bc = new BlogContribution();
bc.setCreationDate(new Date());
bc.setBlog(blog2);
bc.setUser(createUser());
blogContributionDao.merge(bc);
}
assertEquals("30 contributions in datastore", blogContributionDao.findAll().size(), 30);
assertEquals("10 articles in blog 1", blogContributionDao.findByBlog(blog1).size(), 10);
assertEquals("20 articles in blog 2", blogContributionDao.findByBlog(blog2).size(), 20);
blogDao.delete(blog1.getId());
assertEquals("20 contributions in datastore", blogContributionDao.findAll().size(), 20);
blogDao.delete(blog2.getId());
assertEquals("0 contributions in datastore", blogContributionDao.findAll().size(), 0);
}