001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * 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. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * WeblogPageTest.java
020: *
021: * Created on April 7, 2006, 2:57 PM
022: */
023:
024: package org.apache.roller.business;
025:
026: import java.util.List;
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.roller.TestUtils;
033: import org.apache.roller.business.RollerFactory;
034: import org.apache.roller.business.UserManager;
035: import org.apache.roller.pojos.UserData;
036: import org.apache.roller.pojos.WeblogTemplate;
037: import org.apache.roller.pojos.WebsiteData;
038:
039: /**
040: * Test Weblog Page related business operations.
041: */
042: public class WeblogPageTest extends TestCase {
043:
044: public static Log log = LogFactory.getLog(WeblogPageTest.class);
045:
046: UserData testUser = null;
047: WebsiteData testWeblog = null;
048: WeblogTemplate testPage = null;
049:
050: public WeblogPageTest(String name) {
051: super (name);
052: }
053:
054: public static Test suite() {
055: return new TestSuite(WeblogPageTest.class);
056: }
057:
058: /**
059: * All tests in this suite require a user and a weblog.
060: */
061: public void setUp() throws Exception {
062:
063: try {
064: testUser = TestUtils.setupUser("wtTestUser");
065: testWeblog = TestUtils
066: .setupWeblog("wtTestWeblog", testUser);
067: TestUtils.endSession(true);
068: } catch (Exception ex) {
069: log.error(ex);
070: throw new Exception("Test setup failed", ex);
071: }
072:
073: testPage = new WeblogTemplate();
074: testPage.setName("testTemplate");
075: testPage.setDescription("Test Weblog Template");
076: testPage.setLink("testTemp");
077: testPage.setContents("a test weblog template.");
078: testPage.setLastModified(new java.util.Date());
079: testPage.setWebsite(testWeblog);
080: testPage.setTemplateLanguage("velocity");
081: }
082:
083: public void tearDown() throws Exception {
084:
085: try {
086: TestUtils.teardownWeblog(testWeblog.getId());
087: TestUtils.teardownUser(testUser.getId());
088: TestUtils.endSession(true);
089: } catch (Exception ex) {
090: log.error(ex);
091: throw new Exception("Test teardown failed", ex);
092: }
093:
094: testPage = null;
095: }
096:
097: /**
098: * Test basic persistence operations ... Create, Update, Delete
099: */
100: public void testTemplateCRUD() throws Exception {
101:
102: UserManager mgr = RollerFactory.getRoller().getUserManager();
103: WeblogTemplate template = null;
104:
105: // create template
106: mgr.savePage(testPage);
107: TestUtils.endSession(true);
108:
109: // check that create was successful
110: template = null;
111: template = mgr.getPageByName(testWeblog, testPage.getName());
112: assertNotNull(template);
113: assertEquals(testPage.getContents(), template.getContents());
114:
115: // update template
116: template.setName("testtesttest");
117: mgr.savePage(template);
118: TestUtils.endSession(true);
119:
120: // check that update was successful
121: template = null;
122: template = mgr.getPageByName(testWeblog, "testtesttest");
123: assertNotNull(template);
124: assertEquals(testPage.getContents(), template.getContents());
125:
126: // delete template
127: mgr.removePage(template);
128: TestUtils.endSession(true);
129:
130: // check that delete was successful
131: template = null;
132: template = mgr.getPageByName(testWeblog, testPage.getName());
133: assertNull(template);
134: }
135:
136: /**
137: * Test lookup mechanisms ... id, name, link, weblog
138: */
139: public void testPermissionsLookups() throws Exception {
140:
141: UserManager mgr = RollerFactory.getRoller().getUserManager();
142: WeblogTemplate page = null;
143:
144: // create page
145: mgr.savePage(testPage);
146: String id = testPage.getId();
147: TestUtils.endSession(true);
148:
149: // lookup by id
150: page = mgr.getPage(id);
151: assertNotNull(page);
152: assertEquals(testPage.getContents(), page.getContents());
153:
154: // lookup by name
155: page = null;
156: page = mgr.getPageByName(testWeblog, testPage.getName());
157: assertNotNull(page);
158: assertEquals(testPage.getContents(), page.getContents());
159:
160: // lookup by link
161: page = null;
162: page = mgr.getPageByLink(testWeblog, testPage.getLink());
163: assertNotNull(page);
164: assertEquals(testPage.getContents(), page.getContents());
165:
166: // lookup all pages for weblog
167: List pages = mgr.getPages(testWeblog);
168: assertNotNull(pages);
169: assertEquals(1, pages.size());
170:
171: // delete page
172: mgr.removePage(page);
173: TestUtils.endSession(true);
174: }
175:
176: }
|