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