001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.actions;
018:
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.junit.Test;
023: import org.kuali.workflow.test.WorkflowTestCase;
024:
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.actionrequests.ActionRequestValue;
027: import edu.iu.uis.eden.clientapp.WorkflowDocument;
028: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
029: import edu.iu.uis.eden.exception.WorkflowException;
030:
031: public class SaveActionEventTest extends WorkflowTestCase {
032:
033: public static final String DOCUMENT_TYPE_NAME = "SaveActionEventTest";
034: public static final String DOCUMENT_TYPE_NAME_NON_INITIATOR = "SaveActionEventTestNonInitiator";
035: public static final String ADHOC_NODE = "AdHoc";
036: public static final String WORKFLOW_DOCUMENT_NODE = "WorkflowDocument";
037:
038: protected void loadTestData() throws Exception {
039: loadXmlFile("ActionsConfig.xml");
040: }
041:
042: @Test
043: public void testSaveActionEvent() throws Exception {
044: WorkflowDocument document = new WorkflowDocument(
045: new NetworkIdVO("ewestfal"), DOCUMENT_TYPE_NAME);
046: document.saveRoutingData();
047: assertTrue("Document should be initiated.", document
048: .stateIsInitiated());
049: List actionRequests = KEWServiceLocator
050: .getActionRequestService()
051: .findAllActionRequestsByRouteHeaderId(
052: document.getRouteHeaderId());
053: assertEquals("There should be no action requests.", 0,
054: actionRequests.size());
055: assertTrue("Document should be initiated.", document
056: .stateIsInitiated());
057: document.saveDocument("");
058:
059: // document should be SAVED now at the AdHoc node
060: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
061: document.getRouteHeaderId());
062: assertEquals("Document should be at AdHoc node.", ADHOC_NODE,
063: document.getNodeNames()[0]);
064: assertTrue("Document should be SAVED.", document.stateIsSaved());
065: // there should now be one COMPLETE request to the initiator
066: actionRequests = KEWServiceLocator.getActionRequestService()
067: .findAllActionRequestsByRouteHeaderId(
068: document.getRouteHeaderId());
069: assertEquals(
070: "There should be one COMPLETE request to the initiator.",
071: 1, actionRequests.size());
072: assertTrue("Initiator should have complete request.", document
073: .isCompletionRequested());
074: ActionRequestValue savedRequest = (ActionRequestValue) actionRequests
075: .get(0);
076: assertNotNull(savedRequest);
077: assertTrue("Saved request should be a complete request.",
078: savedRequest.isCompleteRequst());
079: assertEquals("Request should be at the AdHoc node.",
080: ADHOC_NODE, savedRequest.getNodeInstance().getName());
081:
082: // if we try and call route document as rkirkend, it should throw an InvalidActionTakenException
083: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
084: document.getRouteHeaderId());
085: try {
086: document.routeDocument("");
087: fail("RouteDocument should have thrown an exception because we aren't the initiator");
088: } catch (WorkflowException e) {
089: }
090:
091: // now, route document as the initiator
092: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
093: document.getRouteHeaderId());
094: document.routeDocument("Routing Rowdy Roddy Pipper");
095:
096: // document should be marked as ENROUTE, move to the WorkflowDocument node,
097: // and approve requests to rkirkend and bmcgough should be generated
098: actionRequests = KEWServiceLocator.getActionRequestService()
099: .findPendingByDoc(document.getRouteHeaderId());
100: assertEquals("Should be 2 pending requests.", 2, actionRequests
101: .size());
102: // rkirkend should have request
103: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
104: document.getRouteHeaderId());
105: assertTrue("Document should be in routing.", document
106: .stateIsEnroute());
107: assertTrue("rkirkend should have approve request.", document
108: .isApprovalRequested());
109: // bmcgough should have request
110: document = new WorkflowDocument(new NetworkIdVO("bmcgough"),
111: document.getRouteHeaderId());
112: assertTrue("Document should be in routing.", document
113: .stateIsEnroute());
114: assertTrue("bmcgough should have approve request.", document
115: .isApprovalRequested());
116:
117: // check node and requests
118: assertEquals("Document should be at WorkflowDocument node.",
119: WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
120: for (Iterator iterator = actionRequests.iterator(); iterator
121: .hasNext();) {
122: ActionRequestValue request = (ActionRequestValue) iterator
123: .next();
124: assertNotNull(request.getNodeInstance());
125: assertEquals("Request should be at WorkflowDocument node.",
126: WORKFLOW_DOCUMENT_NODE, request.getNodeInstance()
127: .getName());
128: }
129:
130: // now, since saveDocument effectively sets the status to saved and generates a complete request, let make sure that we can
131: // take a complete or approve action against the doc to make it transition
132: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
133: DOCUMENT_TYPE_NAME);
134: document.saveDocument("");
135: assertTrue("Document should be saved.", document.stateIsSaved());
136: assertTrue("Should have complete request.", document
137: .isCompletionRequested());
138: assertEquals("Document should be at AdHoc node.", ADHOC_NODE,
139: document.getNodeNames()[0]);
140: // take the complete action
141: document.complete("");
142: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
143: document.getRouteHeaderId());
144: assertTrue("Document should be enroute.", document
145: .stateIsEnroute());
146: assertTrue("Should have approve request.", document
147: .isApprovalRequested());
148: assertEquals("Document should be at WorkflowDocument node.",
149: WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
150:
151: // try above scenario with approve because approve should count for completion
152: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
153: DOCUMENT_TYPE_NAME);
154: document.saveDocument("");
155: assertTrue("Document should be saved.", document.stateIsSaved());
156: assertTrue("Should have complete request.", document
157: .isCompletionRequested());
158: assertTrue("Should also indicate approval is valid.", document
159: .isApprovalRequested());
160: assertEquals("Document should be at AdHoc node.", ADHOC_NODE,
161: document.getNodeNames()[0]);
162: // take the approve action
163: document.approve("");
164: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
165: document.getRouteHeaderId());
166: assertTrue("Document should be enroute.", document
167: .stateIsEnroute());
168: assertTrue("Should have approve request.", document
169: .isApprovalRequested());
170: assertEquals("Document should be at WorkflowDocument node.",
171: WORKFLOW_DOCUMENT_NODE, document.getNodeNames()[0]);
172: }
173:
174: /**
175: * Tests for when INITIATOR_MUST_SAVE policy is equal to true (default value). In this case if non-initiator user
176: * attempts a save of a document with this policy an exception should be thrown
177: */
178: @Test
179: public void testDefaultInitiatorMustSavePolicy() throws Exception {
180: WorkflowDocument document = new WorkflowDocument(
181: new NetworkIdVO("ewestfal"), DOCUMENT_TYPE_NAME);
182: document.saveRoutingData();
183:
184: // verify that there are no requests that have been generated
185: List actionRequests = KEWServiceLocator
186: .getActionRequestService()
187: .findAllActionRequestsByRouteHeaderId(
188: document.getRouteHeaderId());
189: assertEquals("There should be no action requests.", 0,
190: actionRequests.size());
191:
192: // try saving as a user who's not ewestfal
193: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
194: document.getRouteHeaderId());
195: assertTrue(document.stateIsInitiated());
196: try {
197: document.saveDocument("");
198: fail("A WorkflowException should have been thrown.");
199: } catch (WorkflowException e) {
200: e.printStackTrace();
201: }
202:
203: // ensure that the request did not get generated
204: actionRequests = KEWServiceLocator.getActionRequestService()
205: .findAllActionRequestsByRouteHeaderId(
206: document.getRouteHeaderId());
207: assertEquals("There should be no action requests.", 0,
208: actionRequests.size());
209:
210: // now save it as the intiator and it should be successful and generate a request
211: document = new WorkflowDocument(new NetworkIdVO("ewestfal"),
212: document.getRouteHeaderId());
213: document.saveDocument("");
214: assertTrue(document.stateIsSaved());
215: actionRequests = KEWServiceLocator.getActionRequestService()
216: .findAllActionRequestsByRouteHeaderId(
217: document.getRouteHeaderId());
218: assertEquals("There should be one action request.", 1,
219: actionRequests.size());
220: }
221:
222: /**
223: * Tests for when INITIATOR_MUST_SAVE policy is equal to false. In this case if non-initiator user
224: * attempts a save of a document with this policy an exception should NOT be thrown
225: */
226: @Test
227: public void testFalseInitiatorMustSavePolicy() throws Exception {
228: WorkflowDocument document = new WorkflowDocument(
229: new NetworkIdVO("ewestfal"),
230: DOCUMENT_TYPE_NAME_NON_INITIATOR);
231: document.saveRoutingData();
232:
233: // verify that there are no requests that have been generated
234: List actionRequests = KEWServiceLocator
235: .getActionRequestService()
236: .findAllActionRequestsByRouteHeaderId(
237: document.getRouteHeaderId());
238: assertEquals("There should be no action requests.", 0,
239: actionRequests.size());
240:
241: // try saving as a user who's not ewestfal
242: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
243: document.getRouteHeaderId());
244: assertTrue(document.stateIsInitiated());
245: try {
246: document.saveDocument("");
247: } catch (WorkflowException e) {
248: e.printStackTrace();
249: fail("A WorkflowException should not have been thrown.");
250: }
251:
252: // ensure that the document was saved and the request was generated
253: assertTrue(document.stateIsSaved());
254: actionRequests = KEWServiceLocator.getActionRequestService()
255: .findAllActionRequestsByRouteHeaderId(
256: document.getRouteHeaderId());
257: assertEquals("There should be one action request.", 1,
258: actionRequests.size());
259: }
260: }
|