1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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("");
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
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
65 TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
66 document.disapprove("");
67 TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
68
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
83
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
91 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("shenl"), document.getDocumentId());
92 assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
93
94
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
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
106 assertEquals("temay should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
107
108
109 assertEquals("temay should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
110
111
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
116 assertEquals("jitrue should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
117
118 assertEquals("jitrue should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
119
120
121 assertEquals("natjohns should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
122
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
133
134
135 @Ignore("This test will fail until KULRICE-752 is resolved")
136 @Test public void testInitiatorRoleDisapprove() throws WorkflowException {
137
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
150
151
152 @Ignore("This test will fail until KULRICE-752 is resolved")
153 @Test public void testInitiatorDisapprove() throws WorkflowException {
154
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
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 }