1 package org.apache.roller.business; 2 3 import java.util.List ; 4 import java.util.Map ; 5 import junit.framework.TestCase; 6 import org.apache.roller.TestUtils; 7 import org.apache.roller.model.RollerFactory; 8 import org.apache.roller.model.UserManager; 9 import org.apache.roller.model.WeblogManager; 10 import org.apache.roller.pojos.CommentData; 11 import org.apache.roller.pojos.StatCount; 12 import org.apache.roller.pojos.UserData; 13 import org.apache.roller.pojos.WeblogEntryData; 14 import org.apache.roller.pojos.WebsiteData; 15 16 19 public class WeblogStatsTest extends TestCase { 20 21 private UserData user1, user2; 22 23 private WebsiteData website1; 24 private WeblogEntryData entry11; 25 private CommentData comment11; 26 private CommentData comment12; 27 private WeblogEntryData entry12; 28 private CommentData comment13; 29 30 private WebsiteData website2; 31 private WeblogEntryData entry21; 32 private CommentData comment21; 33 34 public WeblogStatsTest() { 35 } 36 protected void setUp() throws Exception { 37 user1 = TestUtils.setupUser("a_commentCountTestUser"); 39 user2 = TestUtils.setupUser("b_commentCountTestUser"); 40 41 website1 = TestUtils.setupWeblog("a_testWebsite1", user1); 42 entry11 = TestUtils.setupWeblogEntry( 43 "anchor11", website1.getDefaultCategory(), website1, user1); 44 comment11 = TestUtils.setupComment("Comment11", entry11); 45 comment12 = TestUtils.setupComment("Comment12", entry11); 46 entry12 = TestUtils.setupWeblogEntry( 47 "anchor12", website1.getDefaultCategory(), website1, user1); 48 comment13 = TestUtils.setupComment("Comment13", entry12); 49 50 website2 = TestUtils.setupWeblog("b_testWebsite2", user1); 51 entry21 = TestUtils.setupWeblogEntry( 52 "anchor21", website2.getDefaultCategory(), website2, user1); 53 comment21 = TestUtils.setupComment("Comment21", entry21); 54 TestUtils.endSession(true); 55 } 56 public void testGetMostCommentedWeblogs() throws Exception { 57 UserManager mgr = RollerFactory.getRoller().getUserManager(); 58 List list = mgr.getMostCommentedWebsites(null, null, 0, -1); 59 60 assertNotNull(list); 61 assertEquals(2, list.size()); 62 63 StatCount s1 = (StatCount)list.get(0); 64 assertEquals(website1.getId(), s1.getSubjectId()); 65 assertEquals(3L, s1.getCount()); 66 67 StatCount s2 = (StatCount)list.get(1); 68 assertEquals(website2.getId(), s2.getSubjectId()); 69 assertEquals(1L, s2.getCount()); 70 } 71 public void testGetMostCommentedWeblogEntries() throws Exception { 72 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 73 List list = mgr.getMostCommentedWeblogEntries(null, null, null, 0, -1); 74 75 assertNotNull(list); 76 assertEquals(3, list.size()); 77 78 StatCount s1 = (StatCount)list.get(0); 79 assertEquals(2L, s1.getCount()); 80 assertEquals(entry11.getId(), s1.getSubjectId()); 81 82 StatCount s2 = (StatCount)list.get(1); 83 assertEquals(1L, s2.getCount()); 84 } 85 public void testGetUserNameLetterMap() throws Exception { 86 UserManager mgr = RollerFactory.getRoller().getUserManager(); 87 Map map = mgr.getUserNameLetterMap(); 88 assertNotNull(map.get("a")); 89 assertNotNull(map.get("b")); 90 assertNull(map.get("c")); 91 } 92 public void testGetWeblogLetterMap() throws Exception { 93 UserManager mgr = RollerFactory.getRoller().getUserManager(); 94 Map map = mgr.getWeblogHandleLetterMap(); 95 assertNotNull(map.get("a")); 96 assertNotNull(map.get("b")); 97 assertNull(map.get("c")); 98 } 99 protected void tearDown() throws Exception { 100 101 TestUtils.teardownComment(comment11.getId()); 103 TestUtils.teardownComment(comment12.getId()); 104 TestUtils.teardownComment(comment13.getId()); 105 TestUtils.teardownWeblog(website1.getId()); 106 107 TestUtils.teardownComment(comment21.getId()); 108 TestUtils.teardownWeblog(website2.getId()); 109 110 TestUtils.teardownUser(user1.getId()); 111 TestUtils.teardownUser(user2.getId()); 112 113 TestUtils.endSession(true); 114 } 115 } 116 | Popular Tags |