View Javadoc

1   /*
2    * Copyright 2007 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.asyncservices;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.junit.Test;
22  import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23  import org.kuali.rice.kew.rule.TestRuleAttribute;
24  import org.kuali.rice.kew.service.KEWServiceLocator;
25  import org.kuali.rice.kew.service.WorkflowDocument;
26  import org.kuali.rice.kew.test.KEWTestCase;
27  import org.kuali.rice.kew.user.AuthenticationUserId;
28  
29  
30  
31  /**
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class ActionInvocationProcessorTest extends KEWTestCase {
37  
38  
39  	@Test public void testActionInvocationProcessorWorksWithNoActionItem() throws Exception {
40  
41  		TestRuleAttribute.setRecipientPrincipalIds("TestRole", "QualRole", getRecipients());
42  
43  		String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
44  		WorkflowDocument doc = new WorkflowDocument(rkirkendPrincipalId, "TestDocumentType");
45  		doc.routeDocument("");
46  
47  		List<ActionRequestValue> requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(doc.getRouteHeaderId());
48  		assertFalse(requests.isEmpty());
49  
50  		ActionRequestValue request = null;
51  		for (ActionRequestValue tempRequest : requests) {
52  			if (tempRequest.getPrincipal() != null && tempRequest.getPrincipal().getPrincipalName().equals("user1")) 
53  			{
54  				request = tempRequest;
55  				break;
56  			}
57  		}
58  
59  		assertNotNull(request);
60  
61  		String user1PrincipalId = getPrincipalIdForName("user1");
62  		new ActionInvocationProcessor().invokeAction(user1PrincipalId, request.getRouteHeaderId(), new ActionInvocation(request.getRouteHeaderId(), request.getActionRequested()));
63  		//do it again and make sure we don't have a blow up
64  		new ActionInvocationProcessor().invokeAction(user1PrincipalId, request.getRouteHeaderId(), new ActionInvocation(request.getRouteHeaderId(), request.getActionRequested()));
65  
66  		//verify that user1 doesn't have any AR's
67  		requests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(doc.getRouteHeaderId());
68  		assertFalse(requests.isEmpty());
69  
70  		request = null;
71  		for (ActionRequestValue tempRequest : requests) {
72  			if (tempRequest.getPrincipalId() != null && tempRequest.getPrincipalId().equals(getPrincipalIdForName("user1")) && tempRequest.isActive()) {
73  				request = tempRequest;
74  				break;
75  			}
76  		}
77  
78  		assertNull(request);
79  
80  	}
81  
82  	public List<String> getRecipients()	{
83  		List<String> recipients = new ArrayList<String>();
84  		recipients.add(getPrincipalIdForName("user1"));
85  		recipients.add(getPrincipalIdForName("user2"));
86  		return recipients;
87  	}
88  
89  }