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