View Javadoc

1   /**
2    * Copyright 2005-2013 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 java.util.ArrayList;
19  import java.util.Collection;
20  
21  import org.apache.log4j.Logger;
22  import org.junit.Test;
23  import org.kuali.rice.core.api.mail.EmailContent;
24  import org.kuali.rice.kew.actionitem.ActionItem;
25  import org.kuali.rice.kew.actionitem.ActionItemActionListExtension;
26  import org.kuali.rice.kew.actionlist.ActionListFilter;
27  import org.kuali.rice.kew.api.WorkflowDocument;
28  import org.kuali.rice.kew.api.WorkflowDocumentFactory;
29  import org.kuali.rice.kew.mail.service.EmailContentService;
30  import org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl;
31  import org.kuali.rice.kew.rule.RuleTestUtils;
32  import org.kuali.rice.kew.service.KEWServiceLocator;
33  import org.kuali.rice.kew.test.KEWTestCase;
34  import org.kuali.rice.kim.api.identity.Person;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  
37  /**
38   * Unit test for the EmailContentService
39   * 
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   *
42   */
43  public class EmailContentServiceTest extends KEWTestCase {
44  	
45  	private static final Logger LOG = Logger.getLogger(EmailContentServiceTest.class);
46  
47  	/**
48  	 * @see org.kuali.rice.test.RiceTestCase#setUp()
49  	 */
50  	@Override
51  	public void setUp() throws Exception {
52  		super.setUp();
53  		loadXmlFile("EmailContentServiceTestConfig.xml");
54  	}
55  	
56  	/**
57  	 * This method specifically exercises a group responsibility to assure that the 
58  	 * {@link StyleableEmailContentServiceImpl} can handle that case.
59  	 * See KULRICE-3659.
60  	 */
61  	@Test
62  	public void testGroup() throws Exception {
63  		String ewestfalPrincipalId = getPrincipalIdForName("ewestfal");
64  		
65  		// this document type has a group responsibility
66  		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestWorkgroupDocType");
67  		doc.route("");
68  		
69  		ActionListFilter actionListFilter = new ActionListFilter();
70  		actionListFilter.setDocumentType(doc.getDocumentTypeName());
71  		Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionList(ewestfalPrincipalId, actionListFilter);
72  
73  		EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
74  		
75  		Person person = KimApiServiceLocator.getPersonService().getPerson(ewestfalPrincipalId);
76  		// this would blow up before the fix
77  		EmailContent emailContent = emailContentService.generateDailyReminder(person, ActionItem.to(new ArrayList<ActionItem>(actionItems)));
78  	}
79  	
80  	/**
81  	 * This method tests that delegation doesn't break the email
82  	 * 
83  	 * @throws Exception
84  	 */
85  	@Test
86  	public void testUserDelegator() throws Exception {
87  		
88  		RuleTestUtils.createDelegationToUser("EmailTestUserDocType", "WorkflowDocumentTemplate", "user1");
89  		
90  		String user1PrincipalId = getPrincipalIdForName("user1");
91  		
92  		// this document type has a group responsibility
93  		WorkflowDocument doc = WorkflowDocumentFactory.createDocument(getPrincipalIdForName("rkirkend"), "EmailTestUserDocType");
94  		doc.route("");
95  		
96  		ActionListFilter actionListFilter = new ActionListFilter();
97  		actionListFilter.setDocumentType(doc.getDocumentTypeName());
98  		Collection<ActionItemActionListExtension> actionItems = KEWServiceLocator.getActionListService().getActionList(user1PrincipalId, actionListFilter);
99  
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 }