1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.mail;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.mail.EmailContent;
20 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kew.api.action.ActionItem;
24 import org.kuali.rice.kew.mail.service.impl.ActionListEmailServiceImpl;
25 import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.test.KEWTestCase;
28 import org.kuali.rice.kim.api.identity.Person;
29 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30
31 import java.util.ArrayList;
32 import java.util.Collection;
33
34 import static org.junit.Assert.*;
35
36
37
38
39
40 public class EmailMessageTest extends KEWTestCase {
41 private ActionListEmailServiceImpl actionListEmailService = new ActionListEmailServiceImpl();
42 private StyleableEmailContentServiceImpl styleableContentService = new StyleableEmailContentServiceImpl();
43
44 @Override
45 public void setUp() throws Exception {
46 super.setUp();
47 actionListEmailService.setDeploymentEnvironment("dev");
48
49 styleableContentService.setDeploymentEnvironment("dev");
50 styleableContentService.setStyleService(CoreServiceApiServiceLocator.getStyleService());
51 }
52
53 @Override
54 protected void loadTestData() throws Exception {
55 loadXmlFile("EmailMessageDocType.xml");
56 }
57
58 private int generateDocs(String[] docTypes, Person user) throws Exception {
59 String principalId = user.getPrincipalId();
60
61 for (String docType: docTypes) {
62 WorkflowDocument document = WorkflowDocumentFactory.createDocument(principalId, docType);
63 document.setTitle("a title");
64 document.route("");
65 document = WorkflowDocumentFactory.createDocument(principalId, docType);
66 document.setTitle("a title");
67 document.route("");
68 document = WorkflowDocumentFactory.createDocument(principalId, docType);
69 document.setTitle("a title");
70 document.route("");
71 document = WorkflowDocumentFactory.createDocument(principalId, docType);
72 document.setTitle("a title");
73 document.route("");
74 document = WorkflowDocumentFactory.createDocument(principalId, docType);
75 document.setTitle("a title");
76 document.route("");
77 }
78
79 return 5 * docTypes.length;
80 }
81
82
83
84
85
86 @Test
87 public void testGenerateRemindersCustomStyleSheet() throws Exception {
88 loadXmlFile("customEmailStyleData.xml");
89 assertNotNull(CoreServiceApiServiceLocator.getStyleService().getStyle("kew.email.style"));
90
91 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("arh14");
92 int count = generateDocs(new String[] { "PingDocument", "PingDocumentWithEmailAttrib" }, user);
93
94 Collection<ActionItem> actionItems = org.kuali.rice.kew.actionitem.ActionItem.to(new ArrayList<org.kuali.rice.kew.actionitem.ActionItem>(KEWServiceLocator.getActionListService().getActionList(user.getPrincipalId(), null)));
95 assertEquals("user should have " + count + " items in his action list.", count, actionItems.size());
96
97 EmailContent content = styleableContentService.generateImmediateReminder(user, actionItems.iterator().next(), KEWServiceLocator.getDocumentTypeService().findByName(actionItems.iterator().next().getDocName()));
98 assertTrue("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
99 assertTrue("Unexpected body", content.getBody().startsWith("CUSTOM:"));
100
101 content = styleableContentService.generateDailyReminder(user, actionItems);
102 assertTrue("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
103 assertTrue("Unexpected body", content.getBody().startsWith("CUSTOM:"));
104
105 content = styleableContentService.generateWeeklyReminder(user, actionItems);
106 assertTrue("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
107 assertTrue("Unexpected body", content.getBody().startsWith("CUSTOM:"));
108 }
109
110
111
112
113
114 @Test
115 public void testGenerateRemindersDocCustomStyleSheet() throws Exception {
116
117
118
119
120 loadXmlFile("customEmailStyleData.xml");
121 loadXmlFile("docCustomEmailStyleData.xml");
122 assertNotNull(CoreServiceApiServiceLocator.getStyleService().getStyle("kew.email.style"));
123 assertNotNull(CoreServiceApiServiceLocator.getStyleService().getStyle("doc.custom.email.style"));
124
125 Person user = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("arh14");
126 int count = generateDocs(new String[] { "PingDocumentCustomStyle" }, user);
127
128 Collection<ActionItem> actionItems = org.kuali.rice.kew.actionitem.ActionItem.to(new ArrayList<org.kuali.rice.kew.actionitem.ActionItem>(KEWServiceLocator.getActionListService().getActionList(user.getPrincipalId(), null)));
129 assertEquals("user should have " + count + " items in his action list.", count, actionItems.size());
130
131 EmailContent content = styleableContentService.generateImmediateReminder(user, actionItems.iterator().next(), KEWServiceLocator.getDocumentTypeService().findByName(actionItems.iterator().next().getDocName()));
132
133 assertFalse("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
134 assertFalse("Unexpected body", content.getBody().startsWith("CUSTOM:"));
135 assertTrue("Unexpected subject", content.getSubject().startsWith("DOCTYPE CUSTOM:"));
136 assertTrue("Unexpected body", content.getBody().startsWith("DOCTYPE CUSTOM:"));
137
138
139
140 content = styleableContentService.generateDailyReminder(user, actionItems);
141 assertTrue("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
142 assertTrue("Unexpected body", content.getBody().startsWith("CUSTOM:"));
143
144 content = styleableContentService.generateWeeklyReminder(user, actionItems);
145 assertTrue("Unexpected subject", content.getSubject().startsWith("CUSTOM:"));
146 assertTrue("Unexpected body", content.getBody().startsWith("CUSTOM:"));
147 }
148
149 }