Clover Coverage Report - KS LUM Rice 1.2-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
111   202   5   37
2   138   0.05   3
3     1.67  
1    
 
  BasicPermissionsTest       Line # 35 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    package org.kuali.rice.student.permission;
17   
18    import java.util.HashMap;
19    import java.util.Map;
20   
21    import org.junit.Test;
22    import org.kuali.rice.kew.service.WorkflowDocument;
23    import org.kuali.rice.kew.util.KEWConstants;
24    import org.kuali.rice.kim.bo.impl.KimAttributes;
25    import org.kuali.rice.kim.bo.types.dto.AttributeSet;
26    import org.kuali.rice.kim.service.KIMServiceLocator;
27    import org.kuali.rice.kim.service.PermissionService;
28    import org.kuali.rice.student.StudentStandaloneTestBase;
29   
30    /**
31    * Test case to verify permissions work properly
32    *
33    * @author delyea
34    */
 
35    public class BasicPermissionsTest extends StudentStandaloneTestBase {
36   
37    protected static final String PERMISSIONS_NAME_OPEN_DOCUMENT = "Open Document";
38    protected static final String PERMISSIONS_NAME_COMMENT_ON_DOCUMENT = "Comment on Document";
39    protected static final String PERMISSIONS_NAME_EDIT_DOCUMENT = "Edit Document";
40   
 
41  0 toggle @Override
42    public void setUp() throws Exception {
43  0 super.setUp();
44  0 loadXmlFile("BasicPermissionsTestConfig.xml");
45    }
46   
 
47  0 toggle protected void verifyPermissions(String principalId, String documentId, Map<String,Boolean> existingPermissions) {
48  0 String permissionNamespace = "KS-LUM";
49  0 PermissionService permService = KIMServiceLocator.getPermissionService();
50  0 for (Map.Entry<String, Boolean> entry : existingPermissions.entrySet()) {
51  0 if ( (entry.getValue() != null) && (entry.getValue().booleanValue()) ) {
52  0 assertTrue("Principal Id '" + principalId + "' should have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
53    }
54    else {
55  0 assertFalse("Principal Id '" + principalId + "' should not have permission '" + entry.getKey() + "'", permService.isAuthorized(principalId, permissionNamespace, entry.getKey(), null, new AttributeSet(KimAttributes.DOCUMENT_NUMBER, ""+documentId)));
56    }
57    }
58    }
59   
 
60  0 toggle @Test public void testOpenPermission() throws Exception {
61  0 String documentTypeName = "BasicPermissionsTestDocument";
62  0 Map<String,Boolean> hasPermissionByPermissionName = new HashMap<String,Boolean>();
63   
64  0 String principalId = "testuser1";
65  0 WorkflowDocument doc = new WorkflowDocument(principalId, documentTypeName);
66  0 doc.saveDocument("");
67   
68    // verify testuser1 has correct permissions as initiator
69  0 principalId = "testuser1";
70  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
71  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
72  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
73  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
74  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
75   
76    // send adhoc approve to 'testuser3'
77  0 doc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", "testuser3", "", true);
78   
79    // verify testuser2 has no permissions
80  0 principalId = "testuser2";
81  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
82  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.FALSE);
83  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
84  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
85  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
86   
87    // verify testuser3 has no permissions
88  0 principalId = "testuser3";
89  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
90  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
91  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
92  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
93  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
94   
95  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
96  0 doc.routeDocument("");
97   
98    // verify testuser1 has correct permissions as initiator
99  0 principalId = "testuser1";
100  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
101  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
102  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
103  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
104   
105    // verify testuser3 has correct permissions as router
106  0 principalId = "testuser3";
107  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
108  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
109  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
110  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
111   
112    // verify fred has request for approval and correct permissions
113  0 principalId = "fred";
114  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
115  0 assertTrue("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
116  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
117  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
118  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.TRUE);
119  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
120   
121    // verify doug has request for approval and correct permissions
122  0 principalId = "doug";
123  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
124  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
125  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
126  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
127  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
128  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
129   
130    // appprove the document as fred and re-verify his and doug's permissions
131  0 principalId = "fred";
132  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
133  0 doc.approve("");
134   
135    // verify fred has no request for approval and correct permissions
136  0 principalId = "fred";
137  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
138  0 assertFalse("Approval should be requested of user '" + principalId + "'", doc.isApprovalRequested());
139  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
140  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
141  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
142  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
143   
144    // verify doug still has request for FYI and correct permissions
145  0 principalId = "doug";
146  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
147  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
148  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
149  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
150  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
151  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
152   
153    // verify edna has request for Acknoweldge and correct permissions
154  0 principalId = "edna";
155  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
156  0 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
157  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
158  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
159  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
160  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
161   
162    // route the document to PROCESSED
163  0 principalId = "fran";
164  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
165  0 doc.approve("");
166  0 principalId = "user1";
167  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
168  0 doc.approve("");
169   
170    // verify edna still has request for Acknoweldge and correct permissions
171  0 principalId = "edna";
172  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
173  0 assertTrue("", doc.stateIsProcessed());
174  0 assertTrue("Acknowledge should be requested of user '" + principalId + "'", doc.isAcknowledgeRequested());
175  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
176  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
177  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
178  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
179   
180    // move document to FINAL
181  0 doc.acknowledge("");
182   
183    // verify edna has no request and correct permissions
184  0 principalId = "edna";
185  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
186  0 assertTrue("Doc should be FINAL", doc.stateIsFinal());
187  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
188  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.FALSE);
189  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
190  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
191   
192    // verify doug still has request for FYI and correct permissions
193  0 principalId = "doug";
194  0 doc = new WorkflowDocument(principalId, doc.getRouteHeaderId());
195  0 assertTrue("FYI should be requested of user '" + principalId + "'", doc.isFYIRequested());
196  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_OPEN_DOCUMENT, Boolean.TRUE);
197  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_COMMENT_ON_DOCUMENT, Boolean.TRUE);
198  0 hasPermissionByPermissionName.put(PERMISSIONS_NAME_EDIT_DOCUMENT, Boolean.FALSE);
199  0 verifyPermissions(principalId, ""+doc.getRouteHeaderId(), hasPermissionByPermissionName);
200   
201    }
202    }