View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.mail;
17  
18  import org.apache.log4j.Logger;
19  import org.junit.Test;
20  import org.kuali.rice.core.api.mail.EmailContent;
21  import org.kuali.rice.kew.actionitem.ActionItem;
22  import org.kuali.rice.kew.actionlist.ActionListFilter;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
25  import org.kuali.rice.kew.mail.service.EmailContentService;
26  import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
27  import org.kuali.rice.kew.rule.RuleTestUtils;
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  /**
37   * Unit test for the EmailContentService
38   * 
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   *
41   */
42  public class EmailContentServiceTest extends KEWTestCase {
43  	
44  	private static final Logger LOG = Logger.getLogger(EmailContentServiceTest.class);
45  
46  	/**
47  	 * @see org.kuali.rice.test.RiceTestCase#setUp()
48  	 */
49  	@Override
50  	public void setUp() throws Exception {
51  		super.setUp();
52  		loadXmlFile("EmailContentServiceTestConfig.xml");
53  	}
54  	
55  	/**
56  	 * This method specifically exercises a group responsibility to assure that the 
57  	 * {@link StyleableEmailContentServiceImpl} can handle that case.
58  	 * See KULRICE-3659.
59  	 */
60  	@Test
61  	public void testGroup() throws Exception {
62  		String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
63  		
64  		// this document type has a group responsibility
65  		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestWorkgroupDocType");
66  		doc.route("");
67  		
68  		ActionListFilter actionListFilter = new ActionListFilter();
69  		actionListFilter.setDocumentType(doc.getDocumentTypeName());
70  		Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionList(ewestfalPrincipalId, actionListFilter);
71  
72  		EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
73  		
74  		Person person = KimApiServiceLocator.getPersonService().getPerson(ewestfalPrincipalId);
75  		// this would blow up before the fix
76  		EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
77  	}
78  	
79  	/**
80  	 * This method tests that delegation doesn't break the email
81  	 * 
82  	 * @throws Exception
83  	 */
84  	@Test
85  	public void testUserDelegator() throws Exception {
86  		
87  		RuleTestUtils.createDelegationToUser("EmailTestUserDocType", "WorkflowDocumentTemplate", "user1");
88  		
89  		String user1PrincipalId = getPrincipalIdForName("user1");
90  		
91  		// this document type has a group responsibility
92  		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestUserDocType");
93  		doc.route("");
94  		
95  		ActionListFilter actionListFilter = new ActionListFilter();
96  		actionListFilter.setDocumentType(doc.getDocumentTypeName());
97  		Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, actionListFilter);
98  
99  		EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
100 		
101 		Person person = KimApiServiceLocator.getPersonService().getPerson(user1PrincipalId);
102 		EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
103 	}
104 	
105 	/**
106 	 * This method tests that 
107 	 * 
108 	 * @throws Exception
109 	 */
110 	@Test
111 	public void testGroupDelegator() throws Exception {
112 		
113 		RuleTestUtils.createDelegationToGroup("EmailTestWorkgroupDocType", "WorkflowDocumentTemplate", "EmailTestDelegateWorkgroup");
114 		
115 		String user1PrincipalId = getPrincipalIdForName("user1");
116 		
117 		// this document type has a group responsibility
118 		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestWorkgroupDocType");
119 		doc.route("");
120 		
121 		ActionListFilter actionListFilter = new ActionListFilter();
122 		actionListFilter.setDocumentType(doc.getDocumentTypeName());
123 		Collection<ActionItem> actionItems = KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, actionListFilter);
124 
125 		EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
126 		
127 		Person person = KimApiServiceLocator.getPersonService().getPerson(user1PrincipalId);
128 		EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
129 	}
130 }