KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.business;
19
20 import java.util.List JavaDoc;
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.roller.TestUtils;
27 import org.apache.roller.model.RollerFactory;
28 import org.apache.roller.model.UserManager;
29 import org.apache.roller.pojos.CommentData;
30 import org.apache.roller.pojos.StatCount;
31 import org.apache.roller.pojos.UserData;
32 import org.apache.roller.pojos.WeblogEntryData;
33 import org.apache.roller.pojos.WebsiteData;
34
35
36 /**
37  * Test Weblog related business operations.
38  */

39 public class WeblogTest extends TestCase {
40     
41     public static Log log = LogFactory.getLog(WeblogTest.class);
42     
43     UserData testUser = null;
44     
45     
46     public WeblogTest(String JavaDoc name) {
47         super(name);
48     }
49     
50     
51     public static Test suite() {
52         return new TestSuite(WeblogTest.class);
53     }
54     
55     
56     /**
57      * All tests in this suite require a user.
58      */

59     public void setUp() throws Exception JavaDoc {
60         
61         try {
62             testUser = TestUtils.setupUser("weblogTestUser");
63             TestUtils.endSession(true);
64         } catch (Exception JavaDoc ex) {
65             log.error(ex);
66             throw new Exception JavaDoc("Test setup failed", ex);
67         }
68     }
69     
70     public void tearDown() throws Exception JavaDoc {
71         
72         try {
73             TestUtils.teardownUser(testUser.getId());
74             TestUtils.endSession(true);
75         } catch (Exception JavaDoc ex) {
76             log.error(ex);
77             throw new Exception JavaDoc("Test teardown failed", ex);
78         }
79     }
80     
81     
82     /**
83      * Test basic persistence operations ... Create, Update, Delete.
84      */

85     public void testWeblogCRUD() throws Exception JavaDoc {
86         
87         UserManager mgr = RollerFactory.getRoller().getUserManager();
88         WebsiteData weblog = null;
89         
90         WebsiteData testWeblog = new WebsiteData();
91         testWeblog.setName("Test Weblog");
92         testWeblog.setDescription("Test Weblog");
93         testWeblog.setHandle("testweblog");
94         testWeblog.setEmailAddress("testweblog@dev.null");
95         testWeblog.setEditorPage("editor-text.jsp");
96         testWeblog.setBlacklist("");
97         testWeblog.setEmailFromAddress("");
98         testWeblog.setEditorTheme("basic");
99         testWeblog.setLocale("en_US");
100         testWeblog.setTimeZone("America/Los_Angeles");
101         testWeblog.setDateCreated(new java.util.Date JavaDoc());
102         testWeblog.setCreator(testUser);
103         
104         // make sure test weblog does not exist
105
weblog = mgr.getWebsiteByHandle(testWeblog.getHandle());
106         assertNull(weblog);
107         
108         // add test weblog
109
mgr.addWebsite(testWeblog);
110         String JavaDoc id = testWeblog.getId();
111         TestUtils.endSession(true);
112         
113         // make sure test weblog exists
114
weblog = null;
115         weblog = mgr.getWebsite(id);
116         assertNotNull(weblog);
117         assertEquals(testWeblog, weblog);
118         
119         // modify weblog and save
120
weblog.setName("testtesttest");
121         mgr.saveWebsite(weblog);
122         TestUtils.endSession(true);
123         
124         // make sure changes were saved
125
weblog = null;
126         weblog = mgr.getWebsite(id);
127         assertNotNull(weblog);
128         assertEquals("testtesttest", weblog.getName());
129         
130         // remove test weblog
131
mgr.removeWebsite(weblog);
132         TestUtils.endSession(true);
133         
134         // make sure weblog no longer exists
135
weblog = null;
136         weblog = mgr.getWebsite(id);
137         assertNull(weblog);
138     }
139     
140     
141     /**
142      * Test lookup mechanisms.
143      */

144     public void testWeblogLookups() throws Exception JavaDoc {
145         
146         UserManager mgr = RollerFactory.getRoller().getUserManager();
147         WebsiteData weblog = null;
148         
149         // add test weblogs
150
WebsiteData testWeblog1 = TestUtils.setupWeblog("testWeblog1", testUser);
151         WebsiteData testWeblog2 = TestUtils.setupWeblog("testWeblog2", testUser);
152         TestUtils.endSession(true);
153         
154         // lookup by id
155
weblog = mgr.getWebsite(testWeblog1.getId());
156         assertNotNull(weblog);
157         assertEquals(testWeblog1.getHandle(), weblog.getHandle());
158         
159         // lookup by weblog handle
160
weblog = null;
161         weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
162         assertNotNull(weblog);
163         assertEquals(testWeblog1.getHandle(), weblog.getHandle());
164         
165         // make sure disable weblogs are not returned
166
weblog.setEnabled(Boolean.FALSE);
167         mgr.saveWebsite(weblog);
168         weblog = null;
169         weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
170         assertNull(weblog);
171         
172         // restore enabled state
173
weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle(), Boolean.FALSE);
174         weblog.setEnabled(Boolean.TRUE);
175         mgr.saveWebsite(weblog);
176         TestUtils.endSession(true);
177         weblog = null;
178         weblog = mgr.getWebsiteByHandle(testWeblog1.getHandle());
179         assertNotNull(weblog);
180         
181         // get all weblogs for user
182
weblog = null;
183         List JavaDoc weblogs1 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
184         assertEquals(2, weblogs1.size());
185         weblog = (WebsiteData) weblogs1.get(0);
186         assertNotNull(weblog);
187         
188         // testing paging
189
List JavaDoc weblogs11 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, 1);
190         assertEquals(1, weblogs11.size());
191         List JavaDoc weblogs12 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 1, 1);
192         assertEquals(1, weblogs11.size());
193         
194         // make sure disabled weblogs are not returned
195
weblog.setEnabled(Boolean.FALSE);
196         mgr.saveWebsite(weblog);
197         TestUtils.endSession(true);
198         List JavaDoc weblogs2 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
199         assertEquals(1, weblogs2.size());
200         weblog = (WebsiteData) weblogs2.get(0);
201         assertNotNull(weblog);
202         
203         // make sure inactive weblogs are not returned
204
weblog.setActive(Boolean.FALSE);
205         mgr.saveWebsite(weblog);
206         TestUtils.endSession(true);
207         List JavaDoc weblogs3 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
208         assertEquals(0, weblogs3.size());
209         
210         // remove test weblogs
211
TestUtils.teardownWeblog(testWeblog1.getId());
212         TestUtils.teardownWeblog(testWeblog2.getId());
213         TestUtils.endSession(true);
214     }
215     
216     
217     /**
218      * Test that we can safely remove a fully loaded weblog.
219      * That means a weblog with entries, categories, bookmarks, pings, etc.
220      */

221     public void testRemoveLoadedWeblog() throws Exception JavaDoc {
222         // TODO: implement testRemoveLoadedWeblog
223
}
224 }
225
226
227
Popular Tags