1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actionrequest;
17
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.junit.Test;
28 import org.kuali.rice.kew.api.KewApiServiceLocator;
29 import org.kuali.rice.kew.api.document.DocumentRefreshQueue;
30 import org.kuali.rice.kew.api.WorkflowDocument;
31 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
32 import org.kuali.rice.kew.api.action.ActionRequest;
33 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
34 import org.kuali.rice.kew.service.KEWServiceLocator;
35 import org.kuali.rice.kew.test.KEWTestCase;
36
37
38
39
40
41
42 public class DocumentRefreshQueueTest extends KEWTestCase {
43
44 protected void loadTestData() throws Exception {
45 loadXmlFile("ActionRequestsConfig.xml");
46 }
47
48 private static final String SEQ_DOCUMENT_TYPE_NAME = "DRSeqDocType";
49 private static final String PAR_DOCUMENT_TYPE_NAME = "DRParDocType";
50
51
52
53
54
55
56 @Test
57 public void testDocumentRequeueSingleNode() throws Exception {
58 String initiatorPrincipalId = getPrincipalIdForName("ewestfal");
59 String firstApproverPrincipalId = getPrincipalIdForName("bmcgough");
60 String secondApproverPrincipalId = getPrincipalIdForName("rkirkend");
61
62
63 WorkflowDocument document = WorkflowDocumentFactory.createDocument(initiatorPrincipalId, SEQ_DOCUMENT_TYPE_NAME);
64 String documentNumber = document.getDocumentId();
65 document.route("");
66 document = WorkflowDocumentFactory.loadDocument(initiatorPrincipalId, documentNumber);
67 assertTrue(document.isEnroute());
68 assertEquals("Wrong number of requests", 2, document.getRootActionRequests().size());
69
70
71 Set<String> initialRequestIds = new HashSet<String>();
72
73 for (ActionRequest request : document.getRootActionRequests()) {
74 initialRequestIds.add(request.getId());
75 }
76
77
78 DocumentRouteHeaderValue documentRouteHeader
79 = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentNumber);
80 DocumentRefreshQueue documentRequeuer = KewApiServiceLocator.getDocumentRequeuerService(
81 documentRouteHeader.getDocumentType().getApplicationId(), documentNumber, 0);
82 documentRequeuer.refreshDocument(documentNumber);
83
84
85 document = WorkflowDocumentFactory.loadDocument(firstApproverPrincipalId, documentNumber);
86 assertTrue(document.isEnroute());
87 assertEquals("Wrong number of requests", 2, document.getRootActionRequests().size());
88
89 for (ActionRequest request : document.getRootActionRequests()) {
90 assertTrue("Request ids should be different", !initialRequestIds.contains(request.getId()));
91 }
92
93 assertTrue(document.isApprovalRequested());
94 document.approve("");
95
96
97 documentRequeuer.refreshDocument(document.getDocumentId());
98
99
100
101 document = WorkflowDocumentFactory.loadDocument(secondApproverPrincipalId, documentNumber);
102 assertTrue(document.isEnroute());
103 assertEquals("Wrong number of requests", 2, document.getRootActionRequests().size());
104
105 boolean pendingToSecondApprover = false;
106
107 for (ActionRequest request : document.getRootActionRequests()) {
108 if (request.getPrincipalId().equals(secondApproverPrincipalId) && request.isActivated()) {
109 assertFalse("Second approver has too many requests", pendingToSecondApprover);
110 pendingToSecondApprover = true;
111 } else {
112 assertTrue("Previous requests to all others should be done", request.isDone());
113 }
114 }
115
116 assertTrue(document.isApprovalRequested());
117 }
118
119
120
121
122
123
124 @Test
125 public void testDocumentRequeueMultipleNodes() throws Exception {
126 String initiatorPrincipalId = getPrincipalIdForName("ewestfal");
127 String firstApproverPrincipalId = getPrincipalIdForName("bmcgough");
128 String secondApproverPrincipalId = getPrincipalIdForName("rkirkend");
129 String thirdApproverPrincipalId = getPrincipalIdForName("pmckown");
130
131
132 WorkflowDocument document = WorkflowDocumentFactory.createDocument(initiatorPrincipalId, PAR_DOCUMENT_TYPE_NAME);
133 String documentNumber = document.getDocumentId();
134 document.route("");
135 document = WorkflowDocumentFactory.loadDocument(initiatorPrincipalId, documentNumber);
136 assertTrue(document.isEnroute());
137 assertEquals("Wrong number of requests", 3, document.getRootActionRequests().size());
138
139
140 Set<String> initialRequestIds = new HashSet<String>();
141
142 for (ActionRequest request : document.getRootActionRequests()) {
143 initialRequestIds.add(request.getId());
144 }
145
146
147 DocumentRouteHeaderValue documentRouteHeader
148 = KEWServiceLocator.getRouteHeaderService().getRouteHeader(documentNumber);
149 DocumentRefreshQueue documentRequeuer = KewApiServiceLocator.getDocumentRequeuerService(
150 documentRouteHeader.getDocumentType().getApplicationId(), documentNumber, 0);
151 documentRequeuer.refreshDocument(documentNumber);
152
153
154 document = WorkflowDocumentFactory.loadDocument(firstApproverPrincipalId, documentNumber);
155 assertTrue(document.isEnroute());
156 assertEquals("Wrong number of requests", 3, document.getRootActionRequests().size());
157
158 for (ActionRequest request : document.getRootActionRequests()) {
159 assertTrue("Request ids should be different", !initialRequestIds.contains(request.getId()));
160 }
161
162 assertTrue(document.isApprovalRequested());
163 document.approve("");
164
165
166 documentRequeuer.refreshDocument(document.getDocumentId());
167
168
169 document = WorkflowDocumentFactory.loadDocument(secondApproverPrincipalId, documentNumber);
170 assertTrue(document.isEnroute());
171 assertEquals("Wrong number of requests", 3, document.getRootActionRequests().size());
172
173 boolean pendingToSecondApprover = false;
174
175 for (ActionRequest request : document.getRootActionRequests()) {
176 if (request.getPrincipalId().equals(secondApproverPrincipalId) && request.isActivated()) {
177 assertFalse("Second approver has too many requests.", pendingToSecondApprover);
178 pendingToSecondApprover = true;
179 }
180 }
181
182 assertTrue(document.isApprovalRequested());
183 document.approve("");
184
185
186 documentRequeuer.refreshDocument(document.getDocumentId());
187
188
189
190 document = WorkflowDocumentFactory.loadDocument(thirdApproverPrincipalId, documentNumber);
191 assertTrue(document.isEnroute());
192 assertEquals("Wrong number of requests", 3, document.getRootActionRequests().size());
193
194 boolean pendingToThirdApprover = false;
195
196 for (ActionRequest request : document.getRootActionRequests()) {
197 if (request.getPrincipalId().equals(thirdApproverPrincipalId) && request.isActivated()) {
198 assertFalse("Third approver has too many requests.", pendingToThirdApprover);
199 pendingToThirdApprover = true;
200 } else {
201 assertTrue("Previous requests to all others should be done.", request.isDone());
202 }
203 }
204
205 assertTrue(document.isApprovalRequested());
206 document.approve("");
207 }
208
209 }