View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.junit.Test;
19  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
20  import org.kuali.rice.kew.api.WorkflowDocument;
21  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
22  import org.kuali.rice.kew.api.action.ActionType;
23  import org.kuali.rice.kew.test.KEWTestCase;
24  
25  import static org.junit.Assert.*;
26  
27  /**
28   * Test SuperUserDissaprove actions from WorkflowDocument
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class SuperUserDisapproveTest extends KEWTestCase {
33      private static final String DOC_TYPE = NotifySetup.DOCUMENT_TYPE_NAME;
34      private static final String DOC_TYPE_WITH_NOTIFY = "SUDisapproveWithNotificationTest";
35  
36      protected void loadTestData() throws Exception {
37          loadXmlFile("ActionsConfig.xml");
38      }
39  	
40      @Test public void testSuperUserDisapprove() throws Exception {
41          superUserDisapprove(false);
42      }
43  
44      @Test public void testSuperUserDisapproveWithNotification() throws Exception {
45          superUserDisapprove(true);
46      }
47  
48      protected void superUserDisapprove(boolean notify) throws Exception {
49          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
50          document.route("");
51  
52          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
53          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
54          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
55  
56          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
57          assertTrue("WorkflowDocument should indicate jhopf as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
58          document.superUserDisapprove("");
59          assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
60          if (notify) {
61              assertTrue(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
62              assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
63              assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
64              // jhopf took the super user action so should not be notified of disapproval (see KULRICE-752)
65              assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
66          }
67  	}
68  	
69      @Test public void testSuperUserInitiatorDisapprove() throws Exception {
70          superUserInitiatorDisapprove(false);
71      }
72  
73      @Test public void testSuperUserInitiatorDisapproveWithNotification() throws Exception {
74          superUserInitiatorDisapprove(true);
75      }
76      
77      protected void superUserInitiatorDisapprove(boolean notify) throws Exception {
78  		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
79          document.route("");
80          
81          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).approve("");
82          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).approve("");
83          WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).approve("");
84  
85          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
86          assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
87          document.superUserDisapprove("");
88          assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
89          if (notify) {
90              assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId()).isAcknowledgeRequested());
91              assertTrue(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId()).isAcknowledgeRequested());
92              // initiator doesn't get Ack for their own action
93              assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
94          }
95  	}
96  
97      @Test public void testSuperUserInitiatorImmediateDisapprove() throws Exception {
98          superUserInitiatorImmediateDisapprove(false);
99      }
100 
101     @Test public void testSuperUserInitiatorImmediateDisapproveWithNotification() throws Exception {
102         superUserInitiatorImmediateDisapprove(true);
103     }
104 
105     protected void superUserInitiatorImmediateDisapprove(boolean notify) throws Exception {
106         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), notify ? DOC_TYPE_WITH_NOTIFY: DOC_TYPE);
107         assertTrue("WorkflowDocument should indicate ewestfal as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
108         document.superUserDisapprove("");
109         assertTrue("Document should be final after Super User Disapprove", document.isDisapproved());
110         // initiator doesn't get Ack for their own action
111         assertFalse(WorkflowDocumentFactory.loadDocument(document.getInitiatorPrincipalId(), document.getDocumentId()).isAcknowledgeRequested());
112         assertFalse(WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId()).isAcknowledgeRequested());
113     }
114 	
115     @Test public void testSuperUserDisapproveInvalidUser() throws Exception {
116 		WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
117         document.route("");
118         
119         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("quickstart"), document.getDocumentId());
120         try {
121         	assertFalse("WorkflowDocument should not indicate quickstart as SuperUser", document.isValidAction(ActionType.SU_DISAPPROVE));
122         	document.superUserDisapprove("");
123         	fail("invalid user attempted to SuperUserApprove");
124         } catch (Exception e) {
125         }
126         
127 	}
128 	
129 }