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 java.util.Iterator;
19 import java.util.List;
20
21 import javax.xml.namespace.QName;
22
23 import junit.framework.Assert;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.junit.Test;
27 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
28 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
29 import org.kuali.rice.kew.dto.ActionItemDTO;
30 import org.kuali.rice.kew.exception.WorkflowException;
31 import org.kuali.rice.kew.service.KEWServiceLocator;
32 import org.kuali.rice.kew.service.WorkflowDocument;
33 import org.kuali.rice.kew.test.KEWTestCase;
34 import org.kuali.rice.kew.test.TestUtilities;
35 import org.kuali.rice.kew.util.KEWWebServiceConstants;
36 import org.kuali.rice.kew.webservice.DocumentResponse;
37 import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService;
38 import org.kuali.rice.kew.webservice.StandardResponse;
39 import org.kuali.rice.kim.bo.Group;
40
41
42
43
44
45
46
47
48 public class SimpleDocumentActionsWebServiceTest extends KEWTestCase {
49
50 @Override
51 protected void loadTestData() throws Exception {
52 loadXmlFile("ActionsConfig.xml");
53 }
54
55 protected SimpleDocumentActionsWebService getSimpleDocumentActionsWebService() {
56 return (SimpleDocumentActionsWebService) GlobalResourceLoader.getService(new QName(KEWWebServiceConstants.MODULE_TARGET_NAMESPACE, KEWWebServiceConstants.SimpleDocumentActionsWebService.WEB_SERVICE_NAME));
57 }
58
59 @Test
60 public void testCreateAndRoute() throws Exception{
61
62 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
63 DocumentResponse dr = simpleService.create("admin","doc1", "BlanketApproveSequentialTest", "Doc1Title");
64 StandardResponse sr = simpleService.route(dr.getDocId(), "admin", "Doc1Title", "<foo>bar</foo>", "Annotation!");
65 sr = simpleService.approve(dr.getDocId(), "admin", "Doc1Title", "<foo>b</foo>", "Annotation!!!");
66 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
67
68 }
69
70 @Test
71 public void testSave_NoDocContent() throws Exception{
72
73 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
74 DocumentResponse dr = simpleService.create("admin","doc1", "BlanketApproveSequentialTest", "Doc1Title");
75 String docId = dr.getDocId();
76 assertTrue(StringUtils.isEmpty(dr.getErrorMessage()));
77 StandardResponse sr = simpleService.save(dr.getDocId(), "admin", "Doc1Title", null, "Annotation!");
78 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
79 sr = simpleService.approve(dr.getDocId(), "admin", "Doc1Title", "<foo>b</foo>", "Annotation!!!");
80 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
81 }
82
83 @Test
84 public void testSave_WithDocContent() throws Exception{
85
86 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
87 DocumentResponse dr = simpleService.create("admin","doc1", "BlanketApproveSequentialTest", "Doc1Title");
88 String docId = dr.getDocId();
89 assertTrue(StringUtils.isEmpty(dr.getErrorMessage()));
90 String docContent1 = "<foo>bar</foo>";
91 String docTitle1 = "Doc1Title";
92 StandardResponse sr = simpleService.save(dr.getDocId(), "admin", docTitle1, docContent1, "Annotation!");
93 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
94 verifyDocumentDataChanges(simpleService, docId, docContent1, docTitle1);
95 String docContent2 = "<foo>b</foo>";
96 String docTitle2 = "Doc2Title";
97 sr = simpleService.approve(dr.getDocId(), "admin", docTitle2, docContent2, "Annotation!!!");
98 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
99 verifyDocumentDataChanges(simpleService, docId, docContent2, docTitle2);
100
101 }
102
103 @Test
104 public void testSaveDocContent() throws Exception{
105 String docTitle1 = "Doc1Title";
106 String docTitle2 = "Doc2Title";
107
108 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
109 DocumentResponse dr = simpleService.create(getPrincipalIdForName("admin"),"doc1", "BlanketApproveSequentialTest", "Doc1Title");
110 assertTrue(StringUtils.isEmpty(dr.getErrorMessage()));
111
112 assertTrue("doc content should be empty", ((dr.getDocContent() == null) || (StringUtils.isBlank(dr.getDocContent()))));
113 assertEquals("doc title is wrong", docTitle1, dr.getTitle());
114 String docId = dr.getDocId();
115 String docContent = "<foo>bar</foo>";
116 StandardResponse sr = simpleService.saveDocumentContent(docId, getPrincipalIdForName("admin"), docTitle2, docContent);
117 assertTrue(StringUtils.isEmpty(sr.getErrorMessage()));
118 verifyDocumentDataChanges(simpleService, docId, docContent, docTitle2);
119 }
120
121 protected void verifySuccess(StandardResponse sr) {
122 assertTrue("response was invalid with error message: " + sr.getErrorMessage(), StringUtils.isEmpty(sr.getErrorMessage()));
123 }
124
125 protected void verifyDocumentDataChanges(SimpleDocumentActionsWebService simpleService, String docId, String newDocContent, String newDocTitle) throws Exception {
126 DocumentResponse dr = simpleService.getDocument(docId, getPrincipalIdForName("admin"));
127 verifySuccess(dr);
128
129 assertEquals("doc content value is incorrect", newDocContent, dr.getDocContent());
130
131 assertEquals("doc title should have changed", newDocTitle, dr.getTitle());
132 }
133
134 protected String createAndRouteDocument(SimpleDocumentActionsWebService simpleService, String docTitle, String docContent) throws Exception {
135 DocumentResponse dr = simpleService.create(getPrincipalIdForName("admin"),"doc1", "BlanketApproveSequentialTest", docTitle);
136 verifySuccess(dr);
137 StandardResponse sr = simpleService.route(dr.getDocId(), getPrincipalIdForName("admin"), docTitle, docContent, "Annotation!");
138 verifySuccess(sr);
139 return dr.getDocId();
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 protected static void assertNumberOfPendingAdHocRequests(Long documentId, int expectedNumberOfPendingAdHocRequests) {
165 int actualPendingAdHocRequests = 0;
166 List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(documentId);
167 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
168 ActionRequestValue actionRequest = (ActionRequestValue) iterator.next();
169 if (actionRequest.isAdHocRequest()) {
170 actualPendingAdHocRequests++;
171 }
172 }
173 Assert.assertEquals("Wrong number of pending requests for document: " + documentId, expectedNumberOfPendingAdHocRequests, actualPendingAdHocRequests);
174 }
175
176 @Test
177 public void testRevokeAdHocRequestsByNodeName() throws Exception {
178 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
179 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
180
181 StandardResponse sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fran"), "");
182 verifySuccess(sr);
183 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("delyea"), "");
184 verifySuccess(sr);
185
186 sr = simpleService.approve(docId, getPrincipalIdForName("bmcgough"), "newDocTitle", "<foobar>test</foobar>", "");
187 verifySuccess(sr);
188 sr = simpleService.approve(docId, getPrincipalIdForName("rkirkend"), "newDocTitle", "<foobar>test</foobar>", "");
189 verifySuccess(sr);
190
191 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fred"), "");
192 verifySuccess(sr);
193
194 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 3);
195 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "delyea");
196 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
197 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fran");
198 String newDocTitle = "newestDocTitle";
199 String newDocContent = "<foobar>testerIsNew</foobar>";
200 sr = simpleService.revokeAdHocRequestsByNodeName(docId, getPrincipalIdForName("pmckown"), newDocTitle, newDocContent, "WorkflowDocument", "");
201 verifySuccess(sr);
202 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
203
204 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 1);
205 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
206 TestUtilities.assertNotInActionList(getPrincipalIdForName("delyea"), Long.valueOf(docId));
207 TestUtilities.assertNotInActionList(getPrincipalIdForName("fran"), Long.valueOf(docId));
208 }
209
210 @Test
211 public void testRevokeAdHocRequestsByPrincipalId() throws Exception {
212 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
213 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
214
215 StandardResponse sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fran"), "");
216 verifySuccess(sr);
217 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fred"), "");
218 verifySuccess(sr);
219
220 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 2);
221 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
222 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fran");
223
224 String newDocTitle = "newestDocTitle";
225 String newDocContent = "<foobar>testerIsNew</foobar>";
226 sr = simpleService.revokeAdHocRequestsByPrincipalId(docId, getPrincipalIdForName("admin"), newDocTitle, newDocContent, getPrincipalIdForName("fran"), "");
227 verifySuccess(sr);
228 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
229
230 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 1);
231 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
232 TestUtilities.assertNotInActionList(getPrincipalIdForName("fran"), Long.valueOf(docId));
233 }
234
235 @Test
236 public void testRevokeAdHocRequestsByGroupId() throws Exception {
237 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
238 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
239
240 String groupNamespaceCode = "KR-WKFLW";
241 String groupName = "NonSIT";
242 StandardResponse sr = simpleService.requestAdHocAckToGroup(docId, getPrincipalIdForName("admin"), getGroupIdForName(groupNamespaceCode, groupName), "");
243 verifySuccess(sr);
244 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fred"), "");
245 verifySuccess(sr);
246
247 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 2);
248 assertTrue("group should have pending request", doesGroupHavePendingRequest(docId, groupNamespaceCode, groupName));
249
250 String newDocTitle = "newestDocTitle";
251 String newDocContent = "<foobar>testerIsNew</foobar>";
252 sr = simpleService.revokeAdHocRequestsByGroupId(docId, getPrincipalIdForName("admin"), newDocTitle, newDocContent, getGroupIdForName("KR-WKFLW", "NonSIT"), "");
253 verifySuccess(sr);
254 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
255
256 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 1);
257 assertFalse("group should not have pending request", doesGroupHavePendingRequest(docId, groupNamespaceCode, groupName));
258 }
259
260
261
262
263 public boolean doesGroupHavePendingRequest(String documentId, String groupNamespaceCode, String groupName) throws WorkflowException {
264 Group group = KEWServiceLocator.getIdentityHelperService().getGroupByName(groupNamespaceCode, groupName);
265 assertNotNull("group not found for namespace '" + groupNamespaceCode + "' and name '" + groupName, group);
266 List actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(Long.valueOf(documentId));
267 boolean foundRequest = false;
268 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
269 ActionRequestValue actionRequest = (ActionRequestValue) iterator.next();
270 if ( (actionRequest.isGroupRequest()) && (StringUtils.equals(group.getGroupId(),actionRequest.getGroupId())) ) {
271 return true;
272 }
273 }
274 return false;
275 }
276
277 @Test
278 public void testRevokeAdHocRequestsByActionRequestId() throws Exception {
279 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
280 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
281
282 StandardResponse sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fran"), "");
283 verifySuccess(sr);
284 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("delyea"), "");
285 verifySuccess(sr);
286
287 sr = simpleService.approve(docId, getPrincipalIdForName("bmcgough"), "newDocTitle", "<foobar>test</foobar>", "");
288 verifySuccess(sr);
289 sr = simpleService.approve(docId, getPrincipalIdForName("rkirkend"), "newDocTitle", "<foobar>test</foobar>", "");
290 verifySuccess(sr);
291
292 sr = simpleService.requestAdHocAckToPrincipal(docId, getPrincipalIdForName("admin"), getPrincipalIdForName("fred"), "");
293 verifySuccess(sr);
294
295 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 3);
296 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "delyea");
297 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
298 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fran");
299
300 String newDocTitle = "newestDocTitle";
301 String newDocContent = "<foobar>testerIsNew</foobar>";
302 ActionItemDTO[] actionItems = KEWServiceLocator.getWorkflowUtilityService().getActionItemsForPrincipal(getPrincipalIdForName("delyea"));
303 assertEquals("incorrect number of action items for user", 1, actionItems.length);
304 sr = simpleService.revokeAdHocRequestsByActionRequestId(docId, getPrincipalIdForName("admin"), newDocTitle, newDocContent, actionItems[0].getActionRequestId().toString(), "");
305 verifySuccess(sr);
306 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
307
308 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 2);
309 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
310 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fran");
311 TestUtilities.assertNotInActionList(getPrincipalIdForName("delyea"), Long.valueOf(docId));
312
313 actionItems = KEWServiceLocator.getWorkflowUtilityService().getActionItemsForPrincipal(getPrincipalIdForName("fran"));
314 assertEquals("incorrect number of action items for user", 1, actionItems.length);
315 sr = simpleService.revokeAdHocRequestsByActionRequestId(docId, getPrincipalIdForName("admin"), newDocTitle, newDocContent, actionItems[0].getActionRequestId().toString(), "");
316 verifySuccess(sr);
317
318 assertNumberOfPendingAdHocRequests(Long.valueOf(docId), 1);
319 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "fred");
320 TestUtilities.assertNotInActionList(getPrincipalIdForName("delyea"), Long.valueOf(docId));
321 TestUtilities.assertNotInActionList(getPrincipalIdForName("fran"), Long.valueOf(docId));
322 }
323
324 protected void verifySuperUser(SimpleDocumentActionsWebService simpleService, String docId, String principalName) throws Exception {
325 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName(principalName), Long.valueOf(docId));
326 assertTrue(principalName + " should be a super user", doc.isSuperUser());
327 }
328
329 protected void verifyNotSuperUser(SimpleDocumentActionsWebService simpleService, String docId, String principalName) throws Exception {
330 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName(principalName), Long.valueOf(docId));
331 assertFalse(principalName + " should not be a super user", doc.isSuperUser());
332 }
333
334 @Test
335 public void testSuperUserApprove() throws Exception {
336 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
337 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
338 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
339
340
341 String notSuperUserPrincipalName = "fred";
342 verifyNotSuperUser(simpleService, docId, notSuperUserPrincipalName);
343 StandardResponse sr = simpleService.superUserApprove(docId, getPrincipalIdForName(notSuperUserPrincipalName), null, null, "");
344 if ( (sr.getErrorMessage() == null) || StringUtils.isBlank(sr.getErrorMessage()) ) {
345 fail("document was successfully approved by invalid super user");
346 }
347
348
349 String superUserPrincipalName = "shenl";
350 verifySuperUser(simpleService, docId, superUserPrincipalName);
351 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName(superUserPrincipalName), Long.valueOf(docId)), "WorkflowDocument");
352
353 String newDocTitle = "newestDocTitle";
354 String newDocContent = "<foobar>testerIsNew</foobar>";
355 sr = simpleService.superUserApprove(docId, getPrincipalIdForName(superUserPrincipalName), newDocTitle, newDocContent, "");
356 verifySuccess(sr);
357 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
358
359 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName(superUserPrincipalName), Long.valueOf(docId));
360 assertTrue("state of the document should be final", doc.stateIsProcessed());
361 }
362
363 @Test
364 public void testSuperUserDisapprove() throws Exception {
365 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
366 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
367 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
368
369
370 String notSuperUserPrincipalName = "fred";
371 verifyNotSuperUser(simpleService, docId, notSuperUserPrincipalName);
372 StandardResponse sr = simpleService.superUserDisapprove(docId, getPrincipalIdForName(notSuperUserPrincipalName), null, null, "");
373 if ( (sr.getErrorMessage() == null) || StringUtils.isBlank(sr.getErrorMessage()) ) {
374 fail("document was successfully disapproved by invalid super user");
375 }
376
377
378 String superUserPrincipalName = "shenl";
379 verifySuperUser(simpleService, docId, superUserPrincipalName);
380 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName(superUserPrincipalName), Long.valueOf(docId)), "WorkflowDocument");
381
382 String newDocTitle = "newestDocTitle";
383 String newDocContent = "<foobar>testerIsNew</foobar>";
384 sr = simpleService.superUserDisapprove(docId, getPrincipalIdForName(superUserPrincipalName), newDocTitle, newDocContent, "");
385 verifySuccess(sr);
386 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
387 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName(superUserPrincipalName),Long.valueOf(docId));
388 assertTrue("document should be disapproved", doc.stateIsDisapproved());
389 }
390
391 @Test
392 public void testSuperUserCancel() throws Exception {
393 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
394 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
395 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
396
397
398 String notSuperUserPrincipalName = "fred";
399 verifyNotSuperUser(simpleService, docId, notSuperUserPrincipalName);
400 StandardResponse sr = simpleService.superUserCancel(docId, getPrincipalIdForName(notSuperUserPrincipalName), null, null, "");
401 if ( (sr.getErrorMessage() == null) || StringUtils.isBlank(sr.getErrorMessage()) ) {
402 fail("document was successfully cancelled by invalid super user");
403 }
404
405
406 String superUserPrincipalName = "shenl";
407 verifySuperUser(simpleService, docId, superUserPrincipalName);
408
409 String newDocTitle = "newestDocTitle";
410 String newDocContent = "<foobar>testerIsNew</foobar>";
411 sr = simpleService.superUserCancel(docId, getPrincipalIdForName(superUserPrincipalName), newDocTitle, newDocContent, "");
412 verifySuccess(sr);
413 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
414 WorkflowDocument doc = new WorkflowDocument(getPrincipalIdForName(superUserPrincipalName),Long.valueOf(docId));
415 assertTrue("document should be cancelled", doc.stateIsCanceled());
416 }
417
418 @Test
419 public void testReturnToPrevious() throws Exception {
420 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
421 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
422 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
423 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "bmcgough");
424 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "rkirkend");
425
426 StandardResponse sr = simpleService.approve(docId, getPrincipalIdForName("bmcgough"), "newDocTitle", "<foobar>test</foobar>", "");
427 verifySuccess(sr);
428 sr = simpleService.approve(docId, getPrincipalIdForName("rkirkend"), "newDocTitle", "<foobar>test</foobar>", "");
429 verifySuccess(sr);
430
431 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument2");
432 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "pmckown");
433 TestUtilities.assertNotInActionList(getPrincipalIdForName("bmcgough"), Long.valueOf(docId));
434 TestUtilities.assertNotInActionList(getPrincipalIdForName("rkirkend"), Long.valueOf(docId));
435
436
437 sr = simpleService.returnToPreviousNodeWithUpdates(docId, getPrincipalIdForName("delyea"), "", "WorkflowDocument", null, null);
438 if ( (sr.getErrorMessage() == null) || StringUtils.isBlank(sr.getErrorMessage())) {
439 fail("document was successfully returned to previous by invalid user");
440 }
441
442
443 String newDocTitle = "newestDocTitle";
444 String newDocContent = "<foobar>testerIsNew</foobar>";
445 sr = simpleService.returnToPreviousNodeWithUpdates(docId, getPrincipalIdForName("pmckown"), "", "WorkflowDocument", newDocTitle, newDocContent);
446 verifySuccess(sr);
447 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
448
449 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
450 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "bmcgough");
451 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "rkirkend");
452 TestUtilities.assertNotInActionList(getPrincipalIdForName("pmckown"), Long.valueOf(docId));
453 }
454
455 @Test
456 public void testSuperUserReturnToPrevious() throws Exception {
457 SimpleDocumentActionsWebService simpleService = getSimpleDocumentActionsWebService();
458 String docId = createAndRouteDocument(simpleService, "Doc1Title", "<foo>bar</foo>");
459 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
460 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "bmcgough");
461 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "rkirkend");
462
463 StandardResponse sr = simpleService.approve(docId, getPrincipalIdForName("bmcgough"), "newDocTitle", "<foobar>test</foobar>", "");
464 verifySuccess(sr);
465 sr = simpleService.approve(docId, getPrincipalIdForName("rkirkend"), "newDocTitle", "<foobar>test</foobar>", "");
466 verifySuccess(sr);
467
468 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument2");
469 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "pmckown");
470 TestUtilities.assertNotInActionList(getPrincipalIdForName("bmcgough"), Long.valueOf(docId));
471 TestUtilities.assertNotInActionList(getPrincipalIdForName("rkirkend"), Long.valueOf(docId));
472
473
474 sr = simpleService.superUserReturnToPrevious(docId, getPrincipalIdForName("delyea"), null, null, "WorkflowDocument", "");
475 if ( (sr.getErrorMessage() == null) || StringUtils.isBlank(sr.getErrorMessage())) {
476 fail("document was successfully returned to previous by invalid user");
477 }
478
479
480 String newDocTitle = "newestDocTitle";
481 String newDocContent = "<foobar>testerIsNew</foobar>";
482 String superUserPrincipalName = "shenl";
483 verifySuperUser(simpleService, docId, superUserPrincipalName);
484 sr = simpleService.superUserReturnToPrevious(docId, getPrincipalIdForName(superUserPrincipalName), newDocTitle, newDocContent, "WorkflowDocument", "");
485 verifySuccess(sr);
486 verifyDocumentDataChanges(simpleService, docId, newDocContent, newDocTitle);
487
488 TestUtilities.assertAtNode(new WorkflowDocument(getPrincipalIdForName("admin"), Long.valueOf(docId)), "WorkflowDocument");
489 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "bmcgough");
490 TestUtilities.assertUserHasPendingRequest(Long.valueOf(docId), "rkirkend");
491 }
492
493 }