1 18 23 24 package org.apache.roller.business; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 import org.apache.roller.TestUtils; 34 import org.apache.roller.model.AutoPingManager; 35 import org.apache.roller.model.PingTargetManager; 36 import org.apache.roller.model.RollerFactory; 37 import org.apache.roller.pojos.AutoPingData; 38 import org.apache.roller.pojos.PingTargetData; 39 import org.apache.roller.pojos.UserData; 40 import org.apache.roller.pojos.WebsiteData; 41 42 43 46 public class PingsTest extends TestCase { 47 48 public static Log log = LogFactory.getLog(PingsTest.class); 49 50 UserData testUser = null; 51 WebsiteData testWeblog = null; 52 PingTargetData testCommonPing = null; 53 PingTargetData testCustomPing = null; 54 55 56 public PingsTest(String name) { 57 super(name); 58 } 59 60 61 public static Test suite() { 62 return new TestSuite(PingsTest.class); 63 } 64 65 66 69 public void setUp() throws Exception { 70 71 try { 72 testUser = TestUtils.setupUser("wtTestUser"); 73 testWeblog = TestUtils.setupWeblog("wtTestWeblog", testUser); 74 TestUtils.endSession(true); 75 } catch (Exception ex) { 76 log.error(ex); 77 throw new Exception ("Test setup failed", ex); 78 } 79 80 testCommonPing = new PingTargetData(); 81 testCommonPing.setName("testCommonPing"); 82 testCommonPing.setPingUrl("http://localhost/testCommonPing"); 83 84 testCustomPing = new PingTargetData(); 85 testCustomPing.setName("testCommonPing"); 86 testCustomPing.setPingUrl("http://localhost/testCommonPing"); 87 } 88 89 public void tearDown() throws Exception { 90 91 try { 92 TestUtils.teardownWeblog(testWeblog.getId()); 93 TestUtils.teardownUser(testUser.getId()); 94 TestUtils.endSession(true); 95 } catch (Exception ex) { 96 log.error(ex); 97 throw new Exception ("Test teardown failed", ex); 98 } 99 100 testCommonPing = null; 101 testCustomPing = null; 102 } 103 104 105 108 public void testPingTargetCRUD() throws Exception { 109 110 PingTargetManager mgr = RollerFactory.getRoller().getPingTargetManager(); 111 PingTargetData ping = null; 112 113 mgr.savePingTarget(testCommonPing); 115 String commonId = testCommonPing.getId(); 116 TestUtils.endSession(true); 117 118 ping = null; 120 ping = mgr.getPingTarget(commonId); 121 assertNotNull(ping); 122 assertEquals(testCommonPing.getPingUrl(), ping.getPingUrl()); 123 124 testCustomPing.setWebsite(testWeblog); 126 mgr.savePingTarget(testCustomPing); 127 String customId = testCustomPing.getId(); 128 TestUtils.endSession(true); 129 130 ping = null; 132 ping = mgr.getPingTarget(customId); 133 assertNotNull(ping); 134 assertEquals(testCustomPing.getPingUrl(), ping.getPingUrl()); 135 136 ping = null; 138 ping = mgr.getPingTarget(commonId); 139 ping.setName("testtestCommon"); 140 mgr.savePingTarget(ping); 141 TestUtils.endSession(true); 142 143 ping = null; 145 ping = mgr.getPingTarget(commonId); 146 assertNotNull(ping); 147 assertEquals("testtestCommon", ping.getName()); 148 149 ping = null; 151 ping = mgr.getPingTarget(customId); 152 ping.setName("testtestCustom"); 153 mgr.savePingTarget(ping); 154 TestUtils.endSession(true); 155 156 ping = null; 158 ping = mgr.getPingTarget(customId); 159 assertNotNull(ping); 160 assertEquals("testtestCustom", ping.getName()); 161 162 ping = null; 164 ping = mgr.getPingTarget(commonId); 165 mgr.removePingTarget(ping); 166 TestUtils.endSession(true); 167 168 ping = null; 170 ping = mgr.getPingTarget(commonId); 171 assertNull(ping); 172 173 ping = null; 175 ping = mgr.getPingTarget(customId); 176 mgr.removePingTarget(ping); 177 TestUtils.endSession(true); 178 179 ping = null; 181 ping = mgr.getPingTarget(customId); 182 assertNull(ping); 183 } 184 185 186 189 public void testPingTargetLookups() throws Exception { 190 191 PingTargetManager mgr = RollerFactory.getRoller().getPingTargetManager(); 192 PingTargetData ping = null; 193 194 mgr.savePingTarget(testCommonPing); 196 String commonId = testCommonPing.getId(); 197 TestUtils.endSession(true); 198 199 testCustomPing.setWebsite(testWeblog); 201 mgr.savePingTarget(testCustomPing); 202 String customId = testCustomPing.getId(); 203 TestUtils.endSession(true); 204 205 ping = null; 207 ping = mgr.getPingTarget(commonId); 208 assertNotNull(ping); 209 assertEquals(testCommonPing.getName(), ping.getName()); 210 211 List commonPings = mgr.getCommonPingTargets(); 213 assertNotNull(commonPings); 214 assertEquals(1, commonPings.size()); 215 216 List customPings = mgr.getCustomPingTargets(testWeblog); 218 assertNotNull(customPings); 219 assertEquals(1, customPings.size()); 220 221 ping = null; 223 ping = mgr.getPingTarget(commonId); 224 mgr.removePingTarget(ping); 225 TestUtils.endSession(true); 226 227 ping = null; 229 ping = mgr.getPingTarget(customId); 230 mgr.removePingTarget(ping); 231 TestUtils.endSession(true); 232 } 233 234 235 238 public void testAutoPingCRUD() throws Exception { 239 240 AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager(); 241 AutoPingData autoPing = null; 242 243 PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null"); 245 PingTargetData pingTarget2 = TestUtils.setupPingTarget("blahPing", "http://blah/null"); 246 TestUtils.endSession(true); 247 248 autoPing = new AutoPingData(null, pingTarget, testWeblog); 250 mgr.saveAutoPing(autoPing); 251 String id = autoPing.getId(); 252 TestUtils.endSession(true); 253 254 autoPing = null; 256 autoPing = mgr.getAutoPing(id); 257 assertNotNull(autoPing); 258 assertEquals(pingTarget, autoPing.getPingTarget()); 259 260 autoPing.setPingTarget(pingTarget2); 262 mgr.saveAutoPing(autoPing); 263 TestUtils.endSession(true); 264 265 autoPing = null; 267 autoPing = mgr.getAutoPing(id); 268 assertNotNull(autoPing); 269 assertEquals(pingTarget2, autoPing.getPingTarget()); 270 271 mgr.removeAutoPing(autoPing); 273 TestUtils.endSession(true); 274 275 autoPing = null; 277 autoPing = mgr.getAutoPing(id); 278 assertNull(autoPing); 279 280 TestUtils.teardownPingTarget(pingTarget.getId()); 282 TestUtils.teardownPingTarget(pingTarget2.getId()); 283 TestUtils.endSession(true); 284 } 285 286 287 290 public void testPingTargetRemovals() throws Exception { 291 292 AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager(); 293 AutoPingData testAutoPing = null; 294 295 PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null"); 297 PingTargetData pingTarget2 = TestUtils.setupPingTarget("blahPing", "http://blah/null"); 298 PingTargetData pingTarget3 = TestUtils.setupPingTarget("gahPing", "http://gah/null"); 299 300 AutoPingData autoPing = TestUtils.setupAutoPing(pingTarget, testWeblog); 302 AutoPingData autoPing2 = TestUtils.setupAutoPing(pingTarget2, testWeblog); 303 AutoPingData autoPing3 = TestUtils.setupAutoPing(pingTarget3, testWeblog); 304 TestUtils.endSession(true); 305 306 mgr.removeAutoPing(pingTarget, testWeblog); 308 TestUtils.endSession(true); 309 310 testAutoPing = null; 312 testAutoPing = mgr.getAutoPing(autoPing.getId()); 313 assertNull(testAutoPing); 314 315 List autoPings = new ArrayList (); 317 autoPings.add(autoPing2); 318 autoPings.add(autoPing3); 319 mgr.removeAutoPings(autoPings); 320 TestUtils.endSession(true); 321 322 autoPings = mgr.getAutoPingsByWebsite(testWeblog); 324 assertNotNull(autoPings); 325 assertEquals(0, autoPings.size()); 326 327 autoPing = TestUtils.setupAutoPing(pingTarget, testWeblog); 329 autoPing2 = TestUtils.setupAutoPing(pingTarget2, testWeblog); 330 autoPing3 = TestUtils.setupAutoPing(pingTarget3, testWeblog); 331 TestUtils.endSession(true); 332 333 mgr.removeAllAutoPings(); 335 TestUtils.endSession(true); 336 337 autoPings = mgr.getAutoPingsByWebsite(testWeblog); 339 assertNotNull(autoPings); 340 assertEquals(0, autoPings.size()); 341 342 TestUtils.teardownPingTarget(pingTarget.getId()); 344 TestUtils.teardownPingTarget(pingTarget2.getId()); 345 TestUtils.endSession(true); 346 } 347 348 349 352 public void testAutoPingLookups() throws Exception { 353 354 AutoPingManager mgr = RollerFactory.getRoller().getAutopingManager(); 355 AutoPingData autoPing = null; 356 357 PingTargetData pingTarget = TestUtils.setupPingTarget("fooPing", "http://foo/null"); 359 TestUtils.endSession(true); 360 361 autoPing = new AutoPingData(null, pingTarget, testWeblog); 363 mgr.saveAutoPing(autoPing); 364 String id = autoPing.getId(); 365 TestUtils.endSession(true); 366 367 autoPing = null; 369 autoPing = mgr.getAutoPing(id); 370 assertNotNull(autoPing); 371 assertEquals(pingTarget, autoPing.getPingTarget()); 372 373 List autoPings = mgr.getAutoPingsByTarget(pingTarget); 375 assertNotNull(autoPings); 376 assertEquals(1, autoPings.size()); 377 378 autoPings = null; 380 autoPings = mgr.getAutoPingsByWebsite(testWeblog); 381 assertNotNull(autoPing); 382 assertEquals(1, autoPings.size()); 383 384 mgr.removeAutoPing(autoPing); 386 TestUtils.endSession(true); 387 388 TestUtils.teardownPingTarget(pingTarget.getId()); 390 TestUtils.endSession(true); 391 } 392 393 394 public void testApplicableAutoPings() throws Exception { 395 396 } 397 398 399 403 public void testRemoveLoadedPingTarget() throws Exception { 404 } 406 407 } 408 | Popular Tags |