View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.actions;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertFalse;
21  import static org.junit.Assert.assertTrue;
22  import mocks.MockEmailNotificationService;
23  
24  import org.junit.Ignore;
25  import org.junit.Test;
26  import org.kuali.rice.kew.actions.BlanketApproveTest.NotifySetup;
27  import org.kuali.rice.kew.api.WorkflowDocument;
28  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
29  import org.kuali.rice.kew.exception.WorkflowException;
30  import org.kuali.rice.kew.service.KEWServiceLocator;
31  import org.kuali.rice.kew.test.KEWTestCase;
32  import org.kuali.rice.kew.test.TestUtilities;
33  import org.kuali.rice.kew.util.KEWConstants;
34  
35  public class DisapproveActionTest extends KEWTestCase {
36  
37      protected void loadTestData() throws Exception {
38          loadXmlFile("ActionsConfig.xml");
39      }
40  
41      @Test public void testDisapprove() throws Exception {
42          WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
43          document.route("");
44  
45          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
46          assertTrue("This user should have an approve request", document.isApprovalRequested());
47          document.approve("");
48  
49          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
50          assertTrue("This user should have an approve request", document.isApprovalRequested());
51          document.approve("");//ewestfal had force action rule
52  
53          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
54          assertTrue("This user should have an approve request", document.isApprovalRequested());
55          document.approve("");
56  
57          //this be the role delegate of jitrue
58          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
59          assertTrue("This user should have an approve request", document.isApprovalRequested());
60          document.approve("");
61  
62          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
63          assertTrue("This user should have an approve request", document.isApprovalRequested());
64          // assert that the document is at the same node before and after disapprove
65          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
66          document.disapprove("");
67          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
68          // reload just to double check
69          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
70          TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
71  
72          assertTrue("Document should be disapproved", document.isDisapproved());
73          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
74          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
75  
76          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jhopf"), document.getDocumentId());
77          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
78  
79          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("rkirkend"), document.getDocumentId());
80          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
81  
82          //jitrue while part of original approval chain did not take approve action and therefore should
83          //not get action
84          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("jitrue"), document.getDocumentId());
85          assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
86  
87          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("natjohns"), document.getDocumentId());
88          assertTrue("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
89  
90          //shenl part of approval chain but didn't take action
91          document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("shenl"), document.getDocumentId());
92          assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
93  
94          //check that all the emailing went right.
95          assertEquals("jhopf should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
96          assertEquals("jhopf should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
97  
98          assertEquals("ewestfal should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
99          assertEquals("ewestfal should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
100 
101         //rkirkend is a primary delegate and therefore should not receive email notification
102         assertEquals("rkirkend should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
103         assertEquals("rkirkend should have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
104 
105         //temay is rkirkend primary delegate she should have received notification
106         assertEquals("temay should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
107 
108         //there should be no ack emails for temay
109         assertEquals("temay should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
110 
111         // pmckown is a secondary delegate here so he should NOT have received a notification
112         assertEquals("pmckown should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("pmckown", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
113         assertEquals("pmckown should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("pmckown", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
114 
115         //this is a secondary delegator and should receive notifications
116         assertEquals("jitrue should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
117         //no ack emails to jitrue
118         assertEquals("jitrue should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
119 
120         //the 2nd delegates should NOT receive notifications by default
121         assertEquals("natjohns should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
122         //2ndary delegate
123         assertEquals("natjohns should not have been sent an ack email", 1, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
124         assertEquals("shenl should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("shenl", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
125         assertEquals("shenl should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("shenl", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
126 
127         assertEquals("bmcgough should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
128         assertEquals("bmcgough should not have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
129     }
130 
131     /**
132      * Tests whether the initator who disapproved a doc gets an acknowledgement
133      *
134      */
135     @Ignore("This test will fail until KULRICE-752 is resolved")
136     @Test public void testInitiatorRoleDisapprove() throws WorkflowException {
137         // test initiator disapproval of their own doc via InitiatorRoleAttribute
138         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("arh14"), "InitiatorRoleApprovalTest");
139         document.route("routing document");
140 
141         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
142         document.disapprove("disapproving the document");
143 
144         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("arh14"), document.getDocumentId());
145         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
146     }
147 
148     /**
149      * Tests whether the initator who disapproved a doc gets an acknowledgement
150      * 
151      */
152     @Ignore("This test will fail until KULRICE-752 is resolved")
153     @Test public void testInitiatorDisapprove() throws WorkflowException {
154         // test initiator disapproval, via normal request with forceAction=true
155         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), NotifySetup.DOCUMENT_TYPE_NAME);
156         document.route("");
157 
158         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
159         document.disapprove("");
160 
161         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
162         assertFalse("Initiator should not have an Ack request from disapproval because they were the disapprover user", document.isAcknowledgeRequested());
163     }
164 
165     @Test public void testDisapproveByArbitraryRecipient() throws WorkflowException {
166         // test approval by some other person
167         WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("ewestfal"), "BlanketApproveSequentialTest");
168         document.route("");
169 
170         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
171         document.disapprove("disapproving as bmcgough");
172 
173         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("bmcgough"), document.getDocumentId());
174         assertFalse("Acknowledge was incorrectly sent to non-initiator disapprover", document.isAcknowledgeRequested());
175 
176         document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("ewestfal"), document.getDocumentId());
177         assertTrue("Acknowledge was not sent to initiator", document.isAcknowledgeRequested());
178     }
179 
180     private MockEmailNotificationService getMockEmailService() {
181         return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
182     }
183 }