1
2
3
4
5
6
7
8
9
10
11
12
13
14
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("");
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
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
64 TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
65 document.disapprove("");
66 TestUtilities.assertAtNode(document, NotifySetup.NOTIFY_FINAL_NODE);
67
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
82
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
90 document = WorkflowDocumentFactory.loadDocument(getPrincipalIdForName("shenl"), document.getDocumentId());
91 assertFalse("ack should be requested as part of disapprove notification", document.isAcknowledgeRequested());
92
93
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
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
105 assertEquals("temay should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
106
107
108 assertEquals("temay should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("temay", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
109
110
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
115 assertEquals("jitrue should have been sent an approve email", 1, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
116
117 assertEquals("jitrue should have been sent an ack email", 0, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
118
119
120 assertEquals("natjohns should not have been sent an approve email", 0, getMockEmailService().immediateReminderEmailsSent("natjohns", document.getDocumentId(), KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
121
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
132
133
134
135 @Test public void testInitiatorRoleDisapprove() throws WorkflowException {
136
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
149
150
151
152 @Test public void testInitiatorDisapprove() throws WorkflowException {
153
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
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 }