1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
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 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 116 (116) |
Complexity: 5 |
Complexity Density: 0.05 |
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
0
|
@Override... |
42 |
|
public void setUp() throws Exception { |
43 |
0
|
super.setUp(); |
44 |
0
|
loadXmlFile("BasicPermissionsTestConfig.xml"); |
45 |
|
} |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
47 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 103 (103) |
Complexity: 1 |
Complexity Density: 0.01 |
4
-
|
|
60 |
0
|
@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 |
|
|
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 |
|
|
77 |
0
|
doc.adHocRouteDocumentToPrincipal(KEWConstants.ACTION_REQUEST_APPROVE_REQ, "", "testuser3", "", true); |
78 |
|
|
79 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
131 |
0
|
principalId = "fred"; |
132 |
0
|
doc = new WorkflowDocument(principalId, doc.getRouteHeaderId()); |
133 |
0
|
doc.approve(""); |
134 |
|
|
135 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
181 |
0
|
doc.acknowledge(""); |
182 |
|
|
183 |
|
|
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 |
|
|
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 |
|
} |