Source Code Cross Referenced for EmailMessageTestCase.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » mail » 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.mail 
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:        // Created on Jan 8, 2007
018:        package edu.iu.uis.eden.mail;
019:
020:        import java.util.Collection;
021:        import java.util.Date;
022:
023:        import org.junit.Test;
024:        import org.kuali.workflow.test.WorkflowTestCase;
025:
026:        import edu.iu.uis.eden.KEWServiceLocator;
027:        import edu.iu.uis.eden.actionitem.ActionItem;
028:        import edu.iu.uis.eden.clientapp.WorkflowDocument;
029:        import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
030:        import edu.iu.uis.eden.doctype.DocumentType;
031:        import edu.iu.uis.eden.exception.ResourceUnavailableException;
032:        import edu.iu.uis.eden.feedback.web.FeedbackForm;
033:        import edu.iu.uis.eden.plugin.attributes.CustomEmailAttribute;
034:        import edu.iu.uis.eden.user.AuthenticationUserId;
035:        import edu.iu.uis.eden.user.WorkflowUser;
036:
037:        /**
038:         * Tests email content generation
039:         * @author Aaron Hamid (arh14 at cornell dot edu)
040:         */
041:        public class EmailMessageTestCase extends WorkflowTestCase {
042:            private ActionListEmailServiceImpl actionListEmailService = new ActionListEmailServiceImpl();
043:            private HardCodedEmailContentServiceImpl hardCodedEmailContentService = new HardCodedEmailContentServiceImpl();
044:            private StyleableEmailContentServiceImpl styleableContentService = new StyleableEmailContentServiceImpl();
045:
046:            @Override
047:            public void setUp() throws Exception {
048:                super .setUp();
049:                actionListEmailService.setDeploymentEnvironment("unttst");
050:                hardCodedEmailContentService.setDeploymentEnvironment("unttst");
051:                styleableContentService.setDeploymentEnvironment("unttst");
052:                styleableContentService.setStyleService(KEWServiceLocator
053:                        .getStyleService());
054:            }
055:
056:            @Override
057:            protected void loadTestData() throws Exception {
058:                loadXmlFile("EmailMessageDocType.xml");
059:            }
060:
061:            private void testImmediateReminder(WorkflowUser user,
062:                    Collection<ActionItem> actionItems) throws Exception,
063:                    ResourceUnavailableException {
064:                for (ActionItem actionItem : actionItems) {
065:                    DocumentType docType = KEWServiceLocator
066:                            .getDocumentTypeService().findByName(
067:                                    actionItem.getDocName());
068:
069:                    String oldBody = actionListEmailService
070:                            .buildImmediateReminderBody(user, actionItem,
071:                                    docType);
072:                    CustomEmailAttribute cea = docType
073:                            .getCustomEmailAttribute();
074:                    // it's not buildImmediateReminderBody, but sendImmediateReminder in the default ActionListEmailServiceImpl
075:                    // that appends the custom content, so we need to do that here in order for the generated content to match
076:                    // that generated by HardCodedEmailContentServiceImpl
077:                    if (cea != null) {
078:                        oldBody += cea.getCustomEmailBody();
079:                    }
080:                    // have to use getEmailSubject("") to simulate generating an email subject with no custom email attribute
081:                    String customSubject = "";
082:                    if (cea != null) {
083:                        customSubject = cea.getCustomEmailSubject();
084:                    }
085:                    String oldSubject = actionListEmailService.getEmailSubject(
086:                            customSubject).getSubject();
087:
088:                    EmailContent hardCodedContent = hardCodedEmailContentService
089:                            .generateImmediateReminder(user, actionItem,
090:                                    docType);
091:                    EmailContent styledContent = styleableContentService
092:                            .generateImmediateReminder(user, actionItem,
093:                                    docType);
094:
095:                    assertEquals("Immediate reminder body is not identical",
096:                            oldBody, hardCodedContent.getBody());
097:                    assertEquals("Immediate reminder subject is not identical",
098:                            oldSubject, hardCodedContent.getSubject());
099:                    assertEquals("Immediate reminder body is not identical",
100:                            oldBody, styledContent.getBody());
101:                    assertEquals("Immediate reminder subject is not identical",
102:                            oldSubject, styledContent.getSubject());
103:
104:                    log.info("Immediate reminder content: " + styledContent);
105:                }
106:
107:            }
108:
109:            private void testDailyReminder(WorkflowUser user,
110:                    Collection<ActionItem> actionItems) {
111:                String oldBody = actionListEmailService.buildDailyReminderBody(
112:                        user, actionItems);
113:                String oldSubject = actionListEmailService.getEmailSubject()
114:                        .getSubject();
115:                EmailContent hardCodedContent = hardCodedEmailContentService
116:                        .generateDailyReminder(user, actionItems);
117:                EmailContent styledContent = styleableContentService
118:                        .generateDailyReminder(user, actionItems);
119:
120:                assertEquals("Daily reminder body is not identical", oldBody,
121:                        hardCodedContent.getBody());
122:                // daily reminder does not use custom email subject
123:                assertEquals("Daily reminder subject is not identical",
124:                        oldSubject, hardCodedContent.getSubject());
125:                assertEquals("Daily reminder body is not identical", oldBody,
126:                        styledContent.getBody());
127:                // daily reminder does not use custom email subject
128:                assertEquals("Daily reminder subject is not identical",
129:                        oldSubject, styledContent.getSubject());
130:
131:                log.info("Daily reminder content: " + styledContent);
132:
133:            }
134:
135:            private void testWeeklyReminder(WorkflowUser user,
136:                    Collection<ActionItem> actionItems) {
137:                String oldBody = actionListEmailService
138:                        .buildWeeklyReminderBody(user, actionItems);
139:                String oldSubject = actionListEmailService.getEmailSubject()
140:                        .getSubject();
141:
142:                EmailContent hardCodedContent = hardCodedEmailContentService
143:                        .generateWeeklyReminder(user, actionItems);
144:                EmailContent styledContent = styleableContentService
145:                        .generateWeeklyReminder(user, actionItems);
146:
147:                assertEquals("Weekly reminder body is not identical", oldBody,
148:                        hardCodedContent.getBody());
149:                // daily reminder does not use custom email subject
150:                assertEquals("Weekly reminder subject is not identical",
151:                        oldSubject, hardCodedContent.getSubject());
152:                assertEquals("Weekly reminder body is not identical", oldBody,
153:                        styledContent.getBody());
154:                // daily reminder does not use custom email subject
155:                assertEquals("Weekly reminder subject is not identical",
156:                        oldSubject, styledContent.getSubject());
157:
158:                log.info("Weekly reminder content: " + styledContent);
159:            }
160:
161:            private void testEmailContentGeneration(WorkflowUser user,
162:                    int numItems) throws Exception {
163:                Collection<ActionItem> actionItems = KEWServiceLocator
164:                        .getActionListService().getActionList(user, null);
165:                assertEquals("user should have " + numItems
166:                        + " items in his action list.", numItems, actionItems
167:                        .size());
168:
169:                testImmediateReminder(user, actionItems);
170:
171:                testDailyReminder(user, actionItems);
172:
173:                testWeeklyReminder(user, actionItems);
174:            }
175:
176:            private int generateDocs(String[] docTypes, WorkflowUser user)
177:                    throws Exception {
178:                NetworkIdVO nid = new NetworkIdVO(user
179:                        .getAuthenticationUserId().getId());
180:
181:                for (String docType : docTypes) {
182:                    WorkflowDocument document = new WorkflowDocument(nid,
183:                            docType);
184:                    document.setTitle("a title");
185:                    document.routeDocument("");
186:                    document = new WorkflowDocument(nid, docType);
187:                    document.setTitle("a title");
188:                    document.routeDocument("");
189:                    document = new WorkflowDocument(nid, docType);
190:                    document.setTitle("a title");
191:                    document.routeDocument("");
192:                    document = new WorkflowDocument(nid, docType);
193:                    document.setTitle("a title");
194:                    document.routeDocument("");
195:                    document = new WorkflowDocument(nid, docType);
196:                    document.setTitle("a title");
197:                    document.routeDocument("");
198:                }
199:
200:                return 5 * docTypes.length;
201:            }
202:
203:            /**
204:             * tests that the standard actionlistemailserviceimpl and refactored hardcodedemailcontentservice
205:             * produce the same email messages
206:             * @throws Exception
207:             */
208:            @Test
209:            public void testGenerateReminders() throws Exception {
210:                WorkflowUser wfuser = KEWServiceLocator.getUserService()
211:                        .getWorkflowUser(new AuthenticationUserId("arh14"));
212:                int count = generateDocs(new String[] { "PingDocument",
213:                        "PingDocumentWithEmailAttrib" }, wfuser);
214:                testEmailContentGeneration(wfuser, count);
215:            }
216:
217:            /**
218:             * tests custom stylesheet
219:             * @throws Exception
220:             */
221:            @Test
222:            public void testGenerateRemindersCustomStyleSheet()
223:                    throws Exception {
224:                loadXmlFile("customEmailStyleData.xml");
225:                assertNotNull(KEWServiceLocator.getStyleService().getStyle(
226:                        "kew.email.style"));
227:                WorkflowUser user = KEWServiceLocator.getUserService()
228:                        .getWorkflowUser(new AuthenticationUserId("arh14"));
229:                int count = generateDocs(new String[] { "PingDocument",
230:                        "PingDocumentWithEmailAttrib" }, user);
231:
232:                Collection<ActionItem> actionItems = KEWServiceLocator
233:                        .getActionListService().getActionList(user, null);
234:                assertEquals("user should have " + count
235:                        + " items in his action list.", count, actionItems
236:                        .size());
237:
238:                EmailContent content = styleableContentService
239:                        .generateImmediateReminder(user, actionItems.iterator()
240:                                .next(), KEWServiceLocator
241:                                .getDocumentTypeService().findByName(
242:                                        actionItems.iterator().next()
243:                                                .getDocName()));
244:                assertTrue("Unexpected subject", content.getSubject()
245:                        .startsWith("CUSTOM:"));
246:                assertTrue("Unexpected body", content.getBody().startsWith(
247:                        "CUSTOM:"));
248:
249:                content = styleableContentService.generateDailyReminder(user,
250:                        actionItems);
251:                assertTrue("Unexpected subject", content.getSubject()
252:                        .startsWith("CUSTOM:"));
253:                assertTrue("Unexpected body", content.getBody().startsWith(
254:                        "CUSTOM:"));
255:
256:                content = styleableContentService.generateWeeklyReminder(user,
257:                        actionItems);
258:                assertTrue("Unexpected subject", content.getSubject()
259:                        .startsWith("CUSTOM:"));
260:                assertTrue("Unexpected body", content.getBody().startsWith(
261:                        "CUSTOM:"));
262:            }
263:
264:            /**
265:             * tests custom stylesheet
266:             * @throws Exception
267:             */
268:            @Test
269:            public void testGenerateRemindersDocCustomStyleSheet()
270:                    throws Exception {
271:                // we need to make sure that the immediate email message is customized on a per-doc basis
272:                // so we need to easily distinguish from the global style and the custom style
273:                // an easy way to do that is use two styles that have introduced obvious and blatent
274:                // distinguishing marker...so we just reuse the global custom email style here
275:                loadXmlFile("customEmailStyleData.xml");
276:                loadXmlFile("docCustomEmailStyleData.xml");
277:                assertNotNull(KEWServiceLocator.getStyleService().getStyle(
278:                        "kew.email.style"));
279:                assertNotNull(KEWServiceLocator.getStyleService().getStyle(
280:                        "doc.custom.email.style"));
281:
282:                WorkflowUser user = KEWServiceLocator.getUserService()
283:                        .getWorkflowUser(new AuthenticationUserId("arh14"));
284:                int count = generateDocs(
285:                        new String[] { "PingDocumentCustomStyle" }, user);
286:
287:                Collection<ActionItem> actionItems = KEWServiceLocator
288:                        .getActionListService().getActionList(user, null);
289:                assertEquals("user should have " + count
290:                        + " items in his action list.", count, actionItems
291:                        .size());
292:
293:                EmailContent content = styleableContentService
294:                        .generateImmediateReminder(user, actionItems.iterator()
295:                                .next(), KEWServiceLocator
296:                                .getDocumentTypeService().findByName(
297:                                        actionItems.iterator().next()
298:                                                .getDocName()));
299:                // immediate email reminder should have used the doc type email style and NOT the global style
300:                assertFalse("Unexpected subject", content.getSubject()
301:                        .startsWith("CUSTOM:"));
302:                assertFalse("Unexpected body", content.getBody().startsWith(
303:                        "CUSTOM:"));
304:                assertTrue("Unexpected subject", content.getSubject()
305:                        .startsWith("DOCTYPE CUSTOM:"));
306:                assertTrue("Unexpected body", content.getBody().startsWith(
307:                        "DOCTYPE CUSTOM:"));
308:
309:                // daily and weekly are unchanged since they are not document type specific
310:                content = styleableContentService.generateDailyReminder(user,
311:                        actionItems);
312:                assertTrue("Unexpected subject", content.getSubject()
313:                        .startsWith("CUSTOM:"));
314:                assertTrue("Unexpected body", content.getBody().startsWith(
315:                        "CUSTOM:"));
316:
317:                content = styleableContentService.generateWeeklyReminder(user,
318:                        actionItems);
319:                assertTrue("Unexpected subject", content.getSubject()
320:                        .startsWith("CUSTOM:"));
321:                assertTrue("Unexpected body", content.getBody().startsWith(
322:                        "CUSTOM:"));
323:            }
324:
325:            /**
326:             * tests loading a custom stylesheet that has entities that causes XPath to get confused down the ingestion pipeline...
327:             * @throws Exception
328:             */
329:            @Test
330:            public void testBadCustomStyleSheet() throws Exception {
331:                loadXmlFile("badCustomEmailStyleData.xml");
332:                // this doesn't get loaded
333:                assertNull(KEWServiceLocator.getStyleService().getStyle(
334:                        "bad.kew.email.style"));
335:            }
336:
337:            /**
338:             * tests feedback email content generation
339:             * @throws Exception
340:             */
341:            @Test
342:            public void testFeedback() throws Exception {
343:                HardCodedEmailContentServiceImpl hcContentService = new HardCodedEmailContentServiceImpl();
344:                hcContentService.setDeploymentEnvironment("unttst");
345:
346:                StyleableEmailContentServiceImpl styleContentService = new StyleableEmailContentServiceImpl();
347:                styleContentService.setDeploymentEnvironment("unttst");
348:                styleContentService.setStyleService(KEWServiceLocator
349:                        .getStyleService());
350:
351:                FeedbackForm form = new FeedbackForm();
352:                form.setComments("this is \r\n a few lines of \r\n comments");
353:                form.setDocumentType("PingDocument");
354:                form.setEdenCategory("an eden category");
355:                form.setException(new Exception().toString());
356:                form.setFirstName("first name");
357:                form.setLastName("last name");
358:                form.setNetworkId("network id");
359:                form.setPageUrl("page url");
360:                form.setPhone("555-555-5555");
361:                form.setTimeDate(new Date().toString());
362:                form.setUserEmail("user@unittest");
363:                form.setUserName("user name");
364:                // don't set route header id at this point
365:
366:                EmailContent hcContent = hcContentService
367:                        .generateFeedback(form);
368:                EmailContent sContent = styleContentService
369:                        .generateFeedback(form);
370:                assertEquals(hcContent.getSubject().replace("\\s+", " "),
371:                        sContent.getSubject().replace("\\s+", " "));
372:                assertEquals(hcContent.getBody().replace("\\s+", " "), sContent
373:                        .getBody().replace("\\s+", " "));
374:                assertEquals(hcContent.isHtml(), sContent.isHtml());
375:
376:                // now test with the route header id set
377:                form.setRouteHeaderId("12345");
378:
379:                hcContent = hcContentService.generateFeedback(form);
380:                sContent = styleContentService.generateFeedback(form);
381:                assertEquals(hcContent.getSubject().replace("\\s+", " "),
382:                        sContent.getSubject().replace("\\s+", " "));
383:                assertEquals(hcContent.getBody().replace("\\s+", " "), sContent
384:                        .getBody().replace("\\s+", " "));
385:                assertEquals(hcContent.isHtml(), sContent.isHtml());
386:            }
387:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.