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.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     @Ignore("This test will fail until KULRICE-752 is resolved")
135     @Test public void testInitiatorRoleDisapprove() throws WorkflowException {
136         // test initiator disapproval of their own doc via InitiatorRoleAttribute
137         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("arh14"), "InitiatorRoleApprovalTest");
138         document.route("routing document");
139 
140         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
141         document.disapprove("disapproving the document");
142 
143         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
144         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
145     }
146 
147     /**
148      * Tests whether the initator who disapproved a doc gets an acknowledgement
149      * 
150      */
151     @Ignore("This test will fail until KULRICE-752 is resolved")
152     @Test public void testInitiatorDisapprove() throws WorkflowException {
153         // test initiator disapproval, via normal request with forceAction=true
154         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
155         document.route("");
156 
157         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
158         document.disapprove("");
159 
160         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
161         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
162     }
163 
164     @Test public void testDisapproveByArbitraryRecipient() throws WorkflowException {
165         // test approval by some other person
166         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveSequentialTest");
167         document.route("");
168 
169         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
170         document.disapprove("disapproving as bmcgough");
171 
172         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
173         assertFalse("Acknowledge was incorrectly sent to non-initiator disapprover", document.isAcknowledgeRequested());
174 
175         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
176         assertTrue("Acknowledge was not sent to initiator", document.isAcknowledgeRequested());
177     }
178 
179     private MockEmailNotificationService getMockEmailService() {
180         return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
181     }
182 }