1 16 package org.roller.business; 17 18 import java.util.ArrayList ; 19 import java.util.Date ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Set ; 23 24 import junit.framework.Test; 25 import junit.framework.TestCase; 26 import junit.framework.TestSuite; 27 28 import org.roller.RollerException; 29 import org.roller.model.PlanetManager; 30 import org.roller.model.Roller; 31 import org.roller.model.RollerFactory; 32 import org.roller.pojos.PlanetConfigData; 33 import org.roller.pojos.PlanetEntryData; 34 import org.roller.pojos.PlanetGroupData; 35 import org.roller.pojos.PlanetSubscriptionData; 36 import org.roller.pojos.UserData; 37 38 42 public class PlanetManagerTest extends TestCase 43 { 44 private Roller roller = null; 45 46 public static void main(String [] args) 47 { 48 junit.textui.TestRunner.run(PlanetManagerTest.class); 49 } 50 51 public void testConfigurationStorage() throws Exception 52 { 53 Roller roller = getRoller(); 54 assertNotNull(roller); 55 PlanetManager planet = roller.getPlanetManager(); 56 assertNotNull(planet); 57 58 { roller.begin(); 60 61 PlanetConfigData config = new PlanetConfigData(); 62 config.setCacheDir("test_cache_dir"); 63 config.setTitle("test_title"); 64 config.setAdminEmail("test_admin_email"); 65 66 PlanetGroupData group = new PlanetGroupData(); 67 group.setDescription("test_group_desc"); 68 group.setHandle("test_handle"); 69 group.setTitle("test_title"); 70 planet.saveGroup(group); 71 72 config.setDefaultGroup(group); 73 planet.saveConfiguration(config); 74 75 roller.commit(); 76 } 77 { roller.begin(); 79 PlanetConfigData config = planet.getConfiguration(); 80 assertEquals("test_cache_dir",config.getCacheDir()); 81 assertEquals("test_title", config.getTitle()); 82 assertEquals("test_admin_email", config.getAdminEmail()); 83 84 PlanetGroupData group = config.getDefaultGroup(); 85 assertEquals("test_group_desc",group.getDescription()); 86 assertEquals("test_title",group.getTitle()); 87 88 roller.rollback(); 89 } 90 { roller.begin(); 92 PlanetConfigData config = planet.getConfiguration(); 93 config.remove(); 94 roller.commit(); 95 } 96 { 97 roller.begin(); 99 PlanetConfigData config = planet.getConfiguration(); 100 assertNull(config); 101 PlanetGroupData group = planet.getGroup("test_handle"); 102 assertNull(group); 103 roller.rollback(); 104 } 105 } 106 107 public void testGroupStorage() throws Exception 108 { 109 Roller roller = getRoller(); 110 assertNotNull(roller); 111 PlanetManager planet = roller.getPlanetManager(); 112 assertNotNull(planet); 113 114 { roller.begin(UserData.SYSTEM_USER); 116 PlanetGroupData group = new PlanetGroupData(); 117 group.setDescription("test_group_desc"); 118 group.setHandle("test_handle"); 119 group.setTitle("test_title"); 120 planet.saveGroup(group); 121 roller.commit(); 122 } 123 { roller.begin(); 125 PlanetGroupData group = planet.getGroup("test_handle"); 126 assertEquals("test_group_desc",group.getDescription()); 127 assertEquals("test_title",group.getTitle()); 128 assertEquals(1, planet.getGroupHandles().size()); 129 roller.rollback(); 130 } 131 { roller.begin(); 133 PlanetGroupData group = planet.getGroup("test_handle"); 134 planet.deleteGroup(group); 135 roller.commit(); 136 } 137 { roller.begin(); 139 PlanetGroupData group = planet.getGroup("test_handle"); 140 assertNull(group); 141 roller.rollback(); 142 } 143 } 144 145 public void testSubscriptionStorage() throws Exception 146 { 147 Roller roller = getRoller(); 148 assertNotNull(roller); 149 PlanetManager planet = roller.getPlanetManager(); 150 assertNotNull(planet); 151 152 { roller.begin(); 154 PlanetSubscriptionData sub = new PlanetSubscriptionData(); 155 sub.setFeedUrl("test_url"); 156 planet.saveSubscription(sub); 157 roller.commit(); 158 } 159 { roller.begin(); 161 162 PlanetGroupData group = new PlanetGroupData(); 163 group.setDescription("test_group_desc"); 164 group.setHandle("test_handle"); 165 group.setTitle("test_title"); 166 planet.saveGroup(group); 167 168 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 169 assertNotNull(sub); 170 group.addSubscription(sub); 171 172 PlanetSubscriptionData sub1 = new PlanetSubscriptionData(); 173 sub1.setFeedUrl("test_url1"); 174 planet.saveSubscription(sub1); 175 176 List subs = new ArrayList (); 177 subs.add(sub1); 178 group.addSubscriptions(subs); 179 180 planet.saveGroup(group); 181 182 roller.commit(); 183 } 184 { roller.begin(); 186 PlanetGroupData group = planet.getGroup("test_handle"); 187 Set subs = group.getSubscriptions(); 188 assertEquals(2, subs.size()); 189 planet.deleteGroup(group); 190 roller.commit(); 191 } 192 { roller.begin(); 194 PlanetGroupData group = planet.getGroup("test_handle"); 195 assertNull(group); 196 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 197 assertNotNull(sub); 198 PlanetSubscriptionData sub1 = planet.getSubscription("test_url1"); 199 assertNotNull(sub1); 200 planet.deleteSubscription(sub); 201 planet.deleteSubscription(sub1); 202 roller.commit(); 203 } 204 { roller.begin(); 206 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 207 assertNull(sub); 208 PlanetSubscriptionData sub1 = planet.getSubscription("test_url1"); 209 assertNull(sub1); 210 roller.rollback(); 211 } 212 } 213 public void testSubscriptionEntryStorage() throws Exception 214 { 215 Roller roller = getRoller(); 216 assertNotNull(roller); 217 PlanetManager planet = roller.getPlanetManager(); 218 assertNotNull(planet); 219 220 { roller.begin(); 222 PlanetSubscriptionData sub = new PlanetSubscriptionData(); 223 sub.setFeedUrl("test_url"); 224 planet.saveSubscription(sub); 225 roller.commit(); 226 } 227 { roller.begin(); 229 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 230 assertNotNull(sub); 231 232 PlanetEntryData entry1 = new PlanetEntryData(); 233 entry1.setPermalink("test_entry1"); 234 entry1.setCategoriesString("test,test2"); 235 entry1.setSubscription(sub); 236 entry1.setPublished(new Date ()); 237 entry1.save(); 238 sub.addEntry(entry1); 239 240 PlanetEntryData entry2 = new PlanetEntryData(); 241 entry2.setPermalink("test_entry2"); 242 entry2.setCategoriesString("test_cat1,test_cat2,test_cat3"); 243 entry2.setSubscription(sub); 244 entry2.setPublished(new Date ()); 245 entry2.save(); 246 sub.addEntry(entry2); 247 248 roller.commit(); 249 } 250 { roller.begin(); 252 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 253 assertEquals(2, sub.getEntries().size()); 254 planet.deleteSubscription(sub); 255 roller.commit(); 256 } 257 { roller.begin(); 259 PlanetSubscriptionData sub = planet.getSubscription("test_url"); 260 assertNull(sub); 261 roller.rollback(); 262 } 263 } 264 public void testRefreshEntries() 265 { 266 try 267 { 268 Roller roller = getRoller(); 269 assertNotNull(roller); 270 PlanetManager planet = roller.getPlanetManager(); 271 assertNotNull(planet); 272 String feed_url1 = "http://rollerweblogger.org/rss/roller"; 273 { 274 roller.begin(); 275 PlanetConfigData config = new PlanetConfigData(); 276 config.setCacheDir("/tmp"); config.setTitle("test_title"); 278 config.setAdminEmail("test_admin_email"); 279 planet.saveConfiguration(config); 280 281 PlanetGroupData group = new PlanetGroupData(); 282 group.setDescription("test_group_desc"); 283 group.setHandle("test_handle"); 284 group.setTitle("test_title"); 285 planet.saveGroup(group); 286 287 PlanetSubscriptionData sub = new PlanetSubscriptionData(); 288 sub.setFeedUrl(feed_url1); 289 planet.saveSubscription(sub); 290 291 group.addSubscription(sub); 292 planet.saveGroup(group); 293 294 roller.commit(); 295 } 296 { 297 roller.begin(); 298 planet.refreshEntries(); 299 roller.commit(); 300 301 roller.begin(); 302 PlanetSubscriptionData sub = planet.getSubscription(feed_url1); 303 assertTrue(sub.getEntries().size() > 0); 304 305 PlanetGroupData group = planet.getGroup("test_handle"); 306 assertNotNull(group); 307 308 planet.deleteSubscription(sub); 309 planet.deleteGroup(group); 310 311 PlanetConfigData config = planet.getConfiguration(); 312 config.remove(); 313 roller.commit(); 314 } 315 } 316 catch (Exception e) 317 { 318 e.printStackTrace(); 319 } 320 } 321 public void testAggregations() throws Exception 322 { 323 try 324 { 325 Roller roller = getRoller(); 326 assertNotNull(roller); 327 PlanetManager planet = roller.getPlanetManager(); 328 assertNotNull(planet); 329 String feed_url1 = "http://rollerweblogger.org/rss/roller"; 330 String feed_url2 = "http://linuxintegrators.com/acoliver/?flavor=rss2"; 331 { 332 roller.begin(); 333 PlanetConfigData config = new PlanetConfigData(); 334 config.setCacheDir("/tmp"); config.setTitle("test_title"); 336 config.setAdminEmail("test_admin_email"); 337 planet.saveConfiguration(config); 338 339 PlanetGroupData group = new PlanetGroupData(); 340 group.setDescription("test_group_desc"); 341 group.setHandle("test_handle"); 342 group.setTitle("test_title"); 343 planet.saveGroup(group); 344 345 PlanetSubscriptionData sub1 = new PlanetSubscriptionData(); 346 sub1.setFeedUrl(feed_url1); 347 planet.saveSubscription(sub1); 348 349 PlanetSubscriptionData sub2 = new PlanetSubscriptionData(); 350 sub2.setFeedUrl(feed_url2); 351 planet.saveSubscription(sub2); 352 353 group.addSubscription(sub1); 354 group.addSubscription(sub2); 355 planet.saveGroup(group); 356 357 roller.commit(); 358 } 359 { 360 roller.begin(); 361 planet.refreshEntries(); 362 roller.commit(); 363 364 roller.begin(); 365 int count = 0; 366 Iterator subs = planet.getAllSubscriptions(); 367 while (subs.hasNext()) 368 { 369 PlanetSubscriptionData sub= (PlanetSubscriptionData)subs.next(); 370 count += sub.getEntries().size(); 371 } 372 PlanetSubscriptionData sub1 = planet.getSubscription(feed_url1); 373 assertTrue(sub1.getEntries().size() > 0); 374 PlanetSubscriptionData sub2 = planet.getSubscription(feed_url2); 375 assertTrue(sub2.getEntries().size() > 0); 376 assertEquals(count, sub1.getEntries().size() + sub2.getEntries().size()); 377 378 PlanetGroupData group = planet.getGroup("test_handle"); 379 assertNotNull(group); 380 381 List bigag = planet.getAggregation(group, 1000); 382 assertEquals(bigag.size(), count); 383 384 List littleag = planet.getAggregation(group, 10); 385 assertEquals(littleag.size(), count); 386 387 planet.deleteSubscription(sub1); 388 planet.deleteSubscription(sub2); 389 planet.deleteGroup(group); 390 391 PlanetConfigData config = planet.getConfiguration(); 392 config.remove(); 393 roller.commit(); 394 } 395 } 396 catch (Exception e) 397 { 398 e.printStackTrace(); 399 } 400 } 401 public void testSubscriptionCount() throws Exception 402 { 403 try 404 { 405 Roller roller = getRoller(); 406 assertNotNull(roller); 407 PlanetManager planet = roller.getPlanetManager(); 408 assertNotNull(planet); 409 String feed_url1 = "http://rollerweblogger.org/rss/roller"; 410 String feed_url2 = "http://linuxintegrators.com/acoliver/?flavor=rss2"; 411 { 412 roller.begin(); 413 PlanetSubscriptionData sub1 = new PlanetSubscriptionData(); 414 sub1.setFeedUrl(feed_url1); 415 planet.saveSubscription(sub1); 416 PlanetSubscriptionData sub2 = new PlanetSubscriptionData(); 417 sub2.setFeedUrl(feed_url2); 418 planet.saveSubscription(sub2); 419 roller.commit(); 420 421 roller.begin(); 422 assertEquals(2, planet.getSubscriptionCount()); 423 roller.rollback(); 424 } 425 } 426 catch (Exception e) 427 { 428 e.printStackTrace(); 429 } 430 } 431 446 public Roller getRoller() throws RollerException 447 { 448 return RollerFactory.getRoller(); 449 } 450 451 public static Test suite() 452 { 453 return new TestSuite(PlanetManagerTest.class); 454 } 455 } 456 457 | Popular Tags |