001: package org.apache.roller.business;
002:
003: import java.util.List;
004: import java.util.Map;
005: import junit.framework.TestCase;
006: import org.apache.roller.TestUtils;
007: import org.apache.roller.business.RollerFactory;
008: import org.apache.roller.business.UserManager;
009: import org.apache.roller.business.WeblogManager;
010: import org.apache.roller.pojos.CommentData;
011: import org.apache.roller.pojos.StatCount;
012: import org.apache.roller.pojos.UserData;
013: import org.apache.roller.pojos.WeblogEntryData;
014: import org.apache.roller.pojos.WebsiteData;
015:
016: /**
017: *
018: */
019: public class WeblogStatsTest extends TestCase {
020:
021: private UserData user1, user2;
022:
023: private WebsiteData website1;
024: private WeblogEntryData entry11;
025: private CommentData comment11;
026: private CommentData comment12;
027: private WeblogEntryData entry12;
028: private CommentData comment13;
029:
030: private WebsiteData website2;
031: private WeblogEntryData entry21;
032: private CommentData comment21;
033:
034: public WeblogStatsTest() {
035: }
036:
037: protected void setUp() throws Exception {
038: // create weblog with three entries and two comments per entry
039: user1 = TestUtils.setupUser("a_commentCountTestUser");
040: user2 = TestUtils.setupUser("b_commentCountTestUser");
041:
042: website1 = TestUtils.setupWeblog("a_testWebsite1", user1);
043: entry11 = TestUtils.setupWeblogEntry("anchor11", website1
044: .getDefaultCategory(), website1, user1);
045: comment11 = TestUtils.setupComment("Comment11", entry11);
046: comment12 = TestUtils.setupComment("Comment12", entry11);
047: entry12 = TestUtils.setupWeblogEntry("anchor12", website1
048: .getDefaultCategory(), website1, user1);
049: comment13 = TestUtils.setupComment("Comment13", entry12);
050:
051: website2 = TestUtils.setupWeblog("b_testWebsite2", user1);
052: entry21 = TestUtils.setupWeblogEntry("anchor21", website2
053: .getDefaultCategory(), website2, user1);
054: comment21 = TestUtils.setupComment("Comment21", entry21);
055: TestUtils.endSession(true);
056: }
057:
058: public void testGetMostCommentedWeblogs() throws Exception {
059: UserManager mgr = RollerFactory.getRoller().getUserManager();
060: List list = mgr.getMostCommentedWebsites(null, null, 0, -1);
061:
062: assertNotNull(list);
063: assertEquals(2, list.size());
064:
065: StatCount s1 = (StatCount) list.get(0);
066: assertEquals(website1.getId(), s1.getSubjectId());
067: assertEquals(3L, s1.getCount());
068:
069: StatCount s2 = (StatCount) list.get(1);
070: assertEquals(website2.getId(), s2.getSubjectId());
071: assertEquals(1L, s2.getCount());
072: }
073:
074: public void testGetMostCommentedWeblogEntries() throws Exception {
075: WeblogManager mgr = RollerFactory.getRoller()
076: .getWeblogManager();
077: List list = mgr.getMostCommentedWeblogEntries(null, null, null,
078: 0, -1);
079:
080: assertNotNull(list);
081: assertEquals(3, list.size());
082:
083: StatCount s1 = (StatCount) list.get(0);
084: assertEquals(2L, s1.getCount());
085: assertEquals(entry11.getId(), s1.getSubjectId());
086:
087: StatCount s2 = (StatCount) list.get(1);
088: assertEquals(1L, s2.getCount());
089: }
090:
091: public void testGetUserNameLetterMap() throws Exception {
092: UserManager mgr = RollerFactory.getRoller().getUserManager();
093: Map map = mgr.getUserNameLetterMap();
094: assertNotNull(map.get("a"));
095: assertNotNull(map.get("b"));
096: assertNull(map.get("c"));
097: }
098:
099: public void testGetWeblogLetterMap() throws Exception {
100: UserManager mgr = RollerFactory.getRoller().getUserManager();
101: Map map = mgr.getWeblogHandleLetterMap();
102: assertNotNull(map.get("a"));
103: assertNotNull(map.get("b"));
104: assertNull(map.get("c"));
105: }
106:
107: protected void tearDown() throws Exception {
108:
109: // TODO: ATLAS figure out why comments must be torn down first
110: TestUtils.teardownComment(comment11.getId());
111: TestUtils.teardownComment(comment12.getId());
112: TestUtils.teardownComment(comment13.getId());
113: TestUtils.teardownWeblog(website1.getId());
114:
115: TestUtils.teardownComment(comment21.getId());
116: TestUtils.teardownWeblog(website2.getId());
117:
118: TestUtils.teardownUser(user1.getId());
119: TestUtils.teardownUser(user2.getId());
120:
121: TestUtils.endSession(true);
122: }
123: }
|