1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import org.junit.Test;
19 import org.kuali.rice.kew.api.KewApiServiceLocator;
20 import org.kuali.rice.kew.api.WorkflowDocument;
21 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22 import org.kuali.rice.kew.api.action.ActionRequest;
23 import org.kuali.rice.kew.api.action.ActionRequestType;
24 import org.kuali.rice.kew.api.action.AdHocRevoke;
25 import org.kuali.rice.kew.api.action.InvalidActionTakenException;
26 import org.kuali.rice.kew.api.exception.WorkflowException;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.test.KEWTestCase;
29 import org.kuali.rice.kew.test.TestUtilities;
30 import org.kuali.rice.kew.api.KewApiConstants;
31 import org.kuali.rice.kim.api.KimConstants;
32
33 import java.util.Collection;
34 import java.util.List;
35
36 import static org.junit.Assert.*;
37
38 public class RevokeAdHocActionTest extends KEWTestCase {
39
40 private static final String ADH0C_DOC = "AdhocRouteTest";
41 private String docId;
42
43 protected void loadTestData() throws Exception {
44 loadXmlFile("ActionsConfig.xml");
45 }
46
47
48
49
50 @Test public void testRevokeByActionRequestId() throws Exception {
51 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADH0C_DOC);
52 docId = doc.getDocumentId();
53 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false);
54
55
56 TestUtilities.assertNumberOfPendingRequests(docId, 1);
57 TestUtilities.assertUserHasPendingRequest(docId, "dewey");
58
59
60 try {
61 doc.revokeAdHocRequestById("123456789", "");
62 fail("Revoking by a bad action request id should have thrown an exception!");
63 } catch (InvalidActionTakenException e) {}
64
65
66 List<ActionRequest> actionRequestVOs = KewApiServiceLocator.getWorkflowDocumentService().getRootActionRequests(docId);
67 assertEquals(1, actionRequestVOs.size());
68 String actionRequestId = actionRequestVOs.get(0).getId();
69 doc.revokeAdHocRequestById(actionRequestId, "");
70
71
72 TestUtilities.assertNumberOfPendingRequests(docId, 0);
73
74
75 doc.route("");
76 doc = getDocument("user1");
77 assertTrue(doc.isApprovalRequested());
78
79
80 actionRequestVOs = KewApiServiceLocator.getWorkflowDocumentService().getRootActionRequests(docId);
81 for (int index = 0; index < actionRequestVOs.size(); index++) {
82 if (actionRequestVOs.get(index).isPending()) {
83 try {
84 doc.revokeAdHocRequestById(actionRequestVOs.get(index).getId().toString(), "");
85 fail("Attempted to revoke by an invalid action request id, should have thrown an error!");
86 } catch (InvalidActionTakenException e) {}
87 }
88 }
89
90 }
91
92
93
94
95 @Test public void testRevokeByUserAndGroup() throws Exception {
96
97 WorkflowDocument doc =WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADH0C_DOC);
98 docId = doc.getDocumentId();
99 String principalId = getPrincipalIdForName("dewey");
100 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotationDewey1", principalId, "respDesc1", false);
101 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotationDewey2", principalId, "respDesc1", false);
102 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "WorkflowAdmin");
103 doc.adHocToGroup(ActionRequestType.APPROVE, "AdHoc", "Annotation WorkflowAdmin", groupId, "respDesc2", true);
104
105 TestUtilities.assertNumberOfPendingRequests(docId, 3);
106 TestUtilities.assertUserHasPendingRequest(docId, "dewey");
107 TestUtilities.assertUserHasPendingRequest(docId, "quickstart");
108
109
110 doc.route("");
111 assertTrue(doc.isEnroute());
112 TestUtilities.assertAtNodeNew(doc, "AdHoc");
113 TestUtilities.assertNumberOfPendingRequests(docId, 3);
114
115 String testGroupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "TestWorkgroup");
116
117 AdHocRevoke revoke = AdHocRevoke.createRevokeFromPrincipal(getPrincipalIdForName("ewestfal"));
118 doc.revokeAdHocRequests(revoke, "This should be a no-op");
119 revoke = AdHocRevoke.createRevokeFromGroup(testGroupId);
120 doc.revokeAdHocRequests(revoke, "This should be a no-op");
121 doc = getDocument("rkirkend");
122 TestUtilities.assertNumberOfPendingRequests(docId, 3);
123 TestUtilities.assertUserHasPendingRequest(docId, "dewey");
124 TestUtilities.assertUserHasPendingRequest(docId, "quickstart");
125
126
127
128 revoke = AdHocRevoke.createRevokeFromPrincipal(getPrincipalIdForName("dewey"));
129 doc.revokeAdHocRequests(revoke, "revokeUser");
130 TestUtilities.assertNumberOfPendingRequests(docId, 1);
131 doc = getDocument("dewey");
132 assertFalse("dewey should no longer have an approve request.", doc.isApprovalRequested());
133 revoke = AdHocRevoke.createRevokeFromGroup(groupId);
134 doc.revokeAdHocRequests(revoke, "revokeWorkgroup");
135
136
137 doc = getDocument("user1");
138 TestUtilities.assertAtNodeNew(doc, "One");
139 assertTrue("user1 should have an approve request.", doc.isApprovalRequested());
140 doc.approve("");
141
142
143 assertTrue("doc should be final", doc.isFinal());
144 }
145
146
147
148
149 @Test public void testRevokeByNodeName() throws Exception {
150
151 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADH0C_DOC);
152 docId = doc.getDocumentId();
153 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotationDewey1", getPrincipalIdForName("dewey"), "respDesc1", false);
154 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "WorkflowAdmin");
155 doc.adHocToGroup(ActionRequestType.APPROVE, "AdHoc", "Annotation WorkflowAdmin", groupId, "respDesc2", true);
156 TestUtilities.assertNumberOfPendingRequests(docId, 2);
157
158
159 doc.revokeAdHocRequests(AdHocRevoke.createRevokeAtNode("AdHoc"), "");
160 TestUtilities.assertNumberOfPendingRequests(docId, 0);
161
162 doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "AdHoc", "annotationEwestfal1", getPrincipalIdForName("ewestfal"), "respDesc1", false);
163
164
165 doc = getDocument("rkirkend");
166 doc.route("");
167 TestUtilities.assertAtNodeNew(doc, "One");
168
169
170 doc = getDocument("ewestfal");
171 assertTrue(doc.isAcknowledgeRequested());
172
173
174 doc = getDocument("user1");
175 assertTrue(doc.isApprovalRequested());
176 doc.approve("");
177 assertTrue(doc.isProcessed());
178
179
180 doc.revokeAdHocRequests(AdHocRevoke.createRevokeAtNode("One"), "");
181 doc = getDocument("ewestfal");
182 assertTrue(doc.isProcessed());
183
184
185 doc.revokeAdHocRequests(AdHocRevoke.createRevokeAtNode("AdHoc"), "");
186 doc = getDocument("ewestfal");
187 assertTrue(doc.isFinal());
188 }
189
190
191
192
193
194
195 @Test public void testRevokePriorToRouting() throws Exception {
196
197 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADH0C_DOC);
198 docId = doc.getDocumentId();
199 doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false);
200
201 doc = getDocument("dewey");
202 assertFalse("User andlee should not have an approve request yet. Document not yet routed.", doc.isApprovalRequested());
203 String groupId = getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "WorkflowAdmin");
204 doc.adHocToGroup(ActionRequestType.APPROVE, "AdHoc", "annotation2", groupId , "respDesc2", true);
205 doc = getDocument("quickstart");
206 assertFalse("User should not have approve request yet. Document not yet routed.", doc.isApprovalRequested());
207
208
209 assertTrue("Document should still be intitiated.", doc.isInitiated());
210
211
212
213 doc = getDocument("rkirkend");
214 List<ActionRequest> actionRequestVOs = KewApiServiceLocator.getWorkflowDocumentService().getRootActionRequests(doc.getDocumentId());
215 assertEquals("There should be 2 ad hoc requests.", 2, actionRequestVOs.size());
216 for (ActionRequest requestVO : actionRequestVOs) {
217 assertTrue("Should be an ad hoc request.", requestVO.isAdHocRequest());
218
219 doc.revokeAdHocRequestById(requestVO.getId().toString(), "");
220 }
221
222
223 List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(docId);
224 assertEquals("There should be no pending requests.", 0, actionRequests.size());
225
226
227 Collection actionTakens = KEWServiceLocator.getActionTakenService().findByDocIdAndAction(docId, KewApiConstants.ACTION_TAKEN_ADHOC_REVOKED_CD);
228 assertEquals("There should be 2 'AdHocRevoked' action takens", 2, actionTakens.size());
229
230
231 doc = getDocument("rkirkend");
232 assertTrue("Document should still be intitiated.", doc.isInitiated());
233 }
234
235
236
237
238
239 @Test public void testRevokeAfterBlanketApprove() throws Exception {
240 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADH0C_DOC);
241 docId = doc.getDocumentId();
242
243 doc.adHocToPrincipal(ActionRequestType.FYI, "AdHoc", "annotationEwestfal1", getPrincipalIdForName("ewestfal"), "respDesc1", false);
244
245
246 doc.blanketApprove("");
247 assertTrue(doc.isProcessed());
248
249
250 doc = getDocument("ewestfal");
251 assertTrue(doc.isFYIRequested());
252 doc = getDocument("user1");
253 assertTrue(doc.isAcknowledgeRequested());
254
255
256 doc.revokeAllAdHocRequests("revoking all adhocs");
257 assertTrue(doc.isProcessed());
258 TestUtilities.assertNumberOfPendingRequests(docId, 1);
259
260
261 assertTrue(doc.isAcknowledgeRequested());
262
263
264 doc = getDocument("ewestfal");
265 assertFalse(doc.isFYIRequested());
266 }
267
268 private WorkflowDocument getDocument(String netid) throws WorkflowException {
269 return WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(netid), docId);
270 }
271
272 }