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