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 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
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
72 new ActionInvocationQueueImpl().invokeAction(user1PrincipalId, request.getDocumentId(), ActionInvocation.create(
73 ActionType.fromCode(request.getActionRequested()), actionItemID));
74
75
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 }