001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.mail;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020
021 import org.apache.log4j.Logger;
022 import org.junit.Test;
023 import org.kuali.rice.core.api.mail.EmailContent;
024 import org.kuali.rice.kew.actionitem.ActionItem;
025 import org.kuali.rice.kew.actionitem.ActionItemActionListExtension;
026 import org.kuali.rice.kew.actionlist.ActionListFilter;
027 import org.kuali.rice.kew.api.WorkflowDocument;
028 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
029 import org.kuali.rice.kew.mail.service.EmailContentService;
030 import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
031 import org.kuali.rice.kew.rule.RuleTestUtils;
032 import org.kuali.rice.kew.service.KEWServiceLocator;
033 import org.kuali.rice.kew.test.KEWTestCase;
034 import org.kuali.rice.kim.api.identity.Person;
035 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
036
037 /**
038 * Unit test for the EmailContentService
039 *
040 * @author Kuali Rice Team (rice.collab@kuali.org)
041 *
042 */
043 public class EmailContentServiceTest extends KEWTestCase {
044
045 private static final Logger LOG = Logger.getLogger(EmailContentServiceTest.class);
046
047 /**
048 * @see org.kuali.rice.test.RiceTestCase#setUp()
049 */
050 @Override
051 public void setUp() throws Exception {
052 super.setUp();
053 loadXmlFile("EmailContentServiceTestConfig.xml");
054 }
055
056 /**
057 * This method specifically exercises a group responsibility to assure that the
058 * {@link StyleableEmailContentServiceImpl} can handle that case.
059 * See KULRICE-3659.
060 */
061 @Test
062 public void testGroup() throws Exception {
063 String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
064
065 // this document type has a group responsibility
066 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestWorkgroupDocType");
067 doc.route("");
068
069 ActionListFilter actionListFilter = new ActionListFilter();
070 actionListFilter.setDocumentType(doc.getDocumentTypeName());
071 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionList(ewestfalPrincipalId, actionListFilter);
072
073 EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
074
075 Person person = KimApiServiceLocator.getPersonService().getPerson(ewestfalPrincipalId);
076 // this would blow up before the fix
077 EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
078 }
079
080 /**
081 * This method tests that delegation doesn't break the email
082 *
083 * @throws Exception
084 */
085 @Test
086 public void testUserDelegator() throws Exception {
087
088 RuleTestUtils.createDelegationToUser("EmailTestUserDocType", "WorkflowDocumentTemplate", "user1");
089
090 String user1PrincipalId = getPrincipalIdForName("user1");
091
092 // this document type has a group responsibility
093 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestUserDocType");
094 doc.route("");
095
096 ActionListFilter actionListFilter = new ActionListFilter();
097 actionListFilter.setDocumentType(doc.getDocumentTypeName());
098 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, actionListFilter);
099
100 EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
101
102 Person person = KimApiServiceLocator.getPersonService().getPerson(user1PrincipalId);
103 EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
104 }
105
106 /**
107 * This method tests that
108 *
109 * @throws Exception
110 */
111 @Test
112 public void testGroupDelegator() throws Exception {
113
114 RuleTestUtils.createDelegationToGroup("EmailTestWorkgroupDocType", "WorkflowDocumentTemplate", "EmailTestDelegateWorkgroup");
115
116 String user1PrincipalId = getPrincipalIdForName("user1");
117
118 // this document type has a group responsibility
119 WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestWorkgroupDocType");
120 doc.route("");
121
122 ActionListFilter actionListFilter = new ActionListFilter();
123 actionListFilter.setDocumentType(doc.getDocumentTypeName());
124 Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, actionListFilter);
125
126 EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
127
128 Person person = KimApiServiceLocator.getPersonService().getPerson(user1PrincipalId);
129 EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
130 }
131 }