View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.junit.Test;
19  import org.kuali.rice.core.api.exception.RiceRuntimeException;
20  import org.kuali.rice.kcb.bo.RecipientDelivererConfig;
21  import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
22  import org.kuali.rice.kcb.service.RecipientPreferenceService;
23  import org.kuali.rice.kcb.test.KCBTestCase;
24  import org.kuali.rice.krad.service.KRADServiceLocator;
25  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26  import org.kuali.rice.test.BaselineTestCase.Mode;
27  import org.springframework.dao.DataAccessException;
28  
29  import java.util.Collection;
30  
31  import static org.junit.Assert.assertEquals;
32  
33  /**
34   * Tests persisting RecipientDelivererConfig 
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
39  public class RecipientDelivererConfigTest extends KCBTestCase {
40      //private RecipientDelivererConfig CFG;
41  
42      private RecipientPreferenceService prefsvc;
43  
44      @Override
45      public void setUp() throws Exception {
46          super.setUp();
47      
48          prefsvc = GlobalKCBServiceLocator.getInstance().getRecipientPreferenceService();
49  
50  //        CFG = new RecipientDelivererConfig();
51  //        CFG.setRecipientId("user1");
52  //        CFG.setDelivererName("mock");
53  //        CFG.setChannel("channel1");
54  
55          prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
56      }
57  
58      @Test
59      public void testCreate() throws Exception {
60          prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel2" });
61          
62          Collection<RecipientDelivererConfig> deliverers = prefsvc.getDeliverersForRecipient("user1");
63          assertEquals(2, deliverers.size());
64      }
65  
66      @Test
67      public void testDelete() throws Exception {
68          prefsvc.removeRecipientDelivererConfigs("user1");
69          
70          assertEquals(0, prefsvc.getDeliverersForRecipient("user1").size());
71      }
72  
73      @Test(expected = RiceRuntimeException.class)
74      public void testDuplicateCreate() throws Exception {
75          // duplicate channel/deliverer entry
76          prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
77      }
78  
79      @Test(expected = DataAccessException.class)
80      public void testInvalidUpdate() throws Exception {
81          // null channel
82          prefsvc.saveRecipientDelivererConfig("user1", null, new String[] { "channel2" });
83          KRADServiceLocator.getDataObjectService().flush(RecipientDelivererConfig.class);
84      }
85      
86      @Test
87      public void testGetDeliverersForRecipientAndChannel() {
88          Collection<RecipientDelivererConfig> cfgs = prefsvc.getDeliverersForRecipientAndChannel("user1", "channel1");
89          assertEquals(1, cfgs.size());
90          assertEquals("mock", cfgs.iterator().next().getDelivererName());
91      }
92  }