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