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