View Javadoc

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