1 package org.roller.business; 2 3 import java.sql.Timestamp ; 4 import java.util.Date ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import junit.framework.Test; 10 import junit.framework.TestSuite; 11 12 import org.roller.RollerException; 13 import org.roller.RollerPermissionsException; 14 import org.roller.model.UserManager; 15 import org.roller.model.WeblogManager; 16 import org.roller.pojos.CommentData; 17 import org.roller.pojos.UserData; 18 import org.roller.pojos.WeblogCategoryData; 19 import org.roller.pojos.WeblogEntryData; 20 import org.roller.pojos.WebsiteData; 21 import org.roller.util.Utilities; 22 import org.roller.RollerTestBase; 23 24 27 public class WeblogManagerTest extends RollerTestBase 28 { 29 String dest_id = null; 30 String c1_id = null; 31 String c2_id = null; 32 String c3_id = null; 33 34 public WeblogManagerTest(String name) 36 { 37 super(name); 38 } 39 40 public static void main(String args[]) 42 { 43 junit.textui.TestRunner.run(WeblogManagerTest.class); 44 } 45 46 public static Test suite() 48 { 49 return new TestSuite(WeblogManagerTest.class); 50 } 51 52 56 public void setUp() throws Exception 57 { 58 super.setUp(); 59 setUpTestWeblogs(); 60 setUpCategoryTree(); 61 } 62 63 71 public void setUpCategoryTree() throws Exception 72 { 73 getRoller().begin(UserData.SYSTEM_USER); 74 75 WebsiteData wd = null; 76 WeblogCategoryData root = null; 77 WeblogManager wmgr = getRoller().getWeblogManager(); 78 79 wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId()); 80 root = wmgr.getRootWeblogCategory(wd); 81 82 WeblogCategoryData dest = wmgr.createWeblogCategory(); 84 dest.setName("c0"); 85 dest.setParent(root); 86 dest.setWebsite(wd); 87 dest.save(); 88 89 WeblogCategoryData c1 = wmgr.createWeblogCategory(); 91 c1.setName("c1"); 92 c1.setParent(root); 93 c1.setWebsite(wd); 94 c1.save(); 95 96 WeblogEntryData e1 = new WeblogEntryData( 97 null, c1, wd, "title1", null, "text", "anchor", 98 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 99 e1.save(); 100 101 WeblogCategoryData c2 = wmgr.createWeblogCategory(); 102 c2.setName("c2"); 103 c2.setParent(c1); 104 c2.setWebsite(wd); 105 c2.save(); 106 107 WeblogEntryData e2 = new WeblogEntryData( 108 null, c2, wd, "title2", null, "text", "anchor", 109 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 110 e2.save(); 111 112 WeblogCategoryData c3 = wmgr.createWeblogCategory(); 113 c3.setName("c3"); 114 c3.setParent(c2); 115 c3.setWebsite(wd); 116 c3.save(); 117 118 WeblogEntryData e3 = new WeblogEntryData( 119 null, c3, wd, "title3", null, "text", "anchor", 120 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 121 e3.save(); 122 123 getRoller().commit(); 124 125 dest_id = dest.getId(); 126 c1_id = c1.getId(); 127 c2_id = c2.getId(); 128 c3_id = c3.getId(); 129 } 130 131 135 public void tearDown() throws Exception 136 { 137 super.tearDown(); 138 tearDownTestWeblogs(); 139 } 140 141 143 144 public void testGetRecent() throws Exception 145 { 146 getRoller().begin(UserData.SYSTEM_USER); 147 148 WebsiteData wd = null; 149 WeblogCategoryData root = null; 150 WeblogManager wmgr = getRoller().getWeblogManager(); 151 152 wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId()); 153 root = wmgr.getRootWeblogCategory(wd); 154 155 WeblogCategoryData t1 = wmgr.createWeblogCategory(); 157 t1.setName("toplevel1"); 158 t1.setParent(root); 159 t1.setWebsite(wd); 160 t1.save(); 161 162 WeblogCategoryData t2 = wmgr.createWeblogCategory(); 163 t2.setName("toplevel2"); 164 t2.setParent(root); 165 t2.setWebsite(wd); 166 t2.save(); 167 168 WeblogCategoryData t3 = wmgr.createWeblogCategory(); 169 t3.setName("toplevel3"); 170 t3.setParent(root); 171 t3.setWebsite(wd); 172 t3.save(); 173 174 getRoller().commit(); 175 176 getRoller().begin(UserData.SYSTEM_USER); 177 178 t1 = wmgr.retrieveWeblogCategory(t1.getId()); 180 wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId()); 181 182 WeblogEntryData e1 = new WeblogEntryData( 184 null, t1, wd, "title1", null, "text1", "anchor", 185 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 186 e1.save(); 187 188 WeblogEntryData e2 = new WeblogEntryData( 189 null, t1, wd, "title2", null, "text2", "anchor", 190 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 191 e2.save(); 192 193 WeblogEntryData e3 = new WeblogEntryData( 194 null, t1, wd, "title3", null, "text3", "anchor", 195 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 196 e3.save(); 197 198 WeblogEntryData e4 = new WeblogEntryData( 199 null, t1, wd, "title4", null, "text4", "anchor", 200 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 201 e4.save(); 202 203 getRoller().commit(); 204 205 getRoller().begin(UserData.SYSTEM_USER); 206 207 210 List entries = wmgr.getWeblogEntries( 211 wd, 212 null, new Date (), "toplevel1", WeblogManager.ALL, new Integer (15)); 218 assertEquals(4, entries.size()); 219 220 getRoller().rollback(); 221 } 222 223 public void testGetWeblogCategoryRoot() throws Exception 224 { 225 getRoller().begin(UserData.SYSTEM_USER); 226 WeblogManager wmgr = getRoller().getWeblogManager(); 227 assertNotNull(wmgr.getRootWeblogCategory(mWebsite)); 228 getRoller().rollback(); 229 } 230 231 public void testGetWeblogCategories() throws Exception 232 { 233 getRoller().begin(UserData.SYSTEM_USER); 234 WeblogManager wmgr = getRoller().getWeblogManager(); 235 assertEquals(8, wmgr.getWeblogCategories(mWebsite).size()); 236 getRoller().rollback(); 237 } 238 239 public void testWeblogCategoryPaths() throws Exception 240 { 241 WebsiteData wd = null; 242 WeblogCategoryData root = null; 243 WeblogManager wmgr = getRoller().getWeblogManager(); 244 245 getRoller().begin(UserData.SYSTEM_USER); 246 247 wd = getRoller().getUserManager().retrieveWebsite(mWebsite.getId()); 248 root = wmgr.getRootWeblogCategory(wd); 249 250 WeblogCategoryData f1 = wmgr.createWeblogCategory(); 251 f1.setName("f1"); 252 f1.setParent(root); 253 f1.setWebsite(wd); 254 f1.save(); 255 256 WeblogCategoryData f2 = wmgr.createWeblogCategory(); 257 f2.setName("f2"); 258 f2.setParent(f1); 259 f2.setWebsite(wd); 260 f2.save(); 261 262 WeblogCategoryData f3 = wmgr.createWeblogCategory(); 263 f3.setName("f3"); 264 f3.setParent(f2); 265 f3.setWebsite(wd); 266 f3.save(); 267 268 getRoller().commit(); 269 270 getRoller().begin(UserData.SYSTEM_USER); 271 272 f1 = wmgr.retrieveWeblogCategory(f1.getId()); 274 assertEquals(2, f1.getAllDescendentAssocs().size()); 275 assertEquals(1, f1.getAncestorAssocs().size()); 276 277 f2 = wmgr.retrieveWeblogCategory(f2.getId()); 278 assertEquals(1, f2.getAllDescendentAssocs().size()); 279 assertEquals(2, f2.getAncestorAssocs().size()); 280 281 f3 = wmgr.retrieveWeblogCategory(f3.getId()); 282 assertEquals(0, f3.getAllDescendentAssocs().size()); 283 assertEquals(3, f3.getAncestorAssocs().size()); 284 285 assertEquals("f1", 287 wmgr.getWeblogCategoryByPath(wd, null, "f1").getName()); 288 289 assertEquals("f1", 290 wmgr.getWeblogCategoryByPath(wd, null, "/f1").getName()); 291 292 assertEquals("f2", 293 wmgr.getWeblogCategoryByPath(wd, null, "/f1/f2").getName()); 294 295 assertEquals("f3", 296 wmgr.getWeblogCategoryByPath(wd, null, "/f1/f2/f3").getName()); 297 298 f3 = wmgr.getWeblogCategoryByPath(wd, null, "/f1/f2/f3"); 300 String pathString = wmgr.getPath(f3); 301 String [] pathArray = Utilities.stringToStringArray(pathString,"/"); 302 assertEquals("f1", pathArray[0]); 303 assertEquals("f2", pathArray[1]); 304 assertEquals("f3", pathArray[2]); 305 306 getRoller().commit(); 307 } 308 309 311 public void testGetWeblogEntryByAnchor() throws Exception 312 { 313 WeblogManager wmgr = getRoller().getWeblogManager(); 314 315 WeblogEntryData entry1 = (WeblogEntryData)mEntriesCreated.get(0); 316 317 WebsiteData website = entry1.getWebsite(); 318 319 WeblogEntryData entry2 = wmgr.getWeblogEntryByAnchor( 320 website, entry1.getAnchor() ); 321 322 assertEquals( entry1.getId(), entry2.getId() ); 323 } 324 325 330 public void testGetWeblogLastUpdateTimeForUser() throws Exception 331 { 332 WeblogManager wmgr = getRoller().getWeblogManager(); 333 334 339 int lastEntryIndex = (mEntriesCreated.size()-1); 340 WeblogEntryData entry1 = null; 342 if (entry1 == null || !entry1.getPublishEntry().booleanValue()) { 345 for (int i=lastEntryIndex; i >= 0; i--) 346 { 347 entry1 = (WeblogEntryData) 348 mEntriesCreated.get(i); if (entry1.getPublishEntry().booleanValue()) { 351 break; 352 } 353 } 354 } 355 356 WebsiteData website = entry1.getWebsite(); 357 UserData user = website.getUser(); 358 Date updateTime = wmgr.getWeblogLastPublishTime(user.getUserName()); 359 360 assertEquals("THIS FAILS RANDOMLY, TRY AGAIN", entry1.getPubTime(),updateTime); 361 } 362 363 368 public void testGetWeblogLastUpdateTimeForAll() throws Exception 369 { 370 WeblogManager wmgr = getRoller().getWeblogManager(); 371 372 375 int lastEntryIndex = (mEntriesCreated.size()-1); 376 WeblogEntryData entry1 = null; 378 WeblogEntryData temp = null; 379 for (int i=lastEntryIndex; i >= 0; i--) 380 { 381 temp = (WeblogEntryData) 382 mEntriesCreated.get(i); if (temp.getPublishEntry().booleanValue()) 385 { 386 if (entry1 == null || entry1.getPubTime().compareTo(temp.getPubTime()) < 0) 387 { 388 if (entry1 != null) 389 System.out.println("replacing " + entry1.getTitle() + " with " + temp.getTitle()); 390 else 391 System.out.println("setting entry1 to " + temp.getTitle()); 392 entry1 = temp; 393 } 394 } 395 } 396 397 Date updateTime = wmgr.getWeblogLastPublishTime(null); 398 399 assertEquals("THIS FAILS RANDOMLY, TRY AGAIN", entry1.getPubTime(),updateTime); 400 } 401 402 403 private int countEntries( Map entryMap ) 404 { 405 int count = 0; 406 Iterator days = entryMap.values().iterator(); 407 while (days.hasNext()) 408 { 409 List dayEntries = (List ) days.next(); 410 Iterator entries = dayEntries.iterator(); 411 while (entries.hasNext()) 412 { 413 entries.next(); 414 count++; 415 } 416 } 417 return count; 418 } 419 420 public void testIsWeblogCategoryInUse() throws Exception 421 { 422 WeblogManager wmgr = getRoller().getWeblogManager(); 423 UserManager umgr = getRoller().getUserManager(); 424 425 getRoller().begin(UserData.SYSTEM_USER); 426 427 WebsiteData website = umgr.retrieveWebsite(mWebsite.getId()); 428 WeblogEntryData entry = (WeblogEntryData)mEntriesCreated.get(2); 429 WeblogCategoryData rootCat = wmgr.getRootWeblogCategory(website); 430 431 WeblogCategoryData usedCat = 432 wmgr.retrieveWeblogCategory(entry.getCategory().getId()); 433 434 WeblogCategoryData unusedCat = wmgr.createWeblogCategory( 435 website, rootCat, "testy", "tasty", "testy.gif"); 436 unusedCat.save(); 437 438 getRoller().commit(); 439 440 getRoller().begin(UserData.SYSTEM_USER); 441 usedCat = wmgr.retrieveWeblogCategory(usedCat.getId()); 442 assertTrue(usedCat.isInUse()); 443 444 unusedCat = wmgr.retrieveWeblogCategory(unusedCat.getId()); 445 assertFalse(unusedCat.isInUse()); 446 getRoller().commit(); 447 } 448 449 public void testStoreComment() throws Exception 450 { 451 getRoller().begin(UserData.SYSTEM_USER); 452 WeblogManager wmgr = getRoller().getWeblogManager(); 453 454 WeblogEntryData entry1 = (WeblogEntryData)mEntriesCreated.get(1); 456 457 entry1 = getRoller().getWeblogManager().retrieveWeblogEntry( 459 entry1.getId()); 460 461 CommentData comment = new CommentData( 462 null, 463 entry1, 464 "TestCommentUser", 465 "test@test.com", 466 "", 467 "This is a test", 468 new Timestamp (new Date ().getTime()), 469 Boolean.FALSE, Boolean.FALSE); 472 comment.save(); 473 getRoller().commit(); 474 475 List comments = wmgr.getComments(entry1.getId()); 476 assertTrue(comments.size() > mCommentCount); 477 478 getRoller().begin(UserData.SYSTEM_USER); 479 wmgr.removeComment(comment.getId()); 480 getRoller().commit(); 481 } 482 483 public void testMoveCategoryContents() throws RollerException 484 { 485 WeblogManager wmgr = getRoller().getWeblogManager(); 486 487 WeblogCategoryData c1 = wmgr.retrieveWeblogCategory(c1_id); 488 WeblogCategoryData dest = wmgr.retrieveWeblogCategory(dest_id); 491 492 getRoller().begin(UserData.SYSTEM_USER); 493 494 dest = wmgr.retrieveWeblogCategory(dest.getId()); 496 c1 = wmgr.retrieveWeblogCategory(c1.getId()); 497 assertEquals(0, dest.retrieveWeblogEntries(true).size()); 498 assertEquals(0, dest.retrieveWeblogEntries(false).size()); 499 assertEquals(1, c1.retrieveWeblogEntries(false).size()); 500 assertEquals(3, c1.retrieveWeblogEntries(true).size()); 501 502 c1.moveContents(dest); 504 505 getRoller().commit(); 506 507 getRoller().begin(UserData.SYSTEM_USER); 508 509 dest = wmgr.retrieveWeblogCategory(dest.getId()); 511 c1 = wmgr.retrieveWeblogCategory(c1.getId()); 512 assertEquals(3, dest.retrieveWeblogEntries(true).size()); 513 assertEquals(3, dest.retrieveWeblogEntries(false).size()); 514 assertEquals(0, c1.retrieveWeblogEntries(true).size()); 515 assertEquals(0, c1.retrieveWeblogEntries(false).size()); 516 517 getRoller().commit(); 518 } 519 520 public void testMoveCategoryProtection() throws RollerException 521 { 522 boolean safe = false; 523 try 524 { 525 getRoller().begin(UserData.SYSTEM_USER); 526 WeblogManager wmgr = getRoller().getWeblogManager(); 527 528 WeblogCategoryData c1 = wmgr.retrieveWeblogCategory(c1_id); 530 WeblogCategoryData c3 = wmgr.retrieveWeblogCategory(c3_id); 531 wmgr.moveWeblogCategoryContents(c1.getId(), c3.getId()); 532 c3.save(); 533 c1.save(); 534 getRoller().commit(); 535 } 536 catch (RollerException e) 537 { 538 safe = true; 539 } 540 assertTrue(safe); 541 } 542 543 public void testMoveCategory() throws RollerException 544 { 545 getRoller().begin(UserData.SYSTEM_USER); 546 WeblogManager wmgr = getRoller().getWeblogManager(); 547 548 WeblogCategoryData c1 = wmgr.retrieveWeblogCategory(c1_id); 549 WeblogCategoryData c2 = wmgr.retrieveWeblogCategory(c2_id); 550 WeblogCategoryData c3 = wmgr.retrieveWeblogCategory(c3_id); 551 WeblogCategoryData dest = wmgr.retrieveWeblogCategory(dest_id); 552 553 dest = wmgr.retrieveWeblogCategory(dest.getId()); 555 c1 = wmgr.retrieveWeblogCategory(c1.getId()); 556 assertEquals(0, dest.retrieveWeblogEntries(true).size()); 557 assertEquals(0, dest.retrieveWeblogEntries(false).size()); 558 assertEquals(1, c1.retrieveWeblogEntries(false).size()); 559 assertEquals(3, c1.retrieveWeblogEntries(true).size()); 560 561 c1.setParent(dest); 563 c1.save(); 564 565 getRoller().commit(); 566 567 getRoller().begin(UserData.SYSTEM_USER); 568 569 dest = wmgr.retrieveWeblogCategory(dest.getId()); 571 c1 = wmgr.retrieveWeblogCategory(c1_id); 572 c2 = wmgr.retrieveWeblogCategory(c2_id); 573 c3 = wmgr.retrieveWeblogCategory(c3_id); 574 575 assertEquals(3, dest.retrieveWeblogEntries(true).size()); 576 assertEquals(0, dest.retrieveWeblogEntries(false).size()); 577 578 assertEquals(dest, c1.getParent()); 579 assertEquals(c1, c2.getParent()); 580 assertEquals(c2, c3.getParent()); 581 582 assertEquals(1, c1.retrieveWeblogEntries(false).size()); 583 assertEquals(1, c2.retrieveWeblogEntries(false).size()); 584 assertEquals(1, c3.retrieveWeblogEntries(false).size()); 585 586 List entries = c1.retrieveWeblogEntries(true); 587 assertEquals(3, entries.size()); 588 589 getRoller().commit(); 590 } 591 592 public void testNextPrevPost() throws RollerException 593 { 594 getRoller().begin(UserData.SYSTEM_USER); 595 WeblogManager wmgr = getRoller().getWeblogManager(); 596 597 WeblogEntryData entry0 = (WeblogEntryData)mEntriesCreated.get(0); 599 WeblogEntryData entry1 = (WeblogEntryData)mEntriesCreated.get(1); 600 WeblogEntryData entry2 = (WeblogEntryData)mEntriesCreated.get(2); 601 WeblogEntryData entry3 = (WeblogEntryData)mEntriesCreated.get(3); 602 WeblogEntryData entry4 = (WeblogEntryData)mEntriesCreated.get(4); 603 WeblogEntryData entry5 = (WeblogEntryData)mEntriesCreated.get(5); 604 WeblogEntryData entry6 = (WeblogEntryData)mEntriesCreated.get(6); 605 WeblogEntryData entry7 = (WeblogEntryData)mEntriesCreated.get(7); 606 607 609 assertEquals(null, wmgr.getPreviousEntry(entry0, null)); 611 612 assertEquals(entry1, wmgr.getNextEntry(entry0, null)); 614 615 assertEquals(entry0, wmgr.getPreviousEntry(entry2, null)); 617 618 620 WeblogCategoryData cat = (WeblogCategoryData)mCategoriesCreated.get(1); 621 622 assertEquals(null, wmgr.getPreviousEntry(entry5, "/root-cat1/root-cat1-cat0")); 623 assertEquals(entry7, wmgr.getNextEntry(entry5, "/root-cat1/root-cat1-cat0")); 624 assertEquals(entry5, wmgr.getPreviousEntry(entry7, "/root-cat1/root-cat1-cat0")); 625 626 getRoller().rollback(); 627 } 628 629 public void testGetComments() throws RollerException 630 { 631 getRoller().begin(UserData.SYSTEM_USER); 632 WeblogEntryData entry0 = (WeblogEntryData)mEntriesCreated.get(0); 633 WeblogManager wmgr = getRoller().getWeblogManager(); 634 assertEquals(mCommentCount, wmgr.getComments(entry0.getId()).size()); 635 getRoller().commit(); 636 } 637 638 public void testQueryWeblogEntries() throws RollerException 639 { 640 getRoller().begin(UserData.SYSTEM_USER); 641 WeblogManager wmgr = getRoller().getWeblogManager(); 642 UserManager umgr = getRoller().getUserManager(); 643 644 WebsiteData website = (WebsiteData)mWebsites.get(0); 645 website = umgr.retrieveWebsite(website.getId()); 646 647 List publishedEntries = wmgr.getWeblogEntries( 649 website, null, new Date (), null, WeblogManager.PUB_ONLY, null); assertEquals(mExpectedPublishedEntryCount, publishedEntries.size()); 656 657 List draftEntries = wmgr.getWeblogEntries( 659 website, null, new Date (), null, WeblogManager.DRAFT_ONLY, null); assertEquals(mExpectedEntryCount-mExpectedPublishedEntryCount, draftEntries.size()); 666 667 List allEntries = wmgr.getWeblogEntries( 669 website, null, new Date (), null, WeblogManager.ALL, null); assertEquals(mExpectedEntryCount, allEntries.size()); 676 677 List allEntries2 = wmgr.getWeblogEntries( 679 website, null, new Date (), null, null, null); assertEquals(mExpectedEntryCount, allEntries2.size()); 686 687 getRoller().commit(); 688 } 689 690 public void testGetRecentComments() throws Exception 691 { 692 getRoller().begin(UserData.SYSTEM_USER); 693 WeblogManager wmgr = getRoller().getWeblogManager(); 694 UserManager umgr = getRoller().getUserManager(); 695 696 WebsiteData website = (WebsiteData)mWebsites.get(0); 697 website = umgr.retrieveWebsite(website.getId()); 698 List comments = wmgr.getRecentComments(website, 2); 699 assertTrue(comments.size() > 1); 700 705 assertTrue("name1".compareTo("name0") >0); 706 assertTrue( 707 ((CommentData)comments.get(0)).getName().compareTo( 708 ((CommentData)comments.get(1)).getName()) > 0); 709 713 assertTrue( 714 ((CommentData)comments.get(0)).getPostTime().compareTo( 715 ((CommentData)comments.get(1)).getPostTime()) > 0); 716 } 717 718 public void testGetLastPublishTime() throws Exception 719 { 720 getRoller().begin(UserData.SYSTEM_USER); 721 WeblogManager wmgr = getRoller().getWeblogManager(); 722 WebsiteData website = (WebsiteData)mWebsites.get(0); 723 724 Date lastPub = wmgr.getWeblogLastPublishTime( 725 website.getUser().getUserName()); 726 assertTrue(lastPub.compareTo(new Date ()) <= 0); 728 } 729 730 public void testEntryAttributes() throws Exception { 731 getRoller().begin(UserData.SYSTEM_USER); 732 WeblogManager wmgr = getRoller().getWeblogManager(); 733 WebsiteData website = (WebsiteData)mWebsites.get(0); 734 735 WeblogCategoryData cat = wmgr.getRootWeblogCategory(website); 736 737 WeblogEntryData entry = new WeblogEntryData( 738 null, cat, website, "title2", null, "text2", "attributetest", 739 new Timestamp (0), new Timestamp (0), Boolean.FALSE); 740 entry.save(); 741 assertNotNull(entry.getId()); 742 743 entry.putEntryAttribute("testname", "testvalue"); 744 entry.putEntryAttribute("testname2", "testvalue2"); 745 entry.save(); 746 747 getRoller().commit(); 748 749 WeblogEntryData fetchedEntry = wmgr.retrieveWeblogEntry(entry.getId()); 750 assertNotNull(fetchedEntry.getEntryAttributes()); 751 assertEquals(2, fetchedEntry.getEntryAttributes().size()); 752 753 assertEquals(fetchedEntry.findEntryAttribute("testname"), "testvalue"); 754 assertEquals(fetchedEntry.findEntryAttribute("testname2"), "testvalue2"); 755 } 756 757 758 public void testPermissions() throws Exception 759 { 760 getRoller().begin(UserData.ANONYMOUS_USER); 761 762 UserData testuser = getRoller().getUserManager().getUser("testuser"); 764 assertNotNull(testuser); 765 766 WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0"); 768 assertNotNull(website0); 769 List entries = getRoller().getWeblogManager().getWeblogEntries( 770 website0, 771 null, new Date (), null, WeblogManager.ALL, 775 new Integer (1)); 776 WeblogEntryData entry = (WeblogEntryData)entries.get(0); 777 assertNotNull(entry); 778 779 getRoller().setUser(testuser); 781 boolean denied = false; 782 try 783 { 784 entry.save(); 785 } 786 catch (RollerPermissionsException e) 787 { 788 denied = true; 790 } 791 assertTrue(denied); 792 getRoller().rollback(); 793 } 794 } 795 796 | Popular Tags |