1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.actions;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.kuali.rice.kew.actionlist.ActionListFilter;
23 import org.kuali.rice.kew.dto.DocumentDetailDTO;
24 import org.kuali.rice.kew.dto.KeyValueDTO;
25 import org.kuali.rice.kew.dto.NetworkIdDTO;
26 import org.kuali.rice.kew.dto.ReportActionToTakeDTO;
27 import org.kuali.rice.kew.dto.ReportCriteriaDTO;
28 import org.kuali.rice.kew.engine.node.BranchState;
29 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
30 import org.kuali.rice.kew.rule.TestRuleAttribute;
31 import org.kuali.rice.kew.service.KEWServiceLocator;
32 import org.kuali.rice.kew.service.WorkflowDocument;
33 import org.kuali.rice.kew.service.WorkflowInfo;
34 import org.kuali.rice.kew.test.KEWTestCase;
35 import org.kuali.rice.kew.util.FutureRequestDocumentStateManager;
36 import org.kuali.rice.kew.util.KEWConstants;
37
38
39
40
41
42
43
44
45 public class FutureRequestsTest extends KEWTestCase {
46
47
48
49
50
51
52
53 @Test
54 public void testSavingFutureRequestsStatuses() throws Exception {
55 List<String> ids = new ArrayList<String>();
56 ids.add(getPrincipalIdForName("user1"));
57 TestRuleAttribute.setRecipientPrincipalIds("TestRole", "TestRole-user1", ids);
58
59
60
61 String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
62 WorkflowDocument document = new WorkflowDocument(rkirkendPrincipalId, "TestDocumentType");
63 document.setReceiveFutureRequests();
64 document.routeDocument("");
65
66 DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getRouteHeaderId());
67
68 FutureRequestDocumentStateManager futRequestStateMan = new FutureRequestDocumentStateManager(routeHeader, rkirkendPrincipalId);
69 assertTrue(futRequestStateMan.isReceiveFutureRequests());
70 assertFalse(futRequestStateMan.isClearFutureRequestState());
71 assertFalse(futRequestStateMan.isDoNotReceiveFutureRequests());
72
73
74
75 document = new WorkflowDocument(rkirkendPrincipalId, "TestDocumentType");
76 document.setDoNotReceiveFutureRequests();
77 document.routeDocument("");
78
79 routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getRouteHeaderId());
80
81 futRequestStateMan = new FutureRequestDocumentStateManager(routeHeader, rkirkendPrincipalId);
82 assertFalse(futRequestStateMan.isReceiveFutureRequests());
83 assertFalse(futRequestStateMan.isClearFutureRequestState());
84 assertTrue(futRequestStateMan.isDoNotReceiveFutureRequests());
85
86
87 document = new WorkflowDocument(rkirkendPrincipalId, document.getRouteHeaderId());
88 document.setClearFutureRequests();
89 document.approve("");
90
91 routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getRouteHeaderId());
92 futRequestStateMan = new FutureRequestDocumentStateManager(routeHeader, rkirkendPrincipalId);
93 assertFalse(futRequestStateMan.isReceiveFutureRequests());
94 assertTrue(futRequestStateMan.isClearFutureRequestState());
95 assertFalse(futRequestStateMan.isDoNotReceiveFutureRequests());
96
97
98 routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getRouteHeaderId());
99 int deactivatedCount = 0;
100 for (BranchState state : routeHeader.getRootBranchState()) {
101 if (state.getKey().contains(FutureRequestDocumentStateManager.FUTURE_REQUESTS_VAR_KEY)) {
102 fail("state clearing should have removed all future request vars");
103 } else if (state.getKey().contains(FutureRequestDocumentStateManager.DEACTIVATED_REQUESTS_VARY_KEY)) {
104 deactivatedCount++;
105 }
106 }
107 assertEquals(2, deactivatedCount);
108
109 document = new WorkflowDocument(rkirkendPrincipalId, "TestDocumentType");
110 document.routeDocument("");
111 routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(document.getRouteHeaderId());
112 futRequestStateMan = new FutureRequestDocumentStateManager(routeHeader, rkirkendPrincipalId);
113 assertFalse(futRequestStateMan.isReceiveFutureRequests());
114 assertFalse(futRequestStateMan.isClearFutureRequestState());
115 assertFalse(futRequestStateMan.isDoNotReceiveFutureRequests());
116 }
117
118
119
120
121
122
123 @Test
124 public void testFutureRequestsWithRouting() throws Exception {
125 this.loadXmlFile(this.getClass(), "FutureRequestsConfig.xml");
126
127 String user1PrincipalId = getPrincipalIdForName("user1");
128 String user2PrincipalId = getPrincipalIdForName("user2");
129
130
131
132
133
134
135 WorkflowDocument document = new WorkflowDocument(user1PrincipalId, "FutureRequestsDoc");
136 document.setDoNotReceiveFutureRequests();
137 document.routeDocument("");
138
139 document = new WorkflowDocument(user1PrincipalId, document.getRouteHeaderId());
140 assertFalse(document.isApprovalRequested());
141
142 document = new WorkflowDocument(user2PrincipalId, document.getRouteHeaderId());
143 assertTrue(document.isApprovalRequested());
144 document.setReceiveFutureRequests();
145 document.approve("");
146
147
148
149 document = new WorkflowDocument(user2PrincipalId, document.getRouteHeaderId());
150 assertTrue(document.isApprovalRequested());
151
152
153 assertEquals(1, KEWServiceLocator.getActionListService().getActionList(user2PrincipalId, new ActionListFilter()).size());
154 assertEquals(1, KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, new ActionListFilter()).size());
155
156 document.approve("");
157
158
159 document = new WorkflowDocument(user2PrincipalId, document.getRouteHeaderId());
160 assertTrue(document.isApprovalRequested());
161 }
162
163
164
165
166
167
168 @Test
169 public void testFutureRequestsWithRoutingAndWorkflowInfoActionRequestCheck() throws Exception {
170 this.loadXmlFile(this.getClass(), "FutureRequestsConfig.xml");
171
172 String user1PrincipalId = getPrincipalIdForName("user1");
173 String user2PrincipalId = getPrincipalIdForName("user2");
174
175 WorkflowDocument document = new WorkflowDocument(user1PrincipalId, "FutureRequestsDoc");
176 document.routeDocument("");
177
178
179
180 document = new WorkflowDocument(user1PrincipalId, document.getRouteHeaderId());
181 WorkflowInfo info = new WorkflowInfo();
182 ReportCriteriaDTO reportCriteriaDTO = new ReportCriteriaDTO(document.getRouteHeaderId());
183 reportCriteriaDTO.setTargetPrincipalIds(new String[]{user1PrincipalId});
184 String actionToTakeNode = "Node1";
185 reportCriteriaDTO.setActionsToTake(new ReportActionToTakeDTO[]{new ReportActionToTakeDTO(KEWConstants.ACTION_TAKEN_APPROVED_CD, user1PrincipalId, actionToTakeNode)});
186 assertTrue("User " + user1PrincipalId + " should have approval requests on the document", info.documentWillHaveAtLeastOneActionRequest(reportCriteriaDTO, new String[]{KEWConstants.ACTION_REQUEST_APPROVE_REQ}, false));
187
188 info = new WorkflowInfo();
189 reportCriteriaDTO = new ReportCriteriaDTO(document.getRouteHeaderId());
190 reportCriteriaDTO.setTargetPrincipalIds(new String[]{user1PrincipalId});
191 actionToTakeNode = "Node1";
192 reportCriteriaDTO.setActionsToTake(new ReportActionToTakeDTO[]{new ReportActionToTakeDTO(KEWConstants.ACTION_TAKEN_APPROVED_CD, user1PrincipalId, actionToTakeNode)});
193 DocumentDetailDTO documentVO = info.routingReport(reportCriteriaDTO);
194 assertTrue("User " + user1PrincipalId + " should have one or more approval requests on the document", documentVO.getActionRequests().length > 0);
195
196 info = new WorkflowInfo();
197 reportCriteriaDTO = new ReportCriteriaDTO(document.getRouteHeaderId());
198 String delyeaPrincipalId = getPrincipalIdForName("delyea");
199 NetworkIdDTO delyeaIdDTO = new NetworkIdDTO("delyea");
200 reportCriteriaDTO.setTargetPrincipalIds(new String[]{user1PrincipalId});
201 actionToTakeNode = "Node1";
202 reportCriteriaDTO.setActionsToTake(new ReportActionToTakeDTO[]{new ReportActionToTakeDTO(KEWConstants.ACTION_TAKEN_APPROVED_CD, user1PrincipalId, actionToTakeNode)});
203 documentVO = info.routingReport(reportCriteriaDTO);
204 assertTrue("User " + delyeaPrincipalId + " should not have any requests on the document but routingReport() method should return all action requests anyway", documentVO.getActionRequests().length > 0);
205
206 document = new WorkflowDocument(user1PrincipalId, "FutureRequestsDoc");
207 document.setDoNotReceiveFutureRequests();
208 document.routeDocument("");
209
210 document = new WorkflowDocument(user1PrincipalId, document.getRouteHeaderId());
211 assertFalse(document.isApprovalRequested());
212
213
214 info = new WorkflowInfo();
215 reportCriteriaDTO = new ReportCriteriaDTO(document.getRouteHeaderId());
216 reportCriteriaDTO.setTargetPrincipalIds(new String[]{user1PrincipalId});
217 assertFalse("User " + user1PrincipalId + " should not have any approval request on the document", info.documentWillHaveAtLeastOneActionRequest(reportCriteriaDTO, new String[]{KEWConstants.ACTION_REQUEST_APPROVE_REQ}, false));
218
219
220 info = new WorkflowInfo();
221 reportCriteriaDTO = new ReportCriteriaDTO(document.getRouteHeaderId());
222 reportCriteriaDTO.setTargetPrincipalIds(new String[]{user2PrincipalId});
223 assertTrue("User " + user2PrincipalId + " should have any approval request on the document", info.documentWillHaveAtLeastOneActionRequest(reportCriteriaDTO, new String[]{KEWConstants.ACTION_REQUEST_APPROVE_REQ}, false));
224
225 }
226
227
228
229
230
231
232
233
234
235
236
237 @Test
238 public void testFutureRequestsWithDuplicateNodesSplit() throws Exception {
239
240 testFutureRequestsWithDuplicateNodesImpl("FutureRequestsConfig2.xml");
241 }
242
243 @Test
244 public void testFutureRequestsWithDuplicateNodesStraight() throws Exception {
245
246 testFutureRequestsWithDuplicateNodesImpl("FutureRequestsConfig3.xml");
247 }
248
249 private void testFutureRequestsWithDuplicateNodesImpl(String fileName) throws Exception{
250 this.loadXmlFile(this.getClass(), fileName);
251
252
253 String user1PrincipalId = getPrincipalIdForName("user1");
254 String user2PrincipalId = getPrincipalIdForName("user2");
255 String user3PrincipalId = getPrincipalIdForName("earl");
256
257 WorkflowDocument document = new WorkflowDocument(user1PrincipalId, "FutureRequestsDoc");
258 document.routeDocument("");
259
260
261
262
263 document = new WorkflowDocument(user3PrincipalId, document.getRouteHeaderId());
264 assertTrue("should have approval status", document.isApprovalRequested());
265
266 document.setReceiveFutureRequests();
267
268
269
270
271 document.saveRoutingData();
272
273 document.approve("route node 1");
274
275 document = new WorkflowDocument(user1PrincipalId, document.getRouteHeaderId());
276 List<KeyValueDTO> l =document.getRouteHeader().getVariables();
277 assertFalse("should not have approval status 1", document.isApprovalRequested());
278
279 document = new WorkflowDocument(user2PrincipalId, document.getRouteHeaderId());
280 assertTrue("should have approval status 2", document.isApprovalRequested());
281 document.approve("routing node 2");
282
283
284
285 document = new WorkflowDocument(user3PrincipalId, document.getRouteHeaderId());
286 System.out.println("Doc status prior to 3: " + document.getStatusDisplayValue());
287 assertTrue("should have approval status 3", document.isApprovalRequested());
288 document.approve("routing node 3");
289 System.out.println("Doc status after 3: " + document.getStatusDisplayValue());
290 }
291 }