1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.actions;
18
19
20 import java.util.Iterator;
21 import java.util.List;
22
23 import org.junit.Test;
24 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25 import org.kuali.rice.kew.dto.NetworkIdDTO;
26 import org.kuali.rice.kew.exception.WorkflowException;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.service.WorkflowDocument;
29 import org.kuali.rice.kew.test.KEWTestCase;
30
31
32 public class SaveActionEventTest extends KEWTestCase {
33
34 public static final String DOCUMENT_TYPE_NAME = "SaveActionEventTest";
35 public static final String DOCUMENT_TYPE_NAME_NON_INITIATOR = "SaveActionEventTestNonInitiator";
36 public static final String ADHOC_NODE = "AdHoc";
37 public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
38
39 protected void loadTestData() throws Exception {
40 loadXmlFile("ActionsConfig.xml");
41 }
42
43 @Test public void testSaveActionEvent() throws Exception {
44 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME);
45 document.saveRoutingData();
46 assertTrue("Document should be initiated.", document.stateIsInitiated());
47 List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
48 assertEquals("There should be no action requests.", 0, actionRequests.size());
49 assertTrue("Document should be initiated.", document.stateIsInitiated());
50 document.saveDocument("");
51
52
53 document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
54 assertEquals("Document should be at AdHoc node.", ADHOC_NODE, document.getNodeNames()[0]);
55 assertTrue("Document should be SAVED.", document.stateIsSaved());
56
57 actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
58 assertEquals("There should be one COMPLETE request to the initiator.", 1, actionRequests.size());
59 assertTrue("Initiator should have complete request.", document.isCompletionRequested());
60 ActionRequestValue savedRequest = (ActionRequestValue)actionRequests.get(0);
61 assertNotNull(savedRequest);
62 assertTrue("Saved request should be a complete request.", savedRequest.isCompleteRequst());
63 assertEquals("Request should be at the AdHoc node.", ADHOC_NODE, savedRequest.getNodeInstance().getName());
64
65
66 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
67 try {
68 document.routeDocument("");
69 fail("RouteDocument should have thrown an exception because we aren't the initiator");
70 } catch (WorkflowException e) {}
71
72
73
74 document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
75 document.routeDocument("Routing Rowdy Roddy Pipper");
76
77
78
79 actionRequests = KEWServiceLocator.getActionRequestService().findPendingByDoc(document.getRouteHeaderId());
80 assertEquals("Should be 2 pending requests.", 2, actionRequests.size());
81
82 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
83 assertTrue("Document should be in routing.", document.stateIsEnroute());
84 assertTrue("rkirkend should have approve request.", document.isApprovalRequested());
85
86 document = new WorkflowDocument(new NetworkIdDTO("bmcgough"), document.getRouteHeaderId());
87 assertTrue("Document should be in routing.", document.stateIsEnroute());
88 assertTrue("bmcgough should have approve request.", document.isApprovalRequested());
89
90
91 assertEquals("Document should be at WorkflowDocument node.", WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
92 for (Iterator iterator = actionRequests.iterator(); iterator.hasNext();) {
93 ActionRequestValue request = (ActionRequestValue) iterator.next();
94 assertNotNull(request.getNodeInstance());
95 assertEquals("Request should be at WorkflowDocument node.", WORKFLOW_DOCUMENT_NODE, request.getNodeInstance().getName());
96 }
97
98
99
100 document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME);
101 document.saveDocument("");
102 assertTrue("Document should be saved.", document.stateIsSaved());
103 assertTrue("Should have complete request.", document.isCompletionRequested());
104 assertEquals("Document should be at AdHoc node.", ADHOC_NODE, document.getNodeNames()[0]);
105
106 document.complete("");
107 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
108 assertTrue("Document should be enroute.", document.stateIsEnroute());
109 assertTrue("Should have approve request.", document.isApprovalRequested());
110 assertEquals("Document should be at WorkflowDocument node.", WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
111
112
113 document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME);
114 document.saveDocument("");
115 assertTrue("Document should be saved.", document.stateIsSaved());
116 assertTrue("Should have complete request.", document.isCompletionRequested());
117 assertTrue("Should also indicate approval is valid.", document.isApprovalRequested());
118 assertEquals("Document should be at AdHoc node.", ADHOC_NODE, document.getNodeNames()[0]);
119
120 document.approve("");
121 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
122 assertTrue("Document should be enroute.", document.stateIsEnroute());
123 assertTrue("Should have approve request.", document.isApprovalRequested());
124 assertEquals("Document should be at WorkflowDocument node.", WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
125 }
126
127
128
129
130
131
132 @Test public void testDefaultInitiatorMustSavePolicy() throws Exception {
133 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME);
134 document.saveRoutingData();
135
136
137 List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
138 assertEquals("There should be no action requests.", 0, actionRequests.size());
139
140
141 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
142 assertTrue(document.stateIsInitiated());
143 try {
144 document.saveDocument("");
145 fail("A WorkflowException should have been thrown.");
146 } catch (WorkflowException e) {
147 e.printStackTrace();
148 }
149
150
151 actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
152 assertEquals("There should be no action requests.", 0, actionRequests.size());
153
154
155 document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), document.getRouteHeaderId());
156 document.saveDocument("");
157 assertTrue(document.stateIsSaved());
158 actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
159 assertEquals("There should be one action request.", 1, actionRequests.size());
160 }
161
162
163
164
165
166 @Test public void testFalseInitiatorMustSavePolicy() throws Exception {
167 WorkflowDocument document = new WorkflowDocument(new NetworkIdDTO("ewestfal"), DOCUMENT_TYPE_NAME_NON_INITIATOR);
168 document.saveRoutingData();
169
170
171 List actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
172 assertEquals("There should be no action requests.", 0, actionRequests.size());
173
174
175 document = new WorkflowDocument(new NetworkIdDTO("rkirkend"), document.getRouteHeaderId());
176 assertTrue(document.stateIsInitiated());
177 try {
178 document.saveDocument("");
179 } catch (WorkflowException e) {
180 e.printStackTrace();
181 fail("A WorkflowException should not have been thrown.");
182 }
183
184
185 assertTrue(document.stateIsSaved());
186 actionRequests = KEWServiceLocator.getActionRequestService().findAllActionRequestsByRouteHeaderId(document.getRouteHeaderId());
187 assertEquals("There should be one action request.", 1, actionRequests.size());
188 }
189 }