001: /*
002: * Copyright 2005 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.roller.business;
017:
018: import java.sql.Timestamp;
019: import java.util.Date;
020: import java.util.List;
021: import junit.framework.Test;
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024: import junit.textui.TestRunner;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.roller.TestUtils;
028: import org.apache.roller.planet.business.PlanetManager;
029: import org.apache.roller.business.RollerFactory;
030: import org.apache.roller.pojos.UserData;
031: import org.apache.roller.pojos.WeblogEntryData;
032: import org.apache.roller.pojos.WebsiteData;
033: import org.apache.roller.planet.tasks.RefreshEntriesTask;
034: import org.apache.roller.planet.tasks.SyncWebsitesTask;
035:
036: /**
037: * Test database implementation of PlanetManager for local feeds.
038: * @author Dave Johnson
039: */
040: public class PlanetManagerLocalTest extends TestCase {
041: public static Log log = LogFactory
042: .getLog(PlanetManagerLocalTest.class);
043:
044: UserData testUser = null;
045: WebsiteData testWeblog = null;
046:
047: public static void main(String[] args) {
048: TestRunner.run(PlanetManagerLocalTest.class);
049: }
050:
051: /**
052: * All tests in this suite require a user and a weblog.
053: */
054: public void setUp() throws Exception {
055:
056: try {
057: testUser = TestUtils.setupUser("entryTestUser");
058: testWeblog = TestUtils.setupWeblog("entryTestWeblog",
059: testUser);
060:
061: WeblogEntryData testEntry1 = new WeblogEntryData();
062: testEntry1.setTitle("entryTestEntry1");
063: testEntry1.setLink("testEntryLink1");
064: testEntry1.setText("blah blah entry1");
065: testEntry1.setAnchor("testEntryAnchor1");
066: testEntry1.setPubTime(new Timestamp(new Date().getTime()));
067: testEntry1
068: .setUpdateTime(new Timestamp(new Date().getTime()));
069: testEntry1.setWebsite(testWeblog);
070: testEntry1.setCreator(testUser);
071: testEntry1.setCategory(testWeblog.getDefaultCategory());
072: RollerFactory.getRoller().getWeblogManager()
073: .saveWeblogEntry(testEntry1);
074:
075: WeblogEntryData testEntry2 = new WeblogEntryData();
076: testEntry2.setTitle("entryTestEntry2");
077: testEntry2.setLink("testEntryLink2");
078: testEntry2.setText("blah blah entry2");
079: testEntry2.setAnchor("testEntryAnchor2");
080: testEntry2.setPubTime(new Timestamp(new Date().getTime()));
081: testEntry2
082: .setUpdateTime(new Timestamp(new Date().getTime()));
083: testEntry2.setWebsite(testWeblog);
084: testEntry2.setCreator(testUser);
085: testEntry2.setCategory(testWeblog.getDefaultCategory());
086: RollerFactory.getRoller().getWeblogManager()
087: .saveWeblogEntry(testEntry1);
088:
089: WeblogEntryData testEntry3 = new WeblogEntryData();
090: testEntry3.setTitle("entryTestEntry3");
091: testEntry3.setLink("testEntryLink3");
092: testEntry3.setText("blah blah entry3");
093: testEntry3.setAnchor("testEntryAnchor3");
094: testEntry3.setPubTime(new Timestamp(new Date().getTime()));
095: testEntry3
096: .setUpdateTime(new Timestamp(new Date().getTime()));
097: testEntry3.setWebsite(testWeblog);
098: testEntry3.setCreator(testUser);
099: testEntry3.setCategory(testWeblog.getDefaultCategory());
100: RollerFactory.getRoller().getWeblogManager()
101: .saveWeblogEntry(testEntry1);
102:
103: TestUtils.endSession(true);
104:
105: } catch (Exception ex) {
106: log.error(ex);
107: throw new Exception("Test setup failed", ex);
108: }
109: }
110:
111: public void tearDown() throws Exception {
112:
113: try {
114: TestUtils.teardownWeblog(testWeblog.getId());
115: TestUtils.teardownUser(testUser.getId());
116: TestUtils.endSession(true);
117: } catch (Exception ex) {
118: log.error(ex);
119: throw new Exception("Test teardown failed", ex);
120: }
121: }
122:
123: public void testRefreshEntries() {
124: try {
125: PlanetManager planet = RollerFactory.getRoller()
126: .getPlanetManager();
127:
128: // run sync task to fill aggregator with websites created by super
129: SyncWebsitesTask syncTask = new SyncWebsitesTask();
130: syncTask.init();
131: syncTask.run();
132:
133: RefreshEntriesTask refreshTask = new RefreshEntriesTask();
134: refreshTask.init();
135: refreshTask.run();
136:
137: List agg = planet.getAggregation(null, null, 0, -1);
138: assertEquals(3, agg.size());
139: } catch (Exception e) {
140: e.printStackTrace();
141: fail();
142: }
143: }
144:
145: public static Test suite() {
146: return new TestSuite(PlanetManagerLocalTest.class);
147: }
148:
149: }
|