001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.actions; 017 018import static org.junit.Assert.assertFalse; 019import static org.junit.Assert.assertTrue; 020import static org.junit.Assert.fail; 021 022import org.junit.Test; 023import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup; 024import org.kuali.rice.kew.api.WorkflowDocument; 025import org.kuali.rice.kew.api.WorkflowDocumentFactory; 026import org.kuali.rice.kew.api.action.ActionType; 027import org.kuali.rice.kew.test.KEWTestCase; 028 029/** 030 * Test SuperUserCancel through WorkflowDocument 031 */ 032public class SuperUserCancelTest extends KEWTestCase { 033 034 protected void loadTestData() throws Exception { 035 loadXmlFile("ActionsConfig.xml"); 036 } 037 038 @Test 039 public void testSuperUserCancel() throws Exception { 040 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME); 041 document.route(""); 042 043 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()); 044 assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_CANCEL)); 045 document.superUserCancel(""); 046 assertTrue("Document should be final after Super User Cancel", document.isCanceled()); 047 } 048 049 @Test 050 public void testSuperUserInitiatorCancel() throws Exception { 051 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME); 052 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL)); 053 document.superUserCancel(""); 054 assertTrue("Document should be final after Super User Cancel", document.isCanceled()); 055 } 056 057 @Test 058 public void testSuperUserNonInitiatorCancel() throws Exception { 059 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("delyea"), NotifySetup.DOCUMENT_TYPE_NAME); 060 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()); 061 assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL)); 062 document.superUserCancel(""); 063 assertTrue("Document should be final after Super User Cancel", document.isCanceled()); 064 } 065 066 @Test 067 public void testSuperUserCancelInvalidUser() throws Exception { 068 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME); 069 document.route(""); 070 071 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId()); 072 try { 073 assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_CANCEL)); 074 document.superUserCancel(""); 075 fail("invalid user attempted to SuperUserApprove"); 076 } catch (Exception e) { 077 } 078 079 } 080 081}