KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > business > PlanetManagerLocalTest


1 /*
2  * Copyright 2005 Sun Microsystems, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.roller.business;
17
18 import java.sql.Timestamp JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.List JavaDoc;
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.roller.TestUtils;
28 import org.apache.roller.model.PlanetManager;
29 import org.apache.roller.model.RollerFactory;
30 import org.apache.roller.pojos.UserData;
31 import org.apache.roller.pojos.WeblogEntryData;
32 import org.apache.roller.pojos.WebsiteData;
33 import org.apache.roller.ui.core.tasks.RefreshEntriesTask;
34 import org.apache.roller.ui.core.tasks.SyncWebsitesTask;
35
36
37
38 /**
39  * Test database implementation of PlanetManager for local feeds.
40  * @author Dave Johnson
41  */

42 public class PlanetManagerLocalTest extends TestCase {
43     public static Log log = LogFactory.getLog(PlanetManagerLocalTest.class);
44     
45     UserData testUser = null;
46     WebsiteData testWeblog = null;
47     
48     public static void main(String JavaDoc[] args) {
49         TestRunner.run(PlanetManagerLocalTest.class);
50     }
51     
52     /**
53      * All tests in this suite require a user and a weblog.
54      */

55     public void setUp() throws Exception JavaDoc {
56         
57         try {
58             testUser = TestUtils.setupUser("entryTestUser");
59             testWeblog = TestUtils.setupWeblog("entryTestWeblog", testUser);
60             
61             WeblogEntryData testEntry1 = new WeblogEntryData();
62             testEntry1.setTitle("entryTestEntry1");
63             testEntry1.setLink("testEntryLink1");
64             testEntry1.setText("blah blah entry1");
65             testEntry1.setAnchor("testEntryAnchor1");
66             testEntry1.setPubTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
67             testEntry1.setUpdateTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
68             testEntry1.setWebsite(testWeblog);
69             testEntry1.setCreator(testUser);
70             testEntry1.setCategory(testWeblog.getDefaultCategory());
71             RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
72
73             WeblogEntryData testEntry2 = new WeblogEntryData();
74             testEntry2.setTitle("entryTestEntry2");
75             testEntry2.setLink("testEntryLink2");
76             testEntry2.setText("blah blah entry2");
77             testEntry2.setAnchor("testEntryAnchor2");
78             testEntry2.setPubTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
79             testEntry2.setUpdateTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
80             testEntry2.setWebsite(testWeblog);
81             testEntry2.setCreator(testUser);
82             testEntry2.setCategory(testWeblog.getDefaultCategory());
83             RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
84
85             WeblogEntryData testEntry3 = new WeblogEntryData();
86             testEntry3.setTitle("entryTestEntry3");
87             testEntry3.setLink("testEntryLink3");
88             testEntry3.setText("blah blah entry3");
89             testEntry3.setAnchor("testEntryAnchor3");
90             testEntry3.setPubTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
91             testEntry3.setUpdateTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
92             testEntry3.setWebsite(testWeblog);
93             testEntry3.setCreator(testUser);
94             testEntry3.setCategory(testWeblog.getDefaultCategory());
95             RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
96
97             TestUtils.endSession(true);
98             
99         } catch (Exception JavaDoc ex) {
100             log.error(ex);
101             throw new Exception JavaDoc("Test setup failed", ex);
102         }
103     }
104     
105     public void tearDown() throws Exception JavaDoc {
106         
107         try {
108             TestUtils.teardownWeblog(testWeblog.getId());
109             TestUtils.teardownUser(testUser.getId());
110             TestUtils.endSession(true);
111         } catch (Exception JavaDoc ex) {
112             log.error(ex);
113             throw new Exception JavaDoc("Test teardown failed", ex);
114         }
115     }
116     
117     public void testRefreshEntries() {
118         try {
119             PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
120             
121             // run sync task to fill aggregator with websites created by super
122
SyncWebsitesTask syncTask = new SyncWebsitesTask();
123             syncTask.init(RollerFactory.getRoller(), "dummy");
124             syncTask.run();
125             
126             RefreshEntriesTask refreshTask = new RefreshEntriesTask();
127             refreshTask.init(RollerFactory.getRoller(), "dummy");
128             refreshTask.run();
129             
130             List JavaDoc agg = planet.getAggregation(null, null, 0, -1);
131             assertEquals(3, agg.size());
132         }
133         catch (Exception JavaDoc e) {
134             e.printStackTrace();
135             fail();
136         }
137     }
138     
139     public static Test suite() {
140         return new TestSuite(PlanetManagerLocalTest.class);
141     }
142     
143     
144 }
145
146
Popular Tags