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