KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
19  * WeblogPageTest.java
20  *
21  * Created on April 7, 2006, 2:57 PM
22  */

23
24 package org.apache.roller.business;
25
26 import java.util.List JavaDoc;
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.roller.TestUtils;
33 import org.apache.roller.model.RollerFactory;
34 import org.apache.roller.model.UserManager;
35 import org.apache.roller.pojos.UserData;
36 import org.apache.roller.pojos.WeblogTemplate;
37 import org.apache.roller.pojos.WebsiteData;
38
39
40 /**
41  * Test Weblog Page related business operations.
42  */

43 public class WeblogPageTest extends TestCase {
44     
45     public static Log log = LogFactory.getLog(WeblogPageTest.class);
46     
47     UserData testUser = null;
48     WebsiteData testWeblog = null;
49     WeblogTemplate testPage = null;
50     
51     
52     public WeblogPageTest(String JavaDoc name) {
53         super(name);
54     }
55     
56     
57     public static Test suite() {
58         return new TestSuite(WeblogPageTest.class);
59     }
60     
61     
62     /**
63      * All tests in this suite require a user and a weblog.
64      */

65     public void setUp() throws Exception JavaDoc {
66         
67         try {
68             testUser = TestUtils.setupUser("wtTestUser");
69             testWeblog = TestUtils.setupWeblog("wtTestWeblog", testUser);
70             TestUtils.endSession(true);
71         } catch (Exception JavaDoc ex) {
72             log.error(ex);
73             throw new Exception JavaDoc("Test setup failed", ex);
74         }
75         
76         testPage = new WeblogTemplate();
77         testPage.setName("testTemplate");
78         testPage.setDescription("Test Weblog Template");
79         testPage.setLink("testTemp");
80         testPage.setContents("a test weblog template.");
81         testPage.setLastModified(new java.util.Date JavaDoc());
82         testPage.setWebsite(testWeblog);
83         testPage.setTemplateLanguage("velocity");
84     }
85     
86     public void tearDown() throws Exception JavaDoc {
87         
88         try {
89             TestUtils.teardownWeblog(testWeblog.getId());
90             TestUtils.teardownUser(testUser.getId());
91             TestUtils.endSession(true);
92         } catch (Exception JavaDoc ex) {
93             log.error(ex);
94             throw new Exception JavaDoc("Test teardown failed", ex);
95         }
96         
97         testPage = null;
98     }
99     
100     
101     /**
102      * Test basic persistence operations ... Create, Update, Delete
103      */

104     public void testTemplateCRUD() throws Exception JavaDoc {
105         
106         UserManager mgr = RollerFactory.getRoller().getUserManager();
107         WeblogTemplate template = null;
108         
109         // create template
110
mgr.savePage(testPage);
111         TestUtils.endSession(true);
112         
113         // check that create was successful
114
template = null;
115         template = mgr.getPageByName(testWeblog, testPage.getName());
116         assertNotNull(template);
117         assertEquals(testPage.getContents(), template.getContents());
118         
119         // update template
120
template.setName("testtesttest");
121         mgr.savePage(template);
122         TestUtils.endSession(true);
123         
124         // check that update was successful
125
template = null;
126         template = mgr.getPageByName(testWeblog, "testtesttest");
127         assertNotNull(template);
128         assertEquals(testPage.getContents(), template.getContents());
129         
130         // delete template
131
mgr.removePage(template);
132         TestUtils.endSession(true);
133         
134         // check that delete was successful
135
template = null;
136         template = mgr.getPageByName(testWeblog, testPage.getName());
137         assertNull(template);
138     }
139     
140     
141     /**
142      * Test lookup mechanisms ... id, name, link, weblog
143      */

144     public void testPermissionsLookups() throws Exception JavaDoc {
145         
146         UserManager mgr = RollerFactory.getRoller().getUserManager();
147         WeblogTemplate page = null;
148         
149         // create page
150
mgr.savePage(testPage);
151         String JavaDoc id = testPage.getId();
152         TestUtils.endSession(true);
153         
154         // lookup by id
155
page = mgr.getPage(id);
156         assertNotNull(page);
157         assertEquals(testPage.getContents(), page.getContents());
158         
159         // lookup by name
160
page = null;
161         page = mgr.getPageByName(testWeblog, testPage.getName());
162         assertNotNull(page);
163         assertEquals(testPage.getContents(), page.getContents());
164         
165         // lookup by link
166
page = null;
167         page = mgr.getPageByLink(testWeblog, testPage.getLink());
168         assertNotNull(page);
169         assertEquals(testPage.getContents(), page.getContents());
170         
171         // lookup all pages for weblog
172
List JavaDoc pages = mgr.getPages(testWeblog);
173         assertNotNull(pages);
174         assertEquals(1, pages.size());
175         
176         // delete page
177
mgr.removePage(page);
178         TestUtils.endSession(true);
179     }
180     
181 }
182
Popular Tags