1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.notification;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
21 import mocks.MockEmailNotificationService;
22
23 import org.junit.Test;
24 import org.kuali.rice.kew.api.WorkflowDocument;
25 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
26 import org.kuali.rice.kew.api.action.ActionRequestType;
27 import org.kuali.rice.kew.doctype.bo.DocumentType;
28 import org.kuali.rice.kew.preferences.Preferences;
29 import org.kuali.rice.kew.preferences.service.PreferencesService;
30 import org.kuali.rice.kew.service.KEWServiceLocator;
31 import org.kuali.rice.kew.test.KEWTestCase;
32 import org.kuali.rice.kew.util.KEWConstants;
33
34
35 public class NotificationServiceTest extends KEWTestCase {
36
37 protected void loadTestData() throws Exception {
38 loadXmlFile("NotificationConfig.xml");
39 }
40
41
42
43
44 @Test public void testNoDuplicateEmails() throws Exception {
45 WorkflowDocument document = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("user1"), "NotificationTest");
46 document.route("");
47
48 assertEquals("rkirkend should only have one email.", 1, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
49 assertEquals("ewestfal should only have one email.", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
50 assertEquals("jhopf should only have one email.", 1, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
51
52 assertEquals("bmcgough should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
53
54 assertEquals("jitrue should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
55
56 assertEquals("user1 should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("user1", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
57
58 }
59
60
61
62
63
64
65
66
67 @Test public void testEmailPreferences() throws Exception {
68 String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
69 String jitruePrincipalId = getPrincipalIdForName("jitrue");
70 String rkirkendPrincipalId = getPrincipalIdForName("rkirkend");
71 String jhopfPrincipalId = getPrincipalIdForName("jhopf");
72 String bmcgoughPrincipalId = getPrincipalIdForName("bmcgough");
73 String user1PrincipalId = getPrincipalIdForName("user1");
74
75
76 assertDefaultNotificationPreferences(ewestfalPrincipalId);
77 assertDefaultNotificationPreferences(jitruePrincipalId);
78 assertDefaultNotificationPreferences(rkirkendPrincipalId);
79 assertDefaultNotificationPreferences(jhopfPrincipalId);
80 assertDefaultNotificationPreferences(bmcgoughPrincipalId);
81
82
83
84 Preferences prefs = getPreferencesService().getPreferences(ewestfalPrincipalId);
85 prefs.setNotifySecondaryDelegation(KEWConstants.PREFERENCES_YES_VAL);
86 prefs.setEmailNotification(KEWConstants.EMAIL_RMNDR_NO_VAL);
87 getPreferencesService().savePreferences(ewestfalPrincipalId, prefs);
88 prefs = getPreferencesService().getPreferences(jitruePrincipalId);
89 prefs.setNotifySecondaryDelegation(KEWConstants.PREFERENCES_YES_VAL);
90 getPreferencesService().savePreferences(jitruePrincipalId, prefs);
91
92
93 prefs = getPreferencesService().getPreferences(rkirkendPrincipalId);
94 prefs.setNotifyPrimaryDelegation(KEWConstants.PREFERENCES_NO_VAL);
95 getPreferencesService().savePreferences(rkirkendPrincipalId, prefs);
96
97
98 prefs = getPreferencesService().getPreferences(bmcgoughPrincipalId);
99 prefs.setEmailNotification(KEWConstants.EMAIL_RMNDR_DAY_VAL);
100 getPreferencesService().savePreferences(bmcgoughPrincipalId, prefs);
101
102
103 prefs = getPreferencesService().getPreferences(jhopfPrincipalId);
104 prefs.setEmailNotification(KEWConstants.EMAIL_RMNDR_NO_VAL);
105 getPreferencesService().savePreferences(jhopfPrincipalId, prefs);
106
107
108 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1PrincipalId, "NotificationTest");
109 document.route("");
110
111
112 assertEquals("ewestfal should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
113 assertEquals("jitrue should have one email.", 1, getMockEmailService().immediateReminderEmailsSent("jitrue", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
114
115
116 assertEquals("rkirkend should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("rkirkend", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
117
118
119 assertEquals("jhopf should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("jhopf", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
120
121
122 assertEquals("bmcgough should have no emails.", 0, getMockEmailService().immediateReminderEmailsSent("bmcgough", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
123 }
124
125
126
127
128 @Test public void testDocumentTypeNotificationFromAddress() throws Exception {
129 String user1PrincipalId = getPrincipalIdForName("user1");
130
131
132 DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName("NotificationTest");
133 assertNull("Wrong notification from address, should be null.", documentType.getNotificationFromAddress());
134 assertNull("Wrong actual notification from address, should be null.", documentType.getActualNotificationFromAddress());
135
136
137 documentType = KEWServiceLocator.getDocumentTypeService().findByName("NotificationFromAddressParent");
138 assertEquals("Wrong notification from address.", "fakey@mcfakey.com", documentType.getNotificationFromAddress());
139
140
141 documentType = KEWServiceLocator.getDocumentTypeService().findByName("NotificationFromAddressChild");
142 assertEquals("Wrong notification from address.", "fakey@mcchild.com", documentType.getNotificationFromAddress());
143
144
145 documentType = KEWServiceLocator.getDocumentTypeService().findByName("NotificationFromAddressChildInherited");
146 assertEquals("Wrong notification from address.", "fakey@mcfakey.com", documentType.getNotificationFromAddress());
147
148
149 WorkflowDocument document = WorkflowDocumentFactory.createDocument(user1PrincipalId, "NotificationFromAddressChild");
150 document.adHocToPrincipal(ActionRequestType.APPROVE, "Initial", "", getPrincipalIdForName("ewestfal"), "", true);
151 document.route("");
152
153
154 assertEquals("ewestfal should have an email.", 1, getMockEmailService().immediateReminderEmailsSent("ewestfal", document.getDocumentId(), KEWConstants.ACTION_REQUEST_APPROVE_REQ));
155
156
157 }
158
159 private void assertDefaultNotificationPreferences(String principalId) throws Exception {
160 Preferences prefs = getPreferencesService().getPreferences(principalId);
161 assertEquals(KEWConstants.EMAIL_RMNDR_IMMEDIATE, prefs.getEmailNotification());
162 assertEquals(KEWConstants.PREFERENCES_YES_VAL, prefs.getNotifyPrimaryDelegation());
163 assertEquals(KEWConstants.PREFERENCES_NO_VAL, prefs.getNotifySecondaryDelegation());
164 }
165
166 private PreferencesService getPreferencesService() {
167 return KEWServiceLocator.getPreferencesService();
168 }
169
170 private MockEmailNotificationService getMockEmailService() {
171 return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
172 }
173
174 }