001 /**
002 * Copyright 2005-2011 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.service.impl;
017
018 import static org.junit.Assert.assertEquals;
019 import mocks.MockEmailNotificationService;
020
021 import org.joda.time.DateTime;
022 import org.junit.After;
023 import org.junit.Before;
024 import org.junit.Test;
025 import org.kuali.rice.kew.api.KewApiServiceLocator;
026 import org.kuali.rice.kew.api.action.ActionItem;
027 import org.kuali.rice.kew.api.mail.ImmediateEmailReminderQueue;
028 import org.kuali.rice.kew.service.KEWServiceLocator;
029 import org.kuali.rice.kew.test.KEWTestCase;
030 import org.kuali.rice.kew.api.KewApiConstants;
031
032 /**
033 * This test case verifies that the the ImmediateEmailReminderQueue can be retrieved from teh KewApiServiceLocator and that calling it
034 * will
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 */
038 public class ImmediateEmailReminderQueueImplTest extends KEWTestCase {
039
040 private ImmediateEmailReminderQueue immediateEmailReminderQueue;
041
042
043 @Before
044 public void setUp() throws Exception {
045 super.setUp();
046
047 immediateEmailReminderQueue = KewApiServiceLocator.getImmediateEmailReminderQueue();
048 }
049
050 @After
051 public void tearDown() throws Exception {
052 super.tearDown();
053 }
054
055 @Test
056 public void test() {
057 ActionItem actionItem = ActionItem.Builder.create("124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ, "123", new DateTime(), "Test", "http://www.test.com", "Test", "125", "user1").build();
058 immediateEmailReminderQueue.sendReminder(actionItem, Boolean.FALSE);
059
060 assertEquals("user1 should have 1 email", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
061 assertEquals("user2 should have no emails", 0, getMockEmailService().immediateReminderEmailsSent("user2", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
062
063 getMockEmailService().resetReminderCounts();
064
065 immediateEmailReminderQueue.sendReminder(actionItem, Boolean.TRUE);
066 assertEquals("user1 should have no emails", 0, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
067
068 getMockEmailService().resetReminderCounts();
069
070 // ensure that skip on approvals defaults to false
071 immediateEmailReminderQueue.sendReminder(actionItem, null);
072 assertEquals("user1 should have 1 email", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_APPROVE_REQ));
073
074 getMockEmailService().resetReminderCounts();
075
076 // try sending an ack and make sure it doesn't get filtered out when skipOnApprovals is true
077 actionItem = ActionItem.Builder.create("124", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, "123", new DateTime(), "Test", "http://www.test.com", "Test", "125", "user1").build();
078 immediateEmailReminderQueue.sendReminder(actionItem, Boolean.TRUE);
079 assertEquals("user1 should have 1 emails", 1, getMockEmailService().immediateReminderEmailsSent("user1", "124", KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ));
080
081
082
083 }
084
085
086 private MockEmailNotificationService getMockEmailService() {
087 return (MockEmailNotificationService)KEWServiceLocator.getActionListEmailService();
088 }
089 }