1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
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 |
|
|
35 |
|
|
36 |
|
@author |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 116 (116) |
Complexity: 5 |
Complexity Density: 0.05 |
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
44 |
0
|
@Override... |
45 |
|
public void setUp() throws Exception { |
46 |
0
|
super.setUp(); |
47 |
0
|
loadXmlFile("BasicPermissionsTestConfig.xml"); |
48 |
|
} |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
50 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 103 (103) |
Complexity: 1 |
Complexity Density: 0.01 |
4
-
|
|
63 |
0
|
@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 |
|
|
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 |
|
|
80 |
0
|
doc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", "testuser3", "", true); |
81 |
|
|
82 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
134 |
0
|
principalId = "fred"; |
135 |
0
|
doc = new WorkflowDocument(principalId, doc.getRouteHeaderId()); |
136 |
0
|
doc.approve(""); |
137 |
|
|
138 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
184 |
0
|
doc.acknowledge(""); |
185 |
|
|
186 |
|
|
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 |
|
|
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 |
|
} |