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