View Javadoc

1   /*
2    * Copyright 2006-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actions;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kew.actionitem.ActionItem;
20  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
21  import org.kuali.rice.kew.api.WorkflowDocument;
22  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23  import org.kuali.rice.kew.api.action.ActionRequest;
24  import org.kuali.rice.kew.api.action.ActionRequestStatus;
25  import org.kuali.rice.kew.api.action.ActionRequestType;
26  import org.kuali.rice.kew.api.action.AdHocToPrincipal;
27  import org.kuali.rice.kew.api.action.RecipientType;
28  import org.kuali.rice.kew.exception.WorkflowException;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kew.test.KEWTestCase;
31  import org.kuali.rice.kew.test.TestUtilities;
32  import org.kuali.rice.kim.api.KimConstants;
33  import org.kuali.rice.kim.api.group.Group;
34  import org.kuali.rice.kim.api.identity.Person;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  import org.kuali.rice.test.BaselineTestCase;
37  
38  import java.util.ArrayList;
39  import java.util.Collection;
40  import java.util.Iterator;
41  import java.util.List;
42  
43  import static org.junit.Assert.*;
44  
45  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
46  public class AdHocRouteTest extends KEWTestCase {
47  
48  	private static final String ADHOC_DOC = "AdhocRouteTest";
49  	private static final String ADHOC_NO_NODE_DOC = "AdHocNoNodeTest";
50      private static final String ADHOC_PRIORITY_PARALLEL_DOC = "AdhocRouteTest-PriorityParallel";
51  	private String docId;
52  
53      protected void loadTestData() throws Exception {
54          loadXmlFile("ActionsConfig.xml");
55      }
56  
57      @Test
58      public void testRequestLabel() throws Exception{
59      	String note = "test note";
60      	Person per = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("rkirkend");
61      	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(per.getPrincipalId(), ADHOC_DOC);
62  
63      	docId = doc.getDocumentId();
64  
65      	doc.adHocToPrincipal(ActionRequestType.FYI, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false, note);
66  
67      	doc = getDocument(per.getPrincipalId(), docId);
68      	List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(docId);
69      	for(ActionRequestValue arv : actionRequests){
70      		assertTrue("The note we passed in should equal the one we get out. note=["+ note +"]", note.equals(arv.getRequestLabel()));
71      	}
72      }
73  
74  	@Test
75  	public void testParallelAdHocRouting() throws Exception {
76      	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
77      	docId = doc.getDocumentId();
78      	doc.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "annotation1", getPrincipalIdForName("dewey"), "respDesc1", false);
79  
80      	doc = getDocument("dewey");
81      	assertFalse("User andlee should not have an approve request yet.  Document not yet routed.", doc.isApprovalRequested());
82  
83      	doc.adHocToGroup(ActionRequestType.APPROVE, "AdHoc", "annotation2", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "WorkflowAdmin"), "respDesc2", true);
84  
85      	doc = getDocument("quickstart");
86      	assertFalse("User should not have approve request yet.  Document not yet routed.", doc.isApprovalRequested());
87  
88      	doc = getDocument("rkirkend");
89      	doc.route("");
90  
91      	// there should be two adhoc requests
92      	List<ActionRequest> actionRequests = doc.getRootActionRequests();
93      	for (ActionRequest actionRequest : actionRequests) {
94      		assertTrue("Request should be an adhoc request.", actionRequest.isAdHocRequest());
95      	}
96  
97      	//all users should now have active approvals
98      	WorkflowDocument deweyDoc = getDocument("dewey");
99      	assertTrue("Dewey should have an approve request", deweyDoc.isApprovalRequested());
100 
101 		doc = getDocument("ewestfal");// test that more than 1 member got
102 										// requests
103     	assertTrue("WorkflowAdmin should have an approve request", doc.isApprovalRequested());
104 
105     	deweyDoc.approve("");
106     	doc.approve("");
107     	doc = getDocument("user1");//this dude has a rule in ActionsConfig.xml
108     	doc.approve("");
109     	assertTrue("The document should be final", doc.isFinal());
110     }
111 
112     /**
113 	 * Test generation of an initial ad-hoc request to initiator prior to
114 	 * routing.
115      *
116      * This test will fail until EN-643 is resolved.
117      */
118 	@Test
119 	public void testAdHocToInitiator() throws Exception {
120         final String ADHOC_NODE = "AdHoc";
121         WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
122         docId = doc.getDocumentId();
123         doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", true);
124 
125         doc.route("");
126         assertTrue(doc.isEnroute());
127 
128         doc = getDocument("rkirkend");
129         assertTrue("rkirkend should have an approval request on the document", doc.isApprovalRequested());
130         TestUtilities.assertAtNodeNew(doc, ADHOC_NODE);
131 
132         // now try it with force action=false
133         doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
134         docId = doc.getDocumentId();
135         doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", false);
136 
137         doc.route("");
138         assertTrue(doc.isEnroute());
139 
140         doc = getDocument("rkirkend");
141         assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
142         TestUtilities.assertAtNodeNew(doc, "One");
143         doc = getDocument("user1");
144         assertTrue("user1 should have an approval request on the document", doc.isApprovalRequested());
145     }
146 
147 	@Test
148 	public void testSerialAdHocRouting() throws Exception {
149     	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
150     	docId = doc.getDocumentId();
151     	doc.route("");
152     	doc = getDocument("user1");
153     	doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("user2"), "", false);
154     	doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("rkirkend"), "", true);
155     	doc.approve("");
156     	doc = getDocument("rkirkend");
157     	assertFalse("rkirkend should not have the document at this point 'S' activation", doc.isApprovalRequested());
158     	doc = getDocument("user2");
159     	assertTrue("user2 should have an approve request", doc.isApprovalRequested());
160     	doc.approve("");
161     	doc = getDocument("rkirkend");
162     	doc.approve("");
163     	assertTrue("The document should be final", doc.isFinal());
164     }
165 
166 	@Test
167     public void testRepeatedAdHocRouting() throws Exception {
168         final String ADHOC_NODE = "AdHoc";
169         WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
170         docId = doc.getDocumentId();
171         doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("user2"), "", false);
172         doc.route("");
173         doc = getDocument("rkirkend");
174         assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
175         // user1 shouldn't have an approve request YET - to prove that we have not yet advanced past this initial AdHoc node
176         doc = getDocument("user1");
177         assertFalse("user1 should NOT have an approval request on the document", doc.isApprovalRequested());
178 
179         doc = getDocument("user2");
180         assertTrue("user2 should have an approval request on document", doc.isApprovalRequested());
181         doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("user3"), "", false);
182         doc.approve("");
183         doc = getDocument("user2");
184         assertFalse("user2 should NOT have an approval request on the document", doc.isApprovalRequested());
185 
186         doc = getDocument("user3");
187         assertTrue("user3 should have an approval request on document", doc.isApprovalRequested());
188         doc.adHocToPrincipal(ActionRequestType.APPROVE, ADHOC_NODE, "annotation1", getPrincipalIdForName("rkirkend"), "", true);
189         doc.approve("");
190         doc = getDocument("user3");
191         assertFalse("user3 should NOT have an approval request on the document", doc.isApprovalRequested());
192 
193         doc = getDocument("rkirkend");
194         assertTrue("rkirkend should have an approval request on document", doc.isApprovalRequested());
195         doc.approve("");
196         doc = getDocument("rkirkend");
197         assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
198 
199         // the last node that is defined on the doc goes to user1
200         doc = getDocument("user1");
201         assertTrue("user1 should have an approval request on document", doc.isApprovalRequested());
202         doc.approve("");
203         doc = getDocument("user1");
204         assertFalse("user1 should NOT have an approval request on the document", doc.isApprovalRequested());
205 
206         // just to be extra sure...let's double check those other ad-hoc-ees
207         doc = getDocument("rkirkend");
208         assertFalse("rkirkend should NOT have an approval request on the document", doc.isApprovalRequested());
209         doc = getDocument("user2");
210         assertFalse("user2 should NOT have an approval request on the document", doc.isApprovalRequested());
211         doc = getDocument("user3");
212         assertFalse("user3 should NOT have an approval request on the document", doc.isApprovalRequested());
213 
214         assertTrue("The document should be final", doc.isFinal());
215     }
216 
217     @Test public void testAdHocWhenDocumentIsInitiated() throws Exception {
218     	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
219         document.saveDocumentData();
220         assertTrue(document.isInitiated());
221 
222         document.adHocToPrincipal(ActionRequestType.APPROVE, "My Annotation", getPrincipalIdForName("rkirkend"), "", true);
223         document.adHocToPrincipal(ActionRequestType.FYI, "My Annotation", getPrincipalIdForName("user1"), "", true);
224 
225         // this is an initiated document, the requests should not be activated yet
226         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
227         assertFalse(document.isApprovalRequested());
228         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
229         assertFalse(document.isFYIRequested());
230 
231         // now route the document, the requests should be activated
232         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
233         document.route("");
234         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
235         assertTrue(document.isApprovalRequested());
236         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
237         assertTrue(document.isFYIRequested());
238     }
239 
240     @Test public void testAdHocWhenDocumentIsFinal() throws Exception {
241         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
242         document.route("");
243         TestUtilities.assertAtNodeNew(document, "WorkgroupByDocument");
244 
245         try {
246         	document.adHocToPrincipal(ActionRequestType.APPROVE, "AdHoc", "", getPrincipalIdForName("ewestfal"), "", true);
247         	fail("document should not be allowed to route to nodes that are complete");
248 		} catch (Exception e) {
249 		}
250 
251 
252         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
253         assertTrue("rkirkend should have request", document.isApprovalRequested());
254         document.approve("");
255 
256         assertTrue("Document should be final", document.isFinal());
257 
258         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("user1"), document.getDocumentId());
259         List<ActionRequest> requests = document.getRootActionRequests();
260         for (ActionRequest request : requests) {
261 			if (request.isActivated()) {
262 				fail("Active requests should not be present on a final document");
263 			}
264 		}
265 
266         // try and adhoc a request to a final document, should blow up
267         try {
268         	document.adHocToPrincipal(ActionRequestType.APPROVE, "WorkgroupByDocument", "", getPrincipalIdForName("ewestfal"), "", true);
269         	fail("Should not be allowed to adhoc approve to a final document.");
270         } catch (Exception e) {
271 
272         }
273 
274         // it should be legal to adhoc an FYI on a FINAL document
275         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
276         assertFalse("rkirkend should not have an FYI request.", document.isFYIRequested());
277     	document.adHocToPrincipal(ActionRequestType.FYI, "WorkgroupByDocument", "", getPrincipalIdForName("rkirkend"), "", true);
278     	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
279     	assertTrue("rkirkend should have an FYI request", document.isFYIRequested());
280     }
281 
282     @Test public void testAdHocWhenDocumentIsSaved() throws Exception {
283     	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TakeWorkgroupAuthorityDoc");
284         document.saveDocument("");
285 
286         // TODO test adhocing of approve requests
287 
288         assertTrue("Document should be saved.", document.isSaved());
289     	document.adHocToPrincipal(ActionRequestType.FYI, "AdHoc", "", getPrincipalIdForName("rkirkend"), "", true);
290     	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
291     	assertTrue("rkirkend should have an FYI request", document.isFYIRequested());
292     }
293 
294     @Test public void testAdHocFieldsSavedCorrectly() throws Exception  {
295     	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
296     	docId = doc.getDocumentId();
297     	doc.route("");
298     	// find all current request and get a list of ids for elimination purposes later
299     	List<String> oldRequestIds = new ArrayList<String>();
300         for (Iterator iterator = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(doc.getDocumentId()).iterator(); iterator.hasNext();) {
301             oldRequestIds.add(((ActionRequestValue) iterator.next()).getActionRequestId());
302         }
303 
304         // send the adhoc route request
305         doc = getDocument("user1");
306     	doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "annotation1", getPrincipalIdForName("user2"), "respDesc", false);
307 
308     	// adhoc request should be only new request on document
309     	ActionRequestValue request = null;
310     	for (Iterator iter = KEWServiceLocator.getActionRequestService().findAllActionRequestsByDocumentId(doc.getDocumentId()).iterator(); iter.hasNext();) {
311             ActionRequestValue actionRequest = (ActionRequestValue) iter.next();
312             if (!oldRequestIds.contains(actionRequest.getActionRequestId())) {
313                 request = actionRequest;
314                 break;
315             }
316         }
317     	assertNotNull("Could not find adhoc routed action request", request);
318 
319     	// verify request data
320         assertEquals("wrong person", request.getPrincipalId(), getPrincipalIdForName("user2"));
321     	assertEquals("annotation incorrect", "annotation1", request.getAnnotation());
322     	assertEquals("action requested code incorrect", request.getActionRequested(), ActionRequestType.APPROVE.getCode());
323     	assertEquals("responsibility desc incorrect", request.getResponsibilityDesc(), "respDesc");
324     	assertEquals("wrong force action", request.getForceAction(), Boolean.FALSE);
325 
326     }
327 
328 	@Test
329 	public void testAdHocDissaprovedDocument() throws Exception {
330     	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), ADHOC_DOC);
331     	docId = doc.getDocumentId();
332     	doc.route("");
333 
334     	doc = getDocument("user1");
335     	TestUtilities.assertAtNodeNew(doc, "One");
336     	doc.disapprove("");
337     	TestUtilities.assertAtNodeNew(doc, "One");
338     	//adhoc an ack and fyi
339 
340     	doc.adHocToPrincipal(ActionRequestType.FYI, "One", "", getPrincipalIdForName("rkirkend"), "", true);
341     	doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "One", "", getPrincipalIdForName("user2"), "", true);
342 
343     	doc = getDocument("rkirkend");
344     	assertTrue(doc.isFYIRequested());
345     	doc.fyi();
346     	doc = getDocument("user2");
347     	assertTrue(doc.isAcknowledgeRequested());
348     	doc.acknowledge("");
349 
350     	//make sure we cant ad hoc approves or completes
351     	doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), ADHOC_DOC);
352     	docId = doc.getDocumentId();
353     	doc.route("");
354 
355     	doc = getDocument("user1");
356     	doc.disapprove("");
357 
358     	// try to ad hoc an approve request
359     	try {
360     		doc.adHocToPrincipal(ActionRequestType.APPROVE, "One", "", getPrincipalIdForName("rkirkend"), "", true);
361     		fail("should have thrown exception cant adhoc approvals on dissaproved documents");
362     	} catch (Exception e) {
363 
364     	}
365 
366     	// try to ad hoc a complete request
367     	try {
368     		doc.adHocToPrincipal(ActionRequestType.COMPLETE, "One", "", getPrincipalIdForName("rkirkend"), "", true);
369     		fail("should have thrown exception cant ad hoc completes on dissaproved documents");
370     	} catch (Exception e) {
371 
372     	}
373 
374         // try to ad hoc an ack request
375         try {
376             doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("user1"), "", true);
377         } catch (Exception e) {
378             e.printStackTrace();
379             fail("should have thrown exception cant ad hoc completes on dissaproved documents");
380     }
381 
382         // try to ad hoc a fyi request
383         try {
384             doc.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("user1"), "", true);
385         } catch (Exception e) {
386             e.printStackTrace();
387             fail("should have thrown exception cant ad hoc completes on dissaproved documents");
388         }
389 
390     }
391 
392     /**
393      *
394      * @throws Exception
395      */
396 	@Test
397 	public void testAdHocNoNodeName() throws Exception {
398     	WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
399     	docId = doc.getDocumentId();
400 
401 		// do an appspecific route to jitrue and NonSIT (w/ force action =
402 		// false), should end up at the current node
403 
404     	doc.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("jitrue"), "", false);
405     	doc.adHocToGroup(ActionRequestType.APPROVE, "", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "NonSIT"), "", false);
406     	doc.route("");
407 
408 		// user1 should not have a request, his action should have counted for
409 		// the ad hoc request to the workgroup
410     	doc = getDocument("user1");
411     	assertFalse(doc.isApprovalRequested());
412     	doc = getDocument("jitrue");
413     	assertTrue(doc.isApprovalRequested());
414 		// we should still be at the "AdHoc" node because we sent an ad hoc
415 		// request to jitrue and the workgroup
416     	TestUtilities.assertAtNodeNew(doc, "AdHoc");
417 
418     	// now disapprove as jitrue
419     	doc = getDocument("jitrue");
420     	TestUtilities.assertAtNodeNew(doc, "AdHoc");
421     	doc.disapprove("");
422     	// we should stay at the AdHoc node following the disapprove
423     	TestUtilities.assertAtNodeNew(doc, "AdHoc");
424     	assertTrue(doc.isDisapproved());
425     	//adhoc an ack and fyi
426 
427     	doc.adHocToPrincipal(ActionRequestType.FYI, "", getPrincipalIdForName("rkirkend"), "", true);
428     	doc.adHocToPrincipal(ActionRequestType.ACKNOWLEDGE, "", getPrincipalIdForName("user2"), "", true);
429 
430     	doc.adHocToGroup(ActionRequestType.ACKNOWLEDGE, "", getGroupIdForName(KimConstants.KIM_GROUP_WORKFLOW_NAMESPACE_CODE, "NonSIT"), "", true);
431 
432     	// rkirkend should have an FYI ad hoc request
433     	doc = getDocument("rkirkend");
434     	assertTrue(doc.isFYIRequested());
435     	doc.fyi();
436 
437 		// user3 should have an ACK ad hoc request because user3 is in the
438 		// NonSIT workgroup
439     	doc = getDocument("user3");
440     	assertTrue(doc.isAcknowledgeRequested());
441 
442 		// user2 should have an ACK ad hoc request (because of their individual
443 		// ack and because they are in the NonSIT workgroup)
444     	doc = getDocument("user2");
445     	assertTrue(doc.isAcknowledgeRequested());
446     	doc.acknowledge("");
447 
448 		// user2's ACK should have counted for the NonSIT workgroup request,
449 		// user 3 should no longer have an ACK
450     	doc = getDocument("user3");
451     	assertFalse(doc.isAcknowledgeRequested());
452 
453 		// finally user1 should have an acknowledge as a result of the
454 		// disapprove since user1 was the initiator
455     	doc = getDocument("user1");
456     	assertTrue(doc.isAcknowledgeRequested());
457     	doc.acknowledge("");
458 
459     	// there should now be no remaining pending requests on the document
460     	TestUtilities.assertNumberOfPendingRequests(doc.getDocumentId(), 0);
461 
462 		// make sure we cant ad hoc approves or completes on a "terminal"
463 		// document
464     	try {
465     		doc.adHocToPrincipal(ActionRequestType.APPROVE, "", getPrincipalIdForName("rkirkend"), "", true);
466     		fail("should have thrown exception cant adhoc approvals on dissaproved documents");
467 		} catch (Exception e) {
468 		}
469     	// try to ad hoc a complete request
470     	try {
471     		doc.adHocToPrincipal(ActionRequestType.COMPLETE, "", getPrincipalIdForName("rkirkend"), "", true);
472     		fail("should have thrown exception cant ad hoc completes on dissaproved documents");
473 		} catch (Exception e) {
474 		}
475 
476     }
477 	
478 	@Test
479 	public void testAdHocWithRequestLabel_ToPrincipal() throws Exception {
480 		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
481 		String label = "MY PRINCIPAL LABEL";
482 		doc.adHocToPrincipal(ActionRequestType.APPROVE, null, "", getPrincipalIdForName("ewestfal"), "", true, label);
483 		
484 		List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
485 		assertEquals("Shoudl have 1 request.", 1, actionRequests.size());
486 		ActionRequestValue actionRequest = actionRequests.get(0);
487 		assertEquals("Should be an approve request", ActionRequestType.APPROVE.getCode(), actionRequest.getActionRequested());
488 		assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
489 		assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
490 		
491 		// now route the document, it should activate the request and create an action item
492 		doc.route("");
493 		
494 		Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
495 		assertEquals("Should have 1 action item.", 1, actionItems.size());
496 		ActionItem actionItem = actionItems.iterator().next();
497 		assertEquals("ActionItem should be constructed from request.", actionRequest.getActionRequestId(), actionItem.getActionRequestId());
498 		assertEquals("ActionItem should have same label", label, actionItem.getRequestLabel());
499 	}
500 
501 	@Test
502 	public void testAdHocWithRequestLabel_ToGroup() throws Exception {
503 		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_DOC);
504 		String label = "MY GROUP LABEL";
505 		Group workflowAdmin = KEWServiceLocator.getIdentityHelperService().getGroupByName("KR-WKFLW", "WorkflowAdmin");
506 		doc.adHocToGroup(ActionRequestType.APPROVE, null, "", workflowAdmin.getId(), "", true, label);
507 		
508 		List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
509 		assertEquals("Should have 1 request.", 1, actionRequests.size());
510 		ActionRequestValue actionRequest = actionRequests.get(0);
511 		assertEquals("Should be an approve request", ActionRequestType.APPROVE.getCode(), actionRequest.getActionRequested());
512 		assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
513 		assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
514 		
515 		// now route the document, it should activate the request and create action items
516 		doc.route("");
517 		
518 		Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
519 		assertTrue("Should have more than 1 action item.", actionItems.size() > 1);
520 		for (ActionItem actionItem : actionItems) {
521 			assertEquals("ActionItem should be constructed from request.", actionRequest.getActionRequestId(), actionItem.getActionRequestId());
522 			assertEquals("ActionItem should have same label", label, actionItem.getRequestLabel());
523 		}
524 	}
525 	
526 	   @Test
527 	    public void testAdHocWithNoNodes() throws Exception {
528 	        WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), ADHOC_NO_NODE_DOC);
529 	        String label = "MY PRINCIPAL LABEL";
530 	        //DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(document);
531 	        
532 	        doc.adHocToPrincipal(ActionRequestType.FYI, null, "", getPrincipalIdForName("ewestfal"), "", true, label);
533 	        
534 	        List<ActionRequestValue> actionRequests = KEWServiceLocator.getActionRequestService().findPendingRootRequestsByDocId(doc.getDocumentId());
535 	        assertEquals("Should have 1 request.", 1, actionRequests.size());
536 	        ActionRequestValue actionRequest = actionRequests.get(0);
537 	        assertEquals("Should be a FYI request", ActionRequestType.FYI.getCode(), actionRequest.getActionRequested());
538 	        assertEquals("Invalid request label", label, actionRequest.getRequestLabel());
539 	        assertEquals("Request should be initialized", ActionRequestStatus.INITIALIZED.getCode(), actionRequest.getStatus());
540 	        
541 	        // now route the document, it should activate the request and create an action item
542 	        doc.route("");
543 	        
544 	        Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionListForSingleDocument(doc.getDocumentId());
545 	        assertEquals("Should have 0 action item.", 0, actionItems.size());
546 	        //ActionItem actionItem = actionItems.iterator().next();
547 	        //assertEquals("ActionItem should be constructed from request.", actionRequest.getActionRequestId(), actionItem.getActionRequestId());
548 	        //assertEquals("ActionItem should have same label", label, actionItem.getRequestLabel());
549 	    }
550 
551     /**
552      * This test allows us to ensure that Priority-Parallel activation is working as expected.
553      */
554     @Test
555     public void testAdHocWithPriorityParallelActivation() throws Exception {
556         String user1 = getPrincipalIdForName("user1");
557         String user2 = getPrincipalIdForName("user2");
558         String user3 = getPrincipalIdForName("user3");
559         String testuser1 = getPrincipalIdForName("testuser1");
560         String testuser2 = getPrincipalIdForName("testuser2");
561         String testuser3 = getPrincipalIdForName("testuser3");
562 
563         WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1, ADHOC_PRIORITY_PARALLEL_DOC);
564 
565         // create adhoc requests as follows:
566         // @Priority 1:
567         //      * ACK to user2
568         // @Priority 2:
569         //      * APPROVE to user3
570         //      * APPROVE to testuser1
571         //      * ACK to testuser2
572         // @Priority 3:
573         //      * FYI to testuser3
574         AdHocToPrincipal.Builder adHocToPrincipal = AdHocToPrincipal.Builder.create(ActionRequestType.ACKNOWLEDGE, null, user2);
575         adHocToPrincipal.setPriority(1);
576         document.adHocToPrincipal(adHocToPrincipal.build(), "");
577 
578         adHocToPrincipal.setPriority(2);
579         adHocToPrincipal.setActionRequested(ActionRequestType.APPROVE);
580         adHocToPrincipal.setTargetPrincipalId(user3);
581         document.adHocToPrincipal(adHocToPrincipal.build(), "");
582 
583         adHocToPrincipal.setTargetPrincipalId(testuser1);
584         document.adHocToPrincipal(adHocToPrincipal.build(), "");
585 
586         adHocToPrincipal.setActionRequested(ActionRequestType.ACKNOWLEDGE);
587         adHocToPrincipal.setTargetPrincipalId(testuser2);
588         document.adHocToPrincipal(adHocToPrincipal.build(), "");
589 
590         adHocToPrincipal.setPriority(3);
591         adHocToPrincipal.setActionRequested(ActionRequestType.FYI);
592         adHocToPrincipal.setTargetPrincipalId(testuser3);
593         document.adHocToPrincipal(adHocToPrincipal.build(), "");
594 
595         // now let's route the document
596         document.route("");
597         assertTrue(document.isEnroute());
598 
599         // check that our action requests are correct
600         List<ActionRequest> rootActionRequests = document.getRootActionRequests();
601         assertEquals("Should have 5 root action requests", 5, rootActionRequests.size());
602         ActionRequest user2Request = null;
603         ActionRequest user3Request = null;
604         ActionRequest testuser1Request = null;
605         ActionRequest testuser2Request = null;
606         ActionRequest testuser3Request = null;
607         for (ActionRequest actionRequest : rootActionRequests) {
608             if (user2.equals(actionRequest.getPrincipalId())) {
609                 user2Request = actionRequest;
610             } else if (user3.equals(actionRequest.getPrincipalId())) {
611                 user3Request = actionRequest;
612             } else if (testuser1.equals(actionRequest.getPrincipalId())) {
613                 testuser1Request = actionRequest;
614             } else if (testuser2.equals(actionRequest.getPrincipalId())) {
615                 testuser2Request = actionRequest;
616             } else if (testuser3.equals(actionRequest.getPrincipalId())) {
617                 testuser3Request = actionRequest;
618             }
619         }
620         // now let's ensure we got the requests we wanted
621         assertNotNull(user2Request);
622         assertEquals(ActionRequestStatus.ACTIVATED, user2Request.getStatus());
623         assertNotNull(user3Request);
624         assertEquals(ActionRequestStatus.ACTIVATED, user3Request.getStatus());
625         assertNotNull(testuser1Request);
626         assertEquals(ActionRequestStatus.ACTIVATED, testuser1Request.getStatus());
627         assertNotNull(testuser2Request);
628         assertEquals(ActionRequestStatus.ACTIVATED, testuser2Request.getStatus());
629         assertNotNull(testuser3Request);
630         assertEquals(ActionRequestStatus.INITIALIZED, testuser3Request.getStatus());
631 
632         // now let's approve for user3
633         document.switchPrincipal(user3);
634         assertTrue(document.isApprovalRequested());
635         document.approve("");
636         assertTrue(document.isEnroute());
637 
638         // make sure the fyi to testuser3 still hasn't been activated yet
639         document.switchPrincipal(testuser3);
640         assertFalse(document.isFYIRequested());
641 
642         // approve for testuser1
643         document.switchPrincipal(testuser1);
644         assertTrue(document.isApprovalRequested());
645         document.approve("");
646 
647         // document should now be in processed status
648         assertTrue(document.isProcessed());
649 
650         // ...and fyi to testuser3 should be activated now, go ahead and clear that fyi
651         document.switchPrincipal(testuser3);
652         assertTrue(document.isFYIRequested());
653         document.fyi();
654 
655         // clear out the remaning ack requests
656         assertTrue(document.isProcessed());
657         document.switchPrincipal(user2);
658         assertTrue(document.isAcknowledgeRequested());
659         document.acknowledge("");
660         assertTrue(document.isProcessed());
661         document.switchPrincipal(testuser2);
662         assertTrue(document.isAcknowledgeRequested());
663         document.acknowledge("");
664 
665         // document should now be final
666         assertTrue(document.isFinal());
667     }
668 
669 	
670     private WorkflowDocument getDocument(String netid) throws WorkflowException {
671     	return WorkflowDocumentFactory.loadDocument(getPrincipalIdForName(netid), docId);
672     }
673     private WorkflowDocument getDocument(String principalId, String docId) throws WorkflowException {
674     	return WorkflowDocumentFactory.loadDocument(principalId, docId);
675     }
676 
677 }