1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.routeheader;
18
19 import org.junit.Test;
20 import org.kuali.rice.kew.api.KewApiServiceLocator;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kew.api.WorkflowRuntimeException;
24 import org.kuali.rice.kew.api.action.ActionRequest;
25 import org.kuali.rice.kew.api.action.ActionRequestType;
26 import org.kuali.rice.kew.api.document.Document;
27 import org.kuali.rice.kew.test.KEWTestCase;
28
29 import java.util.List;
30 import java.util.Set;
31
32 import static org.junit.Assert.*;
33
34 public class AppDocStatusTest extends KEWTestCase {
35
36 protected void loadTestData() throws Exception {
37 super.loadTestData();
38 loadXmlFile("AppDocStatusTestConfig.xml");
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 @Test public void testValidAppDocStatus() throws Exception {
55
56 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TestAppDocStatusDoc2");
57 document.saveDocumentData();
58 assertNotNull(document.getDocumentId());
59 assertTrue("Document should be initiatied", document.isInitiated());
60 assertTrue("Invalid route level.", document.getNodeNames().contains("Initiated"));
61
62
63 document.route("Test Routing.");
64 String appDocStatus = document.getDocument().getApplicationDocumentStatus();
65 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Approval in Progress".equalsIgnoreCase(appDocStatus));
66
67
68 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
69 assertTrue("Document should be enroute", document.isEnroute());
70 Set<String> nodeNames = document.getNodeNames();
71 assertEquals("Wrong number of node names.", 1, nodeNames.size());
72 assertTrue("Wrong node name.", document.getNodeNames().contains("DestinationApproval"));
73
74
75 List<ActionRequest> requests = document.getRootActionRequests();
76 assertEquals(1, requests.size());
77 ActionRequest request = requests.get(0);
78 assertEquals(getPrincipalIdForName("bmcgough"), request.getPrincipalId());
79 assertEquals(ActionRequestType.APPROVE, request.getActionRequested());
80 assertEquals("DestinationApproval", request.getNodeName());
81 assertTrue(document.isApprovalRequested());
82
83
84 document.approve("Test approve by bmcgough");
85
86
87 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
88 Document rh = document.getDocument();
89 appDocStatus = rh.getApplicationDocumentStatus();
90 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Submitted".equalsIgnoreCase(appDocStatus));
91
92
93 assertTrue("Document should be enroute", document.isEnroute());
94 nodeNames = document.getNodeNames();
95 assertEquals("Wrong number of node names.", 1, nodeNames.size());
96 assertTrue("Wrong node name.", nodeNames.contains("TravelerApproval"));
97 document.approve("Test approve by temay");
98
99
100 document.setApplicationDocumentStatus("Completed");
101 document.saveDocumentData();
102
103
104 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
105
106 rh = document.getDocument();
107 appDocStatus = rh.getApplicationDocumentStatus();
108 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Completed".equalsIgnoreCase(appDocStatus));
109
110
111 List<org.kuali.rice.kew.api.document.DocumentStatusTransition> history = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatusTransitionHistory(
112 document.getDocumentId());
113
114 assertEquals(3, history.size());
115 assertTrue("First History record has incorrect status", "Approval In Progress".equalsIgnoreCase(history.get(0).getNewStatus()));
116 assertTrue("Second History record has incorrect old status", "Approval In Progress".equalsIgnoreCase(
117 history.get(1).getOldStatus()));
118 assertTrue("Second History record has incorrect new status", "Submitted".equalsIgnoreCase(history.get(1).getNewStatus()));
119 assertTrue("Third History record has incorrect old status", "Submitted".equalsIgnoreCase(history.get(2).getOldStatus()));
120 assertTrue("Third History record has incorrect new status", "Completed".equalsIgnoreCase(history.get(2).getNewStatus()));
121
122
123 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
124 assertTrue("Document should be final.", document.isFinal());
125 }
126
127
128
129
130
131
132
133
134 @Test public void testAppDocStatusValuesNotDefined() throws Exception {
135
136 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TestAppDocStatusDoc1");
137 document.saveDocumentData();
138 assertNotNull(document.getDocumentId());
139 assertTrue("Document should be initiatied", document.isInitiated());
140 assertTrue("Invalid route level.", document.getNodeNames().contains("Initiated"));
141
142
143 document.route("Test Routing.");
144 Document rh = document.getDocument();
145 String appDocStatus = rh.getApplicationDocumentStatus();
146 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Approval in Progress".equalsIgnoreCase(appDocStatus));
147
148
149 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
150 assertTrue("Document should be enroute", document.isEnroute());
151 Set<String> nodeNames = document.getNodeNames();
152 assertEquals("Wrong number of node names.", 1, nodeNames.size());
153 assertTrue("Wrong node name.", nodeNames.contains("step1"));
154
155
156 List<ActionRequest> requests = document.getRootActionRequests();
157 assertEquals(1, requests.size());
158 ActionRequest request = requests.get(0);
159 assertEquals(getPrincipalIdForName("bmcgough"), request.getPrincipalId());
160 assertEquals(ActionRequestType.APPROVE, request.getActionRequested());
161 assertEquals("step1", request.getNodeName());
162 assertTrue(document.isApprovalRequested());
163
164
165 document.approve("Test approve by bmcgough");
166
167
168 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
169 rh = document.getDocument();
170 appDocStatus = rh.getApplicationDocumentStatus();
171 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Submitted".equalsIgnoreCase(appDocStatus));
172
173
174 assertTrue("Document should be enroute", document.isEnroute());
175 nodeNames = document.getNodeNames();
176 assertEquals("Wrong number of node names.", 1, nodeNames.size());
177 assertTrue("Wrong node name.", nodeNames.contains("step2"));
178 document.approve("Test approve by temay");
179
180
181 document.setApplicationDocumentStatus("Some Random Value");
182 document.saveDocumentData();
183
184
185 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("temay"), document.getDocumentId());
186
187 rh = document.getDocument();
188 appDocStatus = rh.getApplicationDocumentStatus();
189 assertTrue("Application Document Status:" + appDocStatus +" is invalid", "Some Random Value".equalsIgnoreCase(appDocStatus));
190
191
192 List<org.kuali.rice.kew.api.document.DocumentStatusTransition> history = KewApiServiceLocator.getWorkflowDocumentService().getDocumentStatusTransitionHistory(
193 document.getDocumentId());
194
195 assertEquals(3, history.size());
196 assertTrue("First History record has incorrect status", "Approval In Progress".equalsIgnoreCase(history.get(0)
197 .getNewStatus()));
198 assertTrue("Second History record has incorrect old status", "Approval In Progress".equalsIgnoreCase(
199 history.get(1).getOldStatus()));
200 assertTrue("Second History record has incorrect new status", "Submitted".equalsIgnoreCase(history.get(1)
201 .getNewStatus()));
202 assertTrue("Third History record has incorrect old status", "Submitted".equalsIgnoreCase(history.get(2).getOldStatus()));
203 assertTrue("Third History record has incorrect new status", "Some Random Value".equalsIgnoreCase(history.get(2)
204 .getNewStatus()));
205
206
207 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
208 assertTrue("Document should be final.", document.isFinal());
209 }
210
211
212
213
214
215
216
217
218
219 @Test public void testInvalidAppDocStatusValue() throws Exception {
220 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "TestAppDocStatusDoc2");
221 document.saveDocumentData();
222 assertNotNull(document.getDocumentId());
223 assertTrue("Document should be initiatied", document.isInitiated());
224 assertTrue("Invalid route level.", document.getNodeNames().contains("Initiated"));
225
226
227 boolean gotException = false;
228 try {
229 document.setApplicationDocumentStatus("BAD STATUS");
230 document.saveDocumentData();
231 } catch (Throwable t){
232 gotException = true;
233 WorkflowRuntimeException ex = new WorkflowRuntimeException();
234 assertEquals("WrongExceptionType", t.getClass(), ex.getClass());
235 } finally {
236 assertTrue("Expected WorkflowRuntimeException not thrown.", gotException);
237
238 }
239 }
240 }