1 18 23 24 package org.apache.roller; 25 26 import org.apache.roller.model.AutoPingManager; 27 import org.apache.roller.model.PingTargetManager; 28 import org.apache.roller.model.RollerFactory; 29 import org.apache.roller.model.UserManager; 30 import org.apache.roller.model.WeblogManager; 31 import org.apache.roller.pojos.AutoPingData; 32 import org.apache.roller.pojos.CommentData; 33 import org.apache.roller.pojos.PingTargetData; 34 import org.apache.roller.pojos.UserData; 35 import org.apache.roller.pojos.WeblogCategoryData; 36 import org.apache.roller.pojos.WeblogEntryData; 37 import org.apache.roller.pojos.WebsiteData; 38 39 40 43 public final class TestUtils { 44 45 46 54 public static void endSession(boolean flush) throws Exception { 55 56 if(flush) { 57 RollerFactory.getRoller().flush(); 58 } 59 60 RollerFactory.getRoller().release(); 61 } 62 63 64 67 public static UserData setupUser(String username) throws Exception { 68 69 UserData testUser = new UserData(); 70 testUser.setUserName(username); 71 testUser.setPassword("password"); 72 testUser.setFullName("Test User"); 73 testUser.setEmailAddress("TestUser@dev.null"); 74 testUser.setLocale("en_US"); 75 testUser.setTimeZone("America/Los_Angeles"); 76 testUser.setDateCreated(new java.util.Date ()); 77 testUser.setEnabled(Boolean.TRUE); 78 79 UserManager mgr = RollerFactory.getRoller().getUserManager(); 81 mgr.addUser(testUser); 82 83 UserData user = mgr.getUserByUserName(username); 85 86 if(user == null) 87 throw new RollerException("error inserting new user"); 88 89 return user; 90 } 91 92 93 96 public static void teardownUser(String id) throws Exception { 97 98 UserManager mgr = RollerFactory.getRoller().getUserManager(); 100 UserData user = mgr.getUser(id); 101 102 mgr.removeUser(user); 104 } 105 106 107 110 public static WebsiteData setupWeblog(String handle, UserData creator) throws Exception { 111 112 WebsiteData testWeblog = new WebsiteData(); 113 testWeblog.setName("Test Weblog"); 114 testWeblog.setDescription("Test Weblog"); 115 testWeblog.setHandle(handle); 116 testWeblog.setEmailAddress("testweblog@dev.null"); 117 testWeblog.setEditorPage("editor-text.jsp"); 118 testWeblog.setBlacklist(""); 119 testWeblog.setEmailFromAddress(""); 120 testWeblog.setEditorTheme("basic"); 121 testWeblog.setLocale("en_US"); 122 testWeblog.setTimeZone("America/Los_Angeles"); 123 testWeblog.setDateCreated(new java.util.Date ()); 124 testWeblog.setCreator(creator); 125 126 UserManager mgr = RollerFactory.getRoller().getUserManager(); 128 mgr.addWebsite(testWeblog); 129 130 WebsiteData weblog = mgr.getWebsiteByHandle(handle); 132 133 if(weblog == null) 134 throw new RollerException("error setting up weblog"); 135 136 return weblog; 137 } 138 139 140 143 public static void teardownWeblog(String id) throws Exception { 144 145 UserManager mgr = RollerFactory.getRoller().getUserManager(); 147 WebsiteData weblog = mgr.getWebsite(id); 148 149 mgr.removeWebsite(weblog); 151 } 152 153 154 157 public static WeblogEntryData setupWeblogEntry(String anchor, 158 WeblogCategoryData cat, 159 WebsiteData weblog, 160 UserData user) 161 throws Exception { 162 163 WeblogEntryData testEntry = new WeblogEntryData(); 164 testEntry.setTitle(anchor); 165 testEntry.setLink("testEntryLink"); 166 testEntry.setText("blah blah entry"); 167 testEntry.setAnchor(anchor); 168 testEntry.setPubTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 169 testEntry.setUpdateTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 170 testEntry.setStatus(WeblogEntryData.PUBLISHED); 171 testEntry.setWebsite(weblog); 172 testEntry.setCreator(user); 173 testEntry.setCategory(cat); 174 175 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 177 mgr.saveWeblogEntry(testEntry); 178 179 WeblogEntryData entry = mgr.getWeblogEntry(testEntry.getId()); 181 182 if(entry == null) 183 throw new RollerException("error setting up weblog entry"); 184 185 return entry; 186 } 187 188 189 192 public static void teardownWeblogEntry(String id) throws Exception { 193 194 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 196 WeblogEntryData entry = mgr.getWeblogEntry(id); 197 198 mgr.removeWeblogEntry(entry); 200 } 201 202 203 206 public static CommentData setupComment(String content, WeblogEntryData entry) 207 throws Exception { 208 209 CommentData testComment = new CommentData(); 210 testComment.setName("test"); 211 testComment.setEmail("test"); 212 testComment.setUrl("test"); 213 testComment.setRemoteHost("foofoo"); 214 testComment.setContent("this is a test comment"); 215 testComment.setPostTime(new java.sql.Timestamp (new java.util.Date ().getTime())); 216 testComment.setWeblogEntry(entry); 217 testComment.setPending(Boolean.FALSE); 218 testComment.setApproved(Boolean.TRUE); 219 220 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 222 mgr.saveComment(testComment); 223 224 CommentData comment = mgr.getComment(testComment.getId()); 226 227 if(comment == null) 228 throw new RollerException("error setting up comment"); 229 230 return comment; 231 } 232 233 234 237 public static void teardownComment(String id) throws Exception { 238 239 WeblogManager mgr = RollerFactory.getRoller().getWeblogManager(); 241 CommentData comment = mgr.getComment(id); 242 243 mgr.removeComment(comment); 245 } 246 247 248 251 public static PingTargetData setupPingTarget(String name, String url) 252 throws Exception { 253 254 PingTargetData testPing = new PingTargetData(); 255 testPing.setName("testCommonPing"); 256 testPing.setPingUrl("http://localhost/testCommonPing"); 257 258 PingTargetManager pingMgr = RollerFactory.getRoller().getPingTargetManager(); 260 pingMgr.savePingTarget(testPing); 261 262 PingTargetData ping = pingMgr.getPingTarget(testPing.getId()); 264 265 if(ping == null) 266 throw new RollerException("error setting up ping target"); 267 268 return ping; 269 } 270 271 272 275 public static void teardownPingTarget(String id) throws Exception { 276 277 PingTargetManager pingMgr = RollerFactory.getRoller().getPingTargetManager(); 279 PingTargetData ping = pingMgr.getPingTarget(id); 280 281 pingMgr.removePingTarget(ping); 283 } 284 285 286 289 public static AutoPingData setupAutoPing(PingTargetData ping, WebsiteData weblog) 290 throws Exception { 291 292 AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager(); 293 294 AutoPingData autoPing = new AutoPingData(null, ping, weblog); 296 mgr.saveAutoPing(autoPing); 297 298 autoPing = mgr.getAutoPing(autoPing.getId()); 300 301 if(autoPing == null) 302 throw new RollerException("error setting up auto ping"); 303 304 return autoPing; 305 } 306 307 308 311 public static void teardownAutoPing(String id) throws Exception { 312 313 AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager(); 315 AutoPingData autoPing = mgr.getAutoPing(id); 316 317 mgr.removeAutoPing(autoPing); 319 } 320 321 } 322 | Popular Tags |