View Javadoc

1   /*
2    * Copyright 2007-2008 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.kcb.service.impl;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.junit.Test;
22  import org.kuali.rice.kcb.bo.MessageDelivery;
23  import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
24  import org.kuali.rice.kcb.service.MessageDeliveryService;
25  import org.kuali.rice.kcb.test.KCBTestCase;
26  import org.kuali.rice.kcb.test.service.MockEmailService;
27  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
28  import org.kuali.rice.test.BaselineTestCase.Mode;
29  import org.kuali.rice.test.data.UnitTestData;
30  import org.kuali.rice.test.data.UnitTestSql;
31  
32  /**
33   * This class tests the implementation of the email service.
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @BaselineMode(Mode.ROLLBACK)
37  public class EmailServiceTest extends KCBTestCase {
38      public static final String VALID_EMAIL = "abcd@efghi.jkl";
39      public static final String VALID_FORMAT_VALUE = "text";
40  
41      @Test
42      @UnitTestData(sqlStatements = {
43          @UnitTestSql("insert into KREN_MSG_T (MSG_ID, DELIV_TYP, CRTE_DTTM, TTL, CHNl, PRODCR, CNTNT, CNTNT_TYP, URL, RECIP_ID, VER_NBR) values (1, 'fyi', {d '2009-01-01'}, 'a title', 'channel1', 'a producer', 'some content', 'a content type', 'url', 'user1', 0)"),
44          @UnitTestSql("insert into KREN_MSG_DELIV_T (MSG_DELIV_ID, MSG_ID, TYP_NM, SYS_ID, STAT_CD, LOCKD_DTTM, VER_NBR) values (1, 1, 'email', 'fake system id', 'fakestatus', NULL, 0)")
45      })
46      public void testSendNotificationEmail() throws Exception {
47          MessageDeliveryService mds = GlobalKCBServiceLocator.getInstance().getMessageDeliveryService();
48          MockEmailService emailService = (MockEmailService) GlobalKCBServiceLocator.getInstance().getEmailService();
49          emailService.getMailBoxes().clear();
50  
51          MessageDelivery nmd = mds.getMessageDelivery(Long.valueOf(1));
52          Long emailMessageId = emailService.sendEmail(nmd, VALID_EMAIL, VALID_FORMAT_VALUE);
53          
54          assertEquals(1, emailService.getMailBoxes().size());
55          List<Map<String, String>> mailbox = emailService.getMailBoxes().get(VALID_EMAIL);
56          assertNotNull(mailbox);
57          assertEquals(1, mailbox.size());
58      }
59  }