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