View Javadoc

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