View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actions;
17  
18  import static org.junit.Assert.assertFalse;
19  import static org.junit.Assert.assertTrue;
20  import static org.junit.Assert.fail;
21  
22  import org.junit.Test;
23  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
24  import org.kuali.rice.kew.api.WorkflowDocument;
25  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26  import org.kuali.rice.kew.api.action.ActionType;
27  import org.kuali.rice.kew.test.KEWTestCase;
28  
29  /**
30   * Test SuperUserCancel through WorkflowDocument
31   */
32  public class SuperUserCancelTest extends KEWTestCase {
33  
34      protected void loadTestData() throws Exception {
35  	loadXmlFile("ActionsConfig.xml");
36      }
37  
38      @Test
39      public void testSuperUserCancel() throws Exception {
40  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
41  	document.route("");
42  
43  	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
44  	assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
45  	document.superUserCancel("");
46  	assertTrue("Document should be final after Super User Cancel", document.isCanceled());
47      }
48  
49      @Test
50      public void testSuperUserInitiatorCancel() throws Exception {
51  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
52  	assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
53  	document.superUserCancel("");
54  	assertTrue("Document should be final after Super User Cancel", document.isCanceled());
55      }
56  
57      @Test
58      public void testSuperUserNonInitiatorCancel() throws Exception {
59  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("delyea"), NotifySetup.DOCUMENT_TYPE_NAME);
60  	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
61  	assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
62  	document.superUserCancel("");
63  	assertTrue("Document should be final after Super User Cancel", document.isCanceled());
64      }
65  
66      @Test
67      public void testSuperUserCancelInvalidUser() throws Exception {
68  	WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
69  	document.route("");
70  
71  	document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
72  	try {
73  	    assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_CANCEL));
74  	    document.superUserCancel("");
75  	    fail("invalid user attempted to SuperUserApprove");
76  	} catch (Exception e) {
77  	}
78  
79      }
80  
81  }