Clover Coverage Report - KS Web 1.2-M3-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Jun 6 2011 07:05:47 EDT
111   205   5   37
2   138   0.05   3
3     1.67  
1    
 
  BasicPermissionsTest       Line # 38 111 0% 5 116 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    /**
17    *
18    */
19    package org.kuali.rice.student.permission;
20   
21    import java.util.HashMap;
22    import java.util.Map;
23   
24    import org.junit.Test;
25    import org.kuali.rice.kew.service.WorkflowDocument;
26    import org.kuali.rice.kew.util.KEWConstants;
27    import org.kuali.rice.kim.bo.impl.KimAttributes;
28    import org.kuali.rice.kim.bo.types.dto.AttributeSet;
29    import org.kuali.rice.kim.service.KIMServiceLocator;
30    import org.kuali.rice.kim.service.PermissionService;
31    import org.kuali.rice.student.StudentStandaloneTestBase;
32   
33    /**
34    * Test case to verify permissions work properly
35    *
36    * @author delyea
37    */
 
38    public class BasicPermissionsTest extends StudentStandaloneTestBase {
39   
40    protected static final String PERMISSIONS_NAME_OPEN_DOCUMENT = "Open Document";
41    protected static final String PERMISSIONS_NAME_COMMENT_ON_DOCUMENT = "Comment on Document";
42    protected static final String PERMISSIONS_NAME_EDIT_DOCUMENT = "Edit Document";
43   
 
44  0 toggle @Override
45    public void setUp() throws Exception {
46  0 super.setUp();
47  0 loadXmlFile("BasicPermissionsTestConfig.xml");
48    }
49   
 
50  0 toggle protected void verifyPermissions(String principalId, String documentId, Map<String,Boolean> existingPermissions) {
51  0 String permissionNamespace = "KS-LUM";
52  0 PermissionService permService = KIMServiceLocator.getPermissionService();
53  0 for (Map.Entry<String, Boolean> entry : existingPermissions.entrySet()) {
54  0 if ( (entry.getValue() != null) && (entry.getValue().booleanValue()) ) {
55  0 assertTrue("Principal Id '" + principalId + "' should have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
56    }
57    else {
58  0 assertFalse("Principal Id '" + principalId + "' should not have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
59    }
60    }
61    }
62   
 
63  0 toggle @Test public void testOpenPermission() throws Exception {
64  0 String documentTypeName = "BasicPermissionsTestDocument";
65  0 Map<String,Boolean> hasPermissionByPermissionName = new HashMap<String,Boolean>();
66   
67  0 String principalId = "testuser1";
68  0 WorkflowDocument doc = new WorkflowDocument(principalId, documentTypeName);
69  0 doc.saveDocument("");
70   
71    // verify testuser1 has correct permissions as initiator
72  0 principalId = "testuser1";
73  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
74  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
75  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
76  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
77  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
78   
79    // send adhoc approve to 'testuser3'
80  0 doc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", "testuser3", "", true);
81   
82    // verify testuser2 has no permissions
83  0 principalId = "testuser2";
84  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
85  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.FALSE);
86  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
87  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
88  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
89   
90    // verify testuser3 has no permissions
91  0 principalId = "testuser3";
92  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
93  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
94  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
95  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
96  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
97   
98  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
99  0 doc.routeDocument("");
100   
101    // verify testuser1 has correct permissions as initiator
102  0 principalId = "testuser1";
103  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
104  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
105  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
106  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
107   
108    // verify testuser3 has correct permissions as router
109  0 principalId = "testuser3";
110  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
111  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
112  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
113  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
114   
115    // verify fred has request for approval and correct permissions
116  0 principalId = "fred";
117  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
118  0 assertTrue("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
119  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
120  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
121  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
122  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
123   
124    // verify doug has request for approval and correct permissions
125  0 principalId = "doug";
126  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
127  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
128  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
129  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
130  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
131  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
132   
133    // appprove the document as fred and re-verify his and doug's permissions
134  0 principalId = "fred";
135  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
136  0 doc.approve("");
137   
138    // verify fred has no request for approval and correct permissions
139  0 principalId = "fred";
140  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
141  0 assertFalse("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
142  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
143  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
144  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
145  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
146   
147    // verify doug still has request for FYI and correct permissions
148  0 principalId = "doug";
149  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
150  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
151  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
152  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
153  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
154  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
155   
156    // verify edna has request for Acknoweldge and correct permissions
157  0 principalId = "edna";
158  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
159  0 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
160  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
161  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
162  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
163  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
164   
165    // route the document to PROCESSED
166  0 principalId = "fran";
167  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
168  0 doc.approve("");
169  0 principalId = "user1";
170  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
171  0 doc.approve("");
172   
173    // verify edna still has request for Acknoweldge and correct permissions
174  0 principalId = "edna";
175  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
176  0 assertTrue("", doc.stateIsProcessed());
177  0 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
178  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
179  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
180  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
181  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
182   
183    // move document to FINAL
184  0 doc.acknowledge("");
185   
186    // verify edna has no request and correct permissions
187  0 principalId = "edna";
188  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
189  0 assertTrue("Doc should be FINAL", doc.stateIsFinal());
190  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
191  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
192  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
193  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
194   
195    // verify doug still has request for FYI and correct permissions
196  0 principalId = "doug";
197  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
198  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
199  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
200  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
201  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
202  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
203   
204    }
205    }