Source Code Cross Referenced for NotificationServiceTest.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » notification » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.notification 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package edu.iu.uis.eden.notification;
018:
019:        import mocks.MockEmailNotificationService;
020:
021:        import org.junit.Test;
022:        import org.kuali.workflow.test.WorkflowTestCase;
023:
024:        import edu.iu.uis.eden.EdenConstants;
025:        import edu.iu.uis.eden.KEWServiceLocator;
026:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
027:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
028:        import edu.iu.uis.eden.doctype.DocumentType;
029:        import edu.iu.uis.eden.preferences.Preferences;
030:        import edu.iu.uis.eden.preferences.PreferencesService;
031:        import edu.iu.uis.eden.user.AuthenticationUserId;
032:        import edu.iu.uis.eden.user.WorkflowUser;
033:
034:        public class NotificationServiceTest extends WorkflowTestCase {
035:
036:            protected void loadTestData() throws Exception {
037:                loadXmlFile("NotificationConfig.xml");
038:            }
039:
040:            /**
041:             * Tests that when a user is routed to twice at the same time that only email is sent to them.
042:             */
043:            @Test
044:            public void testNoDuplicateEmails() throws Exception {
045:                WorkflowDocument document = new WorkflowDocument(
046:                        new NetworkIdVO("user1"), "NotificationTest");
047:                document.routeDocument("");
048:
049:                assertEquals("rkirkend should only have one email.", 1,
050:                        getMockEmailService().emailsSent("rkirkend",
051:                                document.getRouteHeaderId(),
052:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
053:                assertEquals("ewestfal should only have one email.", 1,
054:                        getMockEmailService().emailsSent("ewestfal",
055:                                document.getRouteHeaderId(),
056:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
057:                assertEquals("jhopf should only have one email.", 1,
058:                        getMockEmailService().emailsSent("jhopf",
059:                                document.getRouteHeaderId(),
060:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
061:                // bmcgough is doing primary delegation so he should not recieve an email notification
062:                assertEquals("bmcgough should have no emails.", 0,
063:                        getMockEmailService().emailsSent("bmcgough",
064:                                document.getRouteHeaderId(),
065:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
066:                // jitrue should have no email because he is a secondary delegate and his default preferences should be set up to not send an email
067:                assertEquals("jitrue should have no emails.", 0,
068:                        getMockEmailService().emailsSent("jitrue",
069:                                document.getRouteHeaderId(),
070:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
071:                // user1 took action so they should _not_ be sent any emails
072:                assertEquals("user1 should have no emails.", 0,
073:                        getMockEmailService().emailsSent("user1",
074:                                document.getRouteHeaderId(),
075:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
076:
077:            }
078:
079:            /**
080:             * Tests that the notification preferences for emails work properly.  There are four different preferences:
081:             * 
082:             * 1) Email notification type (none, immediate, daily, weekly) - defaults to immediate
083:             * 2) Send primary delegation notifications - defaults to true
084:             * 3) Send secondary delegation notifications - defaults to false
085:             */
086:            @Test
087:            public void testEmailPreferences() throws Exception {
088:                WorkflowUser ewestfal = KEWServiceLocator.getUserService()
089:                        .getWorkflowUser(new AuthenticationUserId("ewestfal"));
090:                WorkflowUser jitrue = KEWServiceLocator.getUserService()
091:                        .getWorkflowUser(new AuthenticationUserId("jitrue"));
092:                WorkflowUser rkirkend = KEWServiceLocator.getUserService()
093:                        .getWorkflowUser(new AuthenticationUserId("rkirkend"));
094:                WorkflowUser jhopf = KEWServiceLocator.getUserService()
095:                        .getWorkflowUser(new AuthenticationUserId("jhopf"));
096:                WorkflowUser bmcgough = KEWServiceLocator.getUserService()
097:                        .getWorkflowUser(new AuthenticationUserId("bmcgough"));
098:
099:                // test that the users with secondary delegations have default preferences
100:                assertDefaultNotificationPreferences(ewestfal);
101:                assertDefaultNotificationPreferences(jitrue);
102:                assertDefaultNotificationPreferences(rkirkend);
103:                assertDefaultNotificationPreferences(jhopf);
104:                assertDefaultNotificationPreferences(bmcgough);
105:                // the rest of the default setup is actually tested by testNoDuplicateEmails
106:
107:                // now turn on secondary notification for ewestfal and jitrue, turn off email notification for ewestfal
108:                Preferences prefs = getPreferencesService().getPreferences(
109:                        ewestfal);
110:                prefs
111:                        .setNotifySecondaryDelegation(EdenConstants.PREFERENCES_YES_VAL);
112:                prefs.setEmailNotification(EdenConstants.EMAIL_RMNDR_NO_VAL);
113:                getPreferencesService().savePreferences(ewestfal, prefs);
114:                prefs = getPreferencesService().getPreferences(jitrue);
115:                prefs
116:                        .setNotifySecondaryDelegation(EdenConstants.PREFERENCES_YES_VAL);
117:                getPreferencesService().savePreferences(jitrue, prefs);
118:
119:                // also turn off primary delegation notification for rkirkend
120:                prefs = getPreferencesService().getPreferences(rkirkend);
121:                prefs
122:                        .setNotifyPrimaryDelegation(EdenConstants.PREFERENCES_NO_VAL);
123:                getPreferencesService().savePreferences(rkirkend, prefs);
124:
125:                // also turn notification to daily for bmcgough
126:                prefs = getPreferencesService().getPreferences(bmcgough);
127:                prefs.setEmailNotification(EdenConstants.EMAIL_RMNDR_DAY_VAL);
128:                getPreferencesService().savePreferences(bmcgough, prefs);
129:
130:                // also turn off notification for jhopf
131:                prefs = getPreferencesService().getPreferences(jhopf);
132:                prefs.setEmailNotification(EdenConstants.EMAIL_RMNDR_NO_VAL);
133:                getPreferencesService().savePreferences(jhopf, prefs);
134:
135:                // route the document
136:                WorkflowDocument document = new WorkflowDocument(
137:                        new NetworkIdVO("user1"), "NotificationTest");
138:                document.routeDocument("");
139:
140:                // both ewestfal and jitrue should have one email
141:                assertEquals("ewestfal should have no emails.", 0,
142:                        getMockEmailService().emailsSent("ewestfal",
143:                                document.getRouteHeaderId(),
144:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
145:                assertEquals("jitrue should have one email.", 1,
146:                        getMockEmailService().emailsSent("jitrue",
147:                                document.getRouteHeaderId(),
148:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
149:
150:                // rkirkend (the primary delegate) should now have no emails
151:                assertEquals("rkirkend should have no emails.", 0,
152:                        getMockEmailService().emailsSent("rkirkend",
153:                                document.getRouteHeaderId(),
154:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
155:
156:                // jhopf should now have no emails since his top-level requests are no longer notified
157:                assertEquals("jhopf should have no emails.", 0,
158:                        getMockEmailService().emailsSent("jhopf",
159:                                document.getRouteHeaderId(),
160:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
161:
162:                // bmcgough should now have no emails since his notification preference is DAILY
163:                assertEquals("bmcgough should have no emails.", 0,
164:                        getMockEmailService().emailsSent("bmcgough",
165:                                document.getRouteHeaderId(),
166:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
167:            }
168:
169:            /**
170:             * Tests that the fromNotificationAddress on the document type works properly.  Used to test implementation of KULWF-628.
171:             */
172:            @Test
173:            public void testDocumentTypeNotificationFromAddress()
174:                    throws Exception {
175:                // first test that the notification from addresses are configured correctly
176:                DocumentType documentType = KEWServiceLocator
177:                        .getDocumentTypeService()
178:                        .findByName("NotificationTest");
179:                assertNull("Wrong notification from address, should be null.",
180:                        documentType.getNotificationFromAddress());
181:
182:                // test the parent document type
183:                documentType = KEWServiceLocator.getDocumentTypeService()
184:                        .findByName("NotificationFromAddressParent");
185:                assertEquals("Wrong notification from address.",
186:                        "fakey@mcfakey.com", documentType
187:                                .getNotificationFromAddress());
188:
189:                // test a child document type which overrides the parent's address
190:                documentType = KEWServiceLocator.getDocumentTypeService()
191:                        .findByName("NotificationFromAddressChild");
192:                assertEquals("Wrong notification from address.",
193:                        "fakey@mcchild.com", documentType
194:                                .getNotificationFromAddress());
195:
196:                // test a child document type which doesn't override the parent's address
197:                documentType = KEWServiceLocator.getDocumentTypeService()
198:                        .findByName("NotificationFromAddressChildInherited");
199:                assertEquals("Wrong notification from address.",
200:                        "fakey@mcfakey.com", documentType
201:                                .getNotificationFromAddress());
202:
203:                // Do an app specific route to a document which should send an email to fakey@mcchild.com
204:                WorkflowDocument document = new WorkflowDocument(
205:                        new NetworkIdVO("user1"),
206:                        "NotificationFromAddressChild");
207:                document.appSpecificRouteDocumentToUser(
208:                        EdenConstants.ACTION_REQUEST_APPROVE_REQ, "Initial",
209:                        "", new NetworkIdVO("ewestfal"), "", true);
210:                document.routeDocument("");
211:
212:                // verify that ewestfal was sent an email
213:                assertEquals("ewestfal should have an email.", 1,
214:                        getMockEmailService().emailsSent("ewestfal",
215:                                document.getRouteHeaderId(),
216:                                EdenConstants.ACTION_REQUEST_APPROVE_REQ));
217:
218:                // we currently have no way from this test to determine the email address used for notification
219:            }
220:
221:            private void assertDefaultNotificationPreferences(WorkflowUser user)
222:                    throws Exception {
223:                Preferences prefs = getPreferencesService()
224:                        .getPreferences(user);
225:                assertEquals(EdenConstants.EMAIL_RMNDR_IMMEDIATE, prefs
226:                        .getEmailNotification());
227:                assertEquals(EdenConstants.PREFERENCES_YES_VAL, prefs
228:                        .getNotifyPrimaryDelegation());
229:                assertEquals(EdenConstants.PREFERENCES_NO_VAL, prefs
230:                        .getNotifySecondaryDelegation());
231:            }
232:
233:            private PreferencesService getPreferencesService() {
234:                return KEWServiceLocator.getPreferencesService();
235:            }
236:
237:            private MockEmailNotificationService getMockEmailService() {
238:                return (MockEmailNotificationService) KEWServiceLocator
239:                        .getActionListEmailService();
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.