assertNotNull(sc);
User currentUser = getUser();
assertNotNull(currentUser);
ForumPost fp = new SchoolForumPost(sc, currentUser, TITLE, TEXT,
null);
executeWithToken(new SaveForumPostCommand(fp), false);
PostsList posts = schoolService.getForum(sc, 0, 10);
assertEquals(1, posts.getTotalCount());
assertEquals(1, posts.getPosts().size());
ForumPost saved = posts.getPosts().get(0);
assertNotNull(saved);
assertEquals(SchoolForumPost.class, saved.getClass());
assertTrue(saved.getId() > 0);
assertEquals(TITLE, saved.getPostTitle());
assertEquals(TEXT, saved.getPostString());
assertEquals(0, saved.getReplyCount());
assertEquals(null, saved.getThreadPost());
assertEquals(currentUser, saved.getAuthor());
// save a second post to the same thread
ForumPost fp2 = new SchoolForumPost(sc, currentUser, TITLE, TEXT,
saved);
executeWithToken(new SaveForumPostCommand(fp2), false);
// assert that there's still just 1 top level thread
posts = schoolService.getForum(sc, 0, 10);
assertEquals(1, posts.getTotalCount());
assertEquals(1, posts.getPosts().size());
// relies on setting the inverse side of the association for
// testing
assertEquals(1, posts.getPosts().get(0).getReplyCount());
assertEquals(1, saved.getReplyCount());
// get the posts in this thread
posts = schoolService.getForum(saved, 0, 10);
assertEquals(2, posts.getTotalCount());
assertEquals(2, posts.getPosts().size());
ForumPost saved1 = posts.getPosts().get(0);
assertEquals(saved, saved1);
ForumPost saved2 = posts.getPosts().get(1);
assertNotNull(saved2);
assertEquals(SchoolForumPost.class, saved2.getClass());
assertTrue(saved2.getId() > 0);
assertEquals(TITLE, saved2.getPostTitle());
assertEquals(TEXT, saved2.getPostString());
assertEquals(saved1, saved2.getThreadPost());
assertEquals(currentUser, saved2.getAuthor());
}