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.BookmarkData; 17 import org.roller.pojos.CommentData; 18 import org.roller.pojos.FolderData; 19 import org.roller.pojos.PageData; 20 import org.roller.pojos.UserData; 21 import org.roller.pojos.WeblogCategoryData; 22 import org.roller.pojos.WeblogEntryData; 23 import org.roller.pojos.WebsiteData; 24 import org.roller.util.Utilities; 25 import org.roller.RollerTestBase; 26 27 30 public class PermissionsTest extends RollerTestBase 31 { 32 public PermissionsTest(String name) 33 { 34 super(name); 35 } 36 37 public static void main(String args[]) 38 { 39 junit.textui.TestRunner.run(PermissionsTest.class); 40 } 41 42 public static Test suite() 43 { 44 return new TestSuite(PermissionsTest.class); 45 } 46 47 public void setUp() throws Exception 48 { 49 super.setUp(); 50 setUpTestWeblogs(); 51 } 52 53 public void tearDown() throws Exception 54 { 55 super.tearDown(); 56 tearDownTestWeblogs(); 57 } 58 59 public void testWeblogEntryPermissions() throws Exception 60 { 61 getRoller().begin(UserData.ANONYMOUS_USER); 62 63 UserData testuser = getRoller().getUserManager().getUser("testuser"); 65 assertNotNull(testuser); 66 67 WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0"); 69 assertNotNull(website0); 70 List entries = getRoller().getWeblogManager().getWeblogEntries( 71 website0, 72 null, new Date (), null, WeblogManager.ALL, 76 new Integer (1)); 77 WeblogEntryData entry = (WeblogEntryData)entries.get(0); 78 assertNotNull(entry); 79 80 getRoller().setUser(testuser); 82 boolean denied = false; 83 try 84 { 85 entry.save(); 86 } 87 catch (RollerPermissionsException e) 88 { 89 denied = true; 91 } 92 assertTrue(denied); 93 getRoller().rollback(); 94 } 95 96 public void testBookmarkPermissions() throws Exception 97 { 98 getRoller().begin(UserData.ANONYMOUS_USER); 99 100 UserData testuser = getRoller().getUserManager().getUser("testuser"); 102 assertNotNull(testuser); 103 104 WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0"); 106 assertNotNull(website0); 107 List folders = getRoller().getBookmarkManager().getAllFolders(website0); 108 FolderData root = (FolderData)folders.get(0); 109 FolderData folder = (FolderData)root.getFolders().get(0); 110 111 BookmarkData bookmark = (BookmarkData)(folder.getBookmarks().iterator().next()); 112 assertNotNull(bookmark); 113 114 getRoller().setUser(testuser); 116 boolean denied = false; 117 try 118 { 119 bookmark.save(); 120 } 121 catch (RollerPermissionsException e) 122 { 123 denied = true; 125 } 126 assertTrue(denied); 127 128 getRoller().setUser(testuser); 129 denied = false; 130 try 131 { 132 folder.save(); 133 } 134 catch (RollerPermissionsException e) 135 { 136 denied = true; 138 } 139 assertTrue(denied); 140 141 getRoller().rollback(); 142 } 143 144 public void testPagePermissions() throws Exception 145 { 146 getRoller().begin(UserData.ANONYMOUS_USER); 147 148 UserData testuser = getRoller().getUserManager().getUser("testuser"); 150 assertNotNull(testuser); 151 152 WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0"); 154 assertNotNull(website0); 155 PageData page = (PageData)getRoller().getUserManager().getPages(website0).get(0); 156 assertNotNull(page); 157 158 getRoller().setUser(testuser); 160 boolean denied = false; 161 try 162 { 163 page.save(); 164 } 165 catch (RollerPermissionsException e) 166 { 167 denied = true; 169 } 170 assertTrue(denied); 171 172 173 getRoller().setUser(testuser); 175 denied = false; 176 try 177 { 178 website0.save(); 179 } 180 catch (RollerPermissionsException e) 181 { 182 denied = true; 184 } 185 assertTrue(denied); 186 187 188 getRoller().rollback(); 189 } 190 191 224 } 225 226 | Popular Tags |