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.actions.BlanketApproveTest.NotifySetup;
028: import edu.iu.uis.eden.clientapp.WorkflowDocument;
029: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030: import edu.iu.uis.eden.test.TestUtilities;
031:
032: /**
033: * Tests the super user actions available on the API.
034: */
035: public class SuperUserActionTest extends WorkflowTestCase {
036:
037: protected void loadTestData() throws Exception {
038: loadXmlFile("ActionsConfig.xml");
039: }
040:
041: @Test
042: public void testSuperUserApprove() throws Exception {
043: WorkflowDocument document = new WorkflowDocument(
044: new NetworkIdVO("ewestfal"),
045: NotifySetup.DOCUMENT_TYPE_NAME);
046: document.routeDocument("");
047:
048: document = new WorkflowDocument(new NetworkIdVO("jhopf"),
049: document.getRouteHeaderId());
050: assertTrue(
051: "WorkflowDocument should indicate jhopf as SuperUser",
052: document.isSuperUser());
053: document.super UserApprove("");
054: assertTrue(
055: "Document should be 'processed' after Super User Approve",
056: document.stateIsProcessed());
057: List requests = KEWServiceLocator.getActionRequestService()
058: .findPendingByDoc(document.getRouteHeaderId());
059: assertTrue("Should be active requests still",
060: requests.size() == 2);//number of acks and fyi's configured through rules
061: for (Iterator iter = requests.iterator(); iter.hasNext();) {
062: ActionRequestValue request = (ActionRequestValue) iter
063: .next();
064: if (request.isApproveOrCompleteRequest()) {
065: fail("There should be no approve or complete requests after su approve");
066: }
067: }
068: }
069:
070: @Test
071: public void testSuperUserApproveExceptionCases() throws Exception {
072: WorkflowDocument document = new WorkflowDocument(
073: new NetworkIdVO("user1"), "SUApproveDocument");
074: document.routeDocument("");
075: document = new WorkflowDocument(new NetworkIdVO("user2"),
076: document.getRouteHeaderId());
077: try {
078: document.approve("");
079: } catch (Exception e) {
080: }
081: TestUtilities.getExceptionThreader().join();
082: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
083: document.getRouteHeaderId());
084: assertTrue("Document should be in exception routing", document
085: .stateIsException());
086: document.super UserApprove("");
087: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
088: document.getRouteHeaderId());
089: assertTrue("Document should be final", document.stateIsFinal());
090:
091: List actionRequests = KEWServiceLocator
092: .getActionRequestService().findPendingByDoc(
093: document.getRouteHeaderId());
094: assertTrue(
095: "Should be no active requests for SU Approved document",
096: actionRequests.isEmpty());
097: }
098:
099: @Test
100: public void testSuperUserApproveExceptionCasesWithNotifications()
101: throws Exception {
102: WorkflowDocument document = new WorkflowDocument(
103: new NetworkIdVO("user1"),
104: "SUApproveDocumentNotifications");
105: document.routeDocument("");
106: document = new WorkflowDocument(new NetworkIdVO("user2"),
107: document.getRouteHeaderId());
108: try {
109: document.approve("");
110: } catch (Exception e) {
111: }
112: TestUtilities.getExceptionThreader().join();
113: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
114: document.getRouteHeaderId());
115: assertTrue("Document should be in exception routing", document
116: .stateIsException());
117: document.super UserApprove("");
118: document = new WorkflowDocument(new NetworkIdVO("rkirkend"),
119: document.getRouteHeaderId());
120: assertTrue("Document should be 'processed'", document
121: .stateIsProcessed());
122:
123: List actionRequests = KEWServiceLocator
124: .getActionRequestService().findPendingByDoc(
125: document.getRouteHeaderId());
126: assertFalse(
127: "Should be active requests for SU Approved document",
128: actionRequests.isEmpty());
129: for (Iterator iter = actionRequests.iterator(); iter.hasNext();) {
130: ActionRequestValue request = (ActionRequestValue) iter
131: .next();
132: assertTrue("Should be an ack notification request", request
133: .isAcknowledgeRequest());
134: }
135: }
136:
137: @Test
138: public void testSuperUserInitiatorApprove() throws Exception {
139: WorkflowDocument document = new WorkflowDocument(
140: new NetworkIdVO("ewestfal"),
141: NotifySetup.DOCUMENT_TYPE_NAME);
142: assertTrue(
143: "WorkflowDocument should indicate ewestfal as SuperUser",
144: document.isSuperUser());
145: document.super UserApprove("");
146: assertTrue(
147: "Document should be 'processed' after Super User Approve",
148: document.stateIsProcessed());
149: List requests = KEWServiceLocator.getActionRequestService()
150: .findPendingByDoc(document.getRouteHeaderId());
151: assertTrue("Should be active requests still",
152: requests.size() == 2);//number of acks and fyi's configured through rules
153: for (Iterator iter = requests.iterator(); iter.hasNext();) {
154: ActionRequestValue request = (ActionRequestValue) iter
155: .next();
156: if (request.isApproveOrCompleteRequest()) {
157: fail("There should be no approve or complete requests after su approve");
158: }
159: }
160: }
161:
162: @Test
163: public void testSuperUserApproveWithNotifications()
164: throws Exception {
165: WorkflowDocument document = new WorkflowDocument(
166: new NetworkIdVO("ewestfal"), "NotificationTestChild");
167: assertTrue(
168: "WorkflowDocument should indicate ewestfal as SuperUser",
169: document.isSuperUser());
170: document.super UserApprove("");
171: assertTrue(
172: "Document should be 'processed' after Super User Approve",
173: document.stateIsProcessed());
174: List requests = KEWServiceLocator.getActionRequestService()
175: .findPendingByDoc(document.getRouteHeaderId());
176: assertTrue("Should be active requests still",
177: requests.size() > 2);//number of acks and fyi's configured through rules - we need these for approvals too
178: for (Iterator iter = requests.iterator(); iter.hasNext();) {
179: ActionRequestValue request = (ActionRequestValue) iter
180: .next();
181: if (request.isApproveOrCompleteRequest()) {
182: fail("There should be no approve or complete requests after su approve");
183: }
184: }
185: }
186:
187: @Test
188: public void testSuperUserApproveInvalidUser() throws Exception {
189: WorkflowDocument document = new WorkflowDocument(
190: new NetworkIdVO("ewestfal"),
191: NotifySetup.DOCUMENT_TYPE_NAME);
192: document.routeDocument("");
193:
194: document = new WorkflowDocument(new NetworkIdVO("quickstart"),
195: document.getRouteHeaderId());
196: try {
197: assertFalse(
198: "WorkflowDocument should not indicate quickstart as SuperUser",
199: document.isSuperUser());
200: document.super UserApprove("");
201: fail("invalid user attempted to SuperUserApprove");
202: } catch (Exception e) {
203: }
204:
205: }
206:
207: }
|