1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.routelog.web;
17
18 import java.util.Collection;
19 import java.util.List;
20
21 import org.junit.Test;
22 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23 import org.kuali.rice.kew.actions.AcknowledgeAction;
24 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
25 import org.kuali.rice.kew.dto.DTOConverter;
26 import org.kuali.rice.kew.exception.WorkflowException;
27 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
28 import org.kuali.rice.kew.service.KEWServiceLocator;
29 import org.kuali.rice.kew.service.WorkflowDocument;
30 import org.kuali.rice.kew.test.KEWTestCase;
31
32
33
34
35
36
37
38
39 public class RouteLogActionTest extends KEWTestCase
40 {
41 RouteLogAction routeLogAction = new RouteLogAction();
42
43 protected void loadTestData() throws Exception
44 {
45 loadXmlFile(AcknowledgeAction.class, "ActionsConfig.xml");
46 }
47
48
49
50
51 @SuppressWarnings("unchecked")
52 @Test public void testPopulateRouteLogFutureRequests_HasNoExistingRequests() throws Exception {
53
54 WorkflowDocument document = new WorkflowDocument(getPrincipalIdForName("user1"), getClass().getSimpleName());
55 document.routeDocument("1 - user1 route");
56 verifyFutureRequestState(document);
57
58 document = new WorkflowDocument(getPrincipalIdForName("ewestfal"), document.getRouteHeaderId());
59 document.approve("2 - ewestfal approve");
60 verifyFutureRequestState(document);
61
62 document = new WorkflowDocument(getPrincipalIdForName("user2"), document.getRouteHeaderId());
63 document.approve("3 - user2 approve");
64 verifyFutureRequestState(document);
65
66 document = new WorkflowDocument(getPrincipalIdForName("user3"), document.getRouteHeaderId());
67 document.acknowledge("4 - user3 acknowledge");
68 verifyFutureRequestState(document);
69 }
70
71
72
73
74
75
76
77
78
79
80 private void verifyFutureRequestState(WorkflowDocument document)
81 throws WorkflowException, Exception {
82 Collection<ActionTakenValue> actionsTaken = KEWServiceLocator.getActionTakenService().findByRouteHeaderId(document.getRouteHeaderId());
83 Collection<ActionRequestValue> actionsPending = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
84
85 DocumentRouteHeaderValue docRouteHeaderValue = DTOConverter.convertRouteHeaderVO(document.getRouteHeader());
86 RouteLogForm routeLogForm = new RouteLogForm();
87 routeLogAction.populateRouteLogFutureRequests(routeLogForm, docRouteHeaderValue);
88 List<ActionRequestValue> futureRootRequests = routeLogForm.getFutureRootRequests();
89
90 int takenRequestCount = 0;
91
92 for (ActionTakenValue actionTaken : actionsTaken) {
93 if (actionTaken.getActionRequests() != null) {
94 for (ActionRequestValue actionRequestTaken : actionTaken.getActionRequests()) {
95 ++takenRequestCount;
96 for (ActionRequestValue futureRequest : futureRootRequests) {
97 assertFalse("action taken is in futureRootRequests",
98 futureRequest.getActionRequestId().equals(actionRequestTaken.getActionRequestId()));
99 }
100 }
101 }
102 }
103
104 int pendingRequestsCount = 0;
105
106 for (ActionRequestValue pendingAction : actionsPending) {
107 ++pendingRequestsCount;
108 for (ActionRequestValue futureRequest : futureRootRequests) {
109 assertFalse("action taken is in futureRootRequests",
110 futureRequest.getActionRequestId().equals(pendingAction.getActionRequestId()));
111 }
112 }
113
114
115 assertTrue("taken + pending + future == 3", takenRequestCount + pendingRequestsCount + futureRootRequests.size() == 3);
116
117 recursiveValidate(routeLogForm.getFutureRootRequests());
118 }
119
120
121
122
123 @Test public void testPopulateRouteLogFutureRequests_ZeroFutureRequests() throws Exception {
124 String user1PrincipalId = getPrincipalIdForName("ewestfal");
125
126 RouteLogForm routeLogForm = new RouteLogForm();
127
128 WorkflowDocument document = new WorkflowDocument(user1PrincipalId, "RouteLogActionTestTrivial");
129
130 document.routeDocument("");
131
132 DocumentRouteHeaderValue docRouteHeaderValue = DTOConverter.convertRouteHeaderVO(document.getRouteHeader());
133
134 try {
135 routeLogAction.populateRouteLogFutureRequests(routeLogForm, docRouteHeaderValue);
136 } catch (Exception e) {
137 fail("calculating future requests where there will be none should not be a problem");
138 }
139
140 assertTrue("We're expecting 0 future action requests",routeLogForm.getFutureActionRequestCount()==0);
141 assertTrue("We're expecting 0 future action requests",
142 routeLogForm.getFutureRootRequests() == null || routeLogForm.getFutureRootRequests().size() == 0);
143 }
144
145
146
147
148
149
150
151 private void recursiveValidate(List<ActionRequestValue> actionRequestValues) {
152 if (actionRequestValues != null) for (ActionRequestValue actionRequestValue : actionRequestValues) {
153 assertNotNull(actionRequestValue.getActionRequested());
154 assertNotNull(actionRequestValue.getActionRequestedLabel());
155 assertNotNull(actionRequestValue.getNodeInstance());
156 assertNotNull(actionRequestValue.getNodeInstance().getName());
157 assertNotNull(actionRequestValue.getNodeInstance().getRouteNode());
158 assertNotNull(actionRequestValue.getNodeInstance().getRouteNode().getNodeType());
159
160 recursiveValidate(actionRequestValue.getChildrenRequests());
161 }
162 }
163
164 }