1 18 23 24 package org.apache.roller.business; 25 26 import java.util.List ; 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 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 name) { 53 super(name); 54 } 55 56 57 public static Test suite() { 58 return new TestSuite(WeblogPageTest.class); 59 } 60 61 62 65 public void setUp() throws Exception { 66 67 try { 68 testUser = TestUtils.setupUser("wtTestUser"); 69 testWeblog = TestUtils.setupWeblog("wtTestWeblog", testUser); 70 TestUtils.endSession(true); 71 } catch (Exception ex) { 72 log.error(ex); 73 throw new Exception ("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 ()); 82 testPage.setWebsite(testWeblog); 83 testPage.setTemplateLanguage("velocity"); 84 } 85 86 public void tearDown() throws Exception { 87 88 try { 89 TestUtils.teardownWeblog(testWeblog.getId()); 90 TestUtils.teardownUser(testUser.getId()); 91 TestUtils.endSession(true); 92 } catch (Exception ex) { 93 log.error(ex); 94 throw new Exception ("Test teardown failed", ex); 95 } 96 97 testPage = null; 98 } 99 100 101 104 public void testTemplateCRUD() throws Exception { 105 106 UserManager mgr = RollerFactory.getRoller().getUserManager(); 107 WeblogTemplate template = null; 108 109 mgr.savePage(testPage); 111 TestUtils.endSession(true); 112 113 template = null; 115 template = mgr.getPageByName(testWeblog, testPage.getName()); 116 assertNotNull(template); 117 assertEquals(testPage.getContents(), template.getContents()); 118 119 template.setName("testtesttest"); 121 mgr.savePage(template); 122 TestUtils.endSession(true); 123 124 template = null; 126 template = mgr.getPageByName(testWeblog, "testtesttest"); 127 assertNotNull(template); 128 assertEquals(testPage.getContents(), template.getContents()); 129 130 mgr.removePage(template); 132 TestUtils.endSession(true); 133 134 template = null; 136 template = mgr.getPageByName(testWeblog, testPage.getName()); 137 assertNull(template); 138 } 139 140 141 144 public void testPermissionsLookups() throws Exception { 145 146 UserManager mgr = RollerFactory.getRoller().getUserManager(); 147 WeblogTemplate page = null; 148 149 mgr.savePage(testPage); 151 String id = testPage.getId(); 152 TestUtils.endSession(true); 153 154 page = mgr.getPage(id); 156 assertNotNull(page); 157 assertEquals(testPage.getContents(), page.getContents()); 158 159 page = null; 161 page = mgr.getPageByName(testWeblog, testPage.getName()); 162 assertNotNull(page); 163 assertEquals(testPage.getContents(), page.getContents()); 164 165 page = null; 167 page = mgr.getPageByLink(testWeblog, testPage.getLink()); 168 assertNotNull(page); 169 assertEquals(testPage.getContents(), page.getContents()); 170 171 List pages = mgr.getPages(testWeblog); 173 assertNotNull(pages); 174 assertEquals(1, pages.size()); 175 176 mgr.removePage(page); 178 TestUtils.endSession(true); 179 } 180 181 } 182 | Popular Tags |