1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
36
37
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
70 new ActionInvocationQueueImpl().invokeAction(user1PrincipalId, request.getDocumentId(), ActionInvocation.create(
71 ActionType.fromCode(request.getActionRequested()), actionItemID));
72
73
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 }