View Javadoc

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