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.service.impl;
17  
18  import static org.junit.Assert.assertEquals;
19  import mocks.MockEmailNotificationService;
20  
21  import org.joda.time.DateTime;
22  import org.junit.After;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.kuali.rice.kew.api.KewApiServiceLocator;
26  import org.kuali.rice.kew.api.action.ActionItem;
27  import org.kuali.rice.kew.api.mail.ImmediateEmailReminderQueue;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.kuali.rice.kew.api.KewApiConstants;
31  
32  /**
33   * This test case verifies that the the ImmediateEmailReminderQueue can be retrieved from teh KewApiServiceLocator and that calling it
34   * will 
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class ImmediateEmailReminderQueueImplTest extends KEWTestCase {
39  
40      private ImmediateEmailReminderQueue immediateEmailReminderQueue;
41      
42      
43      @Before
44      public void setUp() throws Exception {
45          super.setUp();
46          
47          immediateEmailReminderQueue = KewApiServiceLocator.getImmediateEmailReminderQueue();
48      }
49      
50      @After
51      public void tearDown() throws Exception {
52          super.tearDown();
53      }
54      
55      @Test
56      public void test() {  
57          ActionItem actionItem = ActionItem.Builder.create("124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, "123", new DateTime(), "Test", "http://www.test.com", "Test", "125", "user1").build();
58          immediateEmailReminderQueue.sendReminder(actionItem, Boolean.FALSE);
59          
60          assertEquals("user1 should have 1 email", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
61          assertEquals("user2 should have no emails", 0, getMockEmailService().immediateReminderEmailsSent("user2", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
62  
63          getMockEmailService().resetReminderCounts();
64  
65          immediateEmailReminderQueue.sendReminder(actionItem, Boolean.TRUE);
66          assertEquals("user1 should have no emails", 0, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
67  
68          getMockEmailService().resetReminderCounts();
69  
70          // ensure that skip on approvals defaults to false
71          immediateEmailReminderQueue.sendReminder(actionItem, null);
72          assertEquals("user1 should have 1 email", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
73  
74          getMockEmailService().resetReminderCounts();
75  
76          // try sending an ack and make sure it doesn't get filtered out when skipOnApprovals is true
77          actionItem = ActionItem.Builder.create("124", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "123", new DateTime(), "Test", "http://www.test.com", "Test", "125", "user1").build();
78          immediateEmailReminderQueue.sendReminder(actionItem, Boolean.TRUE);
79          assertEquals("user1 should have 1 emails", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
80  
81  
82  
83      }
84  
85      
86      private MockEmailNotificationService getMockEmailService() {
87          return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
88      }
89  }