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 static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertFalse;
20  import static org.junit.Assert.assertTrue;
21  import mocks.MockEmailNotificationService;
22  
23  import org.junit.Ignore;
24  import org.junit.Test;
25  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
26  import org.kuali.rice.kew.api.WorkflowDocument;
27  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
28  import org.kuali.rice.kew.api.exception.WorkflowException;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kew.test.KEWTestCase;
31  import org.kuali.rice.kew.test.TestUtilities;
32  import org.kuali.rice.kew.api.KewApiConstants;
33  
34  public class DisapproveActionTest extends KEWTestCase {
35  
36      protected void loadTestData() throws Exception {
37          loadXmlFile("ActionsConfig.xml");
38      }
39  
40      @Test public void testDisapprove() throws Exception {
41          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
42          document.route("");
43  
44          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
45          assertTrue("This user should have an approve request", document.isApprovalRequested());
46          document.approve("");
47  
48          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
49          assertTrue("This user should have an approve request", document.isApprovalRequested());
50          document.approve("");//ewestfal had force action rule
51  
52          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
53          assertTrue("This user should have an approve request", document.isApprovalRequested());
54          document.approve("");
55  
56          //this be the role delegate of jitrue
57          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
58          assertTrue("This user should have an approve request", document.isApprovalRequested());
59          document.approve("");
60  
61          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
62          assertTrue("This user should have an approve request", document.isApprovalRequested());
63          // assert that the document is at the same node before and after disapprove
64          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
65          document.disapprove("");
66          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
67          // reload just to double check
68          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
69          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
70  
71          assertTrue("Document should be disapproved", document.isDisapproved());
72          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
73          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
74  
75          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
76          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
77  
78          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
79          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
80  
81          //jitrue while part of original approval chain did not take approve action and therefore should
82          //not get action
83          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jitrue"), document.getDocumentId());
84          assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
85  
86          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
87          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
88  
89          //shenl part of approval chain but didn't take action
90          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("shenl"), document.getDocumentId());
91          assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
92  
93          //check that all the emailing went right.
94          assertEquals("jhopf should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
95          assertEquals("jhopf should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
96  
97          assertEquals("ewestfal should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
98          assertEquals("ewestfal should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
99  
100         //rkirkend is a primary delegate and therefore should not receive email notification
101         assertEquals("rkirkend should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
102         assertEquals("rkirkend should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
103 
104         //temay is rkirkend primary delegate she should have received notification
105         assertEquals("temay should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
106 
107         //there should be no ack emails for temay
108         assertEquals("temay should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
109 
110         // pmckown is a secondary delegate here so he should NOT have received a notification
111         assertEquals("pmckown should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("pmckown", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
112         assertEquals("pmckown should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("pmckown", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
113 
114         //this is a secondary delegator and should receive notifications
115         assertEquals("jitrue should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
116         //no ack emails to jitrue
117         assertEquals("jitrue should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
118 
119         //the 2nd delegates should NOT receive notifications by default
120         assertEquals("natjohns should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
121         //2ndary delegate
122         assertEquals("natjohns should not have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
123         assertEquals("shenl should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("shenl", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
124         assertEquals("shenl should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("shenl", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
125 
126         assertEquals("bmcgough should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
127         assertEquals("bmcgough should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
128     }
129 
130     /**
131      * Tests whether the initator who disapproved a doc gets an acknowledgement
132      *
133      */
134     @Test public void testInitiatorRoleDisapprove() throws WorkflowException {
135         // test initiator disapproval of their own doc via InitiatorRoleAttribute
136         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("arh14"), "InitiatorRoleApprovalTest");
137         document.route("routing document");
138 
139         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
140         document.disapprove("disapproving the document");
141 
142         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
143         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
144     }
145 
146     /**
147      * Tests whether the initiator who disapproved a doc gets an acknowledgement
148      * 
149      */
150     @Test public void testInitiatorDisapprove() throws WorkflowException {
151         // test initiator disapproval, via normal request with forceAction=true
152         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
153         document.route("");
154 
155         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
156         document.disapprove("");
157 
158         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
159         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
160     }
161 
162     @Test public void testDisapproveByArbitraryRecipient() throws WorkflowException {
163         // test approval by some other person
164         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveSequentialTest");
165         document.route("");
166 
167         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
168         document.disapprove("disapproving as bmcgough");
169 
170         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
171         assertFalse("Acknowledge was incorrectly sent to non-initiator disapprover", document.isAcknowledgeRequested());
172 
173         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
174         assertTrue("Acknowledge was not sent to initiator", document.isAcknowledgeRequested());
175     }
176 
177     private MockEmailNotificationService getMockEmailService() {
178         return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
179     }
180 }