001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.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/ecl2.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 org.kuali.rice.kew.actions;
018
019 import static org.junit.Assert.assertFalse;
020 import static org.junit.Assert.assertTrue;
021 import static org.junit.Assert.fail;
022
023 import org.junit.Test;
024 import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
025 import org.kuali.rice.kew.api.WorkflowDocument;
026 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
027 import org.kuali.rice.kew.api.action.ActionType;
028 import org.kuali.rice.kew.test.KEWTestCase;
029
030 /**
031 * Test SuperUserCancel through WorkflowDocument
032 */
033 public class SuperUserCancelTest extends KEWTestCase {
034
035 protected void loadTestData() throws Exception {
036 loadXmlFile("ActionsConfig.xml");
037 }
038
039 @Test
040 public void testSuperUserCancel() throws Exception {
041 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
042 document.route("");
043
044 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
045 assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
046 document.superUserCancel("");
047 assertTrue("Document should be final after Super User Cancel", document.isCanceled());
048 }
049
050 @Test
051 public void testSuperUserInitiatorCancel() throws Exception {
052 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
053 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
054 document.superUserCancel("");
055 assertTrue("Document should be final after Super User Cancel", document.isCanceled());
056 }
057
058 @Test
059 public void testSuperUserNonInitiatorCancel() throws Exception {
060 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("delyea"), NotifySetup.DOCUMENT_TYPE_NAME);
061 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
062 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
063 document.superUserCancel("");
064 assertTrue("Document should be final after Super User Cancel", document.isCanceled());
065 }
066
067 @Test
068 public void testSuperUserCancelInvalidUser() throws Exception {
069 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
070 document.route("");
071
072 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
073 try {
074 assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
075 document.superUserCancel("");
076 fail("invalid user attempted to SuperUserApprove");
077 } catch (Exception e) {
078 }
079
080 }
081
082 }