KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > PermissionsTest


1 package org.roller.business;
2
3 import java.sql.Timestamp JavaDoc;
4 import java.util.Date JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
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 /**
28  * Test Roller Weblog Management.
29  */

30 public class PermissionsTest extends RollerTestBase
31 {
32     public PermissionsTest(String JavaDoc name)
33     {
34         super(name);
35     }
36     
37     public static void main(String JavaDoc 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 JavaDoc
48     {
49         super.setUp();
50         setUpTestWeblogs();
51     }
52         
53     public void tearDown() throws Exception JavaDoc
54     {
55         super.tearDown();
56         tearDownTestWeblogs();
57     }
58     
59     public void testWeblogEntryPermissions() throws Exception JavaDoc
60     {
61         getRoller().begin(UserData.ANONYMOUS_USER);
62         
63         // evil testuser
64
UserData testuser = getRoller().getUserManager().getUser("testuser");
65         assertNotNull(testuser);
66         
67         // gets hold of testuser0's entry
68
WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0");
69         assertNotNull(website0);
70         List JavaDoc entries = getRoller().getWeblogManager().getWeblogEntries(
71                 website0,
72                 null, // start
73
new Date JavaDoc(), // end
74
null, // cat
75
WeblogManager.ALL,
76                 new Integer JavaDoc(1));
77         WeblogEntryData entry = (WeblogEntryData)entries.get(0);
78         assertNotNull(entry);
79         
80         // and tries to save it
81
getRoller().setUser(testuser);
82         boolean denied = false;
83         try
84         {
85             entry.save();
86         }
87         catch (RollerPermissionsException e)
88         {
89             // permission denied!
90
denied = true;
91         }
92         assertTrue(denied);
93         getRoller().rollback();
94     }
95     
96     public void testBookmarkPermissions() throws Exception JavaDoc
97     {
98         getRoller().begin(UserData.ANONYMOUS_USER);
99         
100         // evil testuser
101
UserData testuser = getRoller().getUserManager().getUser("testuser");
102         assertNotNull(testuser);
103         
104         // gets hold of testuser0's entry
105
WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0");
106         assertNotNull(website0);
107         List JavaDoc 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         // and tries to save it
115
getRoller().setUser(testuser);
116         boolean denied = false;
117         try
118         {
119             bookmark.save();
120         }
121         catch (RollerPermissionsException e)
122         {
123             // permission denied!
124
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             // permission denied!
137
denied = true;
138         }
139         assertTrue(denied);
140        
141         getRoller().rollback();
142     }
143
144     public void testPagePermissions() throws Exception JavaDoc
145     {
146         getRoller().begin(UserData.ANONYMOUS_USER);
147         
148         // evil testuser
149
UserData testuser = getRoller().getUserManager().getUser("testuser");
150         assertNotNull(testuser);
151         
152         // gets hold of testuser0's entry
153
WebsiteData website0 = getRoller().getUserManager().getWebsite("testuser0");
154         assertNotNull(website0);
155         PageData page = (PageData)getRoller().getUserManager().getPages(website0).get(0);
156         assertNotNull(page);
157         
158         // and tries to save it
159
getRoller().setUser(testuser);
160         boolean denied = false;
161         try
162         {
163             page.save();
164         }
165         catch (RollerPermissionsException e)
166         {
167             // permission denied!
168
denied = true;
169         }
170         assertTrue(denied);
171         
172         
173         // and tries to save it
174
getRoller().setUser(testuser);
175         denied = false;
176         try
177         {
178             website0.save();
179         }
180         catch (RollerPermissionsException e)
181         {
182             // permission denied!
183
denied = true;
184         }
185         assertTrue(denied);
186
187         
188         getRoller().rollback();
189     }
190
191     /*
192      Disabling this test for now because it won't work.
193     public void testConfigPermissions() throws Exception
194     {
195         getRoller().begin(UserData.ANONYMOUS_USER);
196         
197         // evil testuser0
198         UserData testuser0 = getRoller().getUserManager().getUser("testuser0");
199         assertNotNull(testuser0);
200         
201         // gets hold of testuser's (an admin) entry
202         WebsiteData website = getRoller().getUserManager().getWebsite("testuser");
203         assertNotNull(website);
204         
205         Map config = getRoller().getPropertiesManager().getProperties();
206         assertNotNull(config);
207         
208         // and tries to save it
209         getRoller().setUser(testuser0);
210         boolean denied = false;
211         try
212         {
213             getRoller().getPropertiesManager().store(config);
214         }
215         catch (RollerPermissionsException e)
216         {
217             // permission denied!
218             denied = true;
219         }
220         assertTrue(denied);
221         getRoller().rollback();
222     }
223     */

224 }
225
226
Popular Tags