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