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.kcb.service.impl;
017
018 import org.junit.Test;
019 import org.kuali.rice.core.api.exception.RiceRuntimeException;
020 import org.kuali.rice.kcb.bo.RecipientDelivererConfig;
021 import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
022 import org.kuali.rice.kcb.service.RecipientPreferenceService;
023 import org.kuali.rice.kcb.test.KCBTestCase;
024 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
025 import org.kuali.rice.test.BaselineTestCase.Mode;
026 import org.springframework.dao.DataIntegrityViolationException;
027
028 import java.util.Collection;
029
030 import static org.junit.Assert.assertEquals;
031
032 /**
033 * Tests persisting RecipientDelivererConfig
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
038 public class RecipientDelivererConfigTest extends KCBTestCase {
039 //private RecipientDelivererConfig CFG;
040
041 private RecipientPreferenceService prefsvc;
042
043 @Override
044 public void setUp() throws Exception {
045 super.setUp();
046
047 prefsvc = GlobalKCBServiceLocator.getInstance().getRecipientPreferenceService();
048
049 // CFG = new RecipientDelivererConfig();
050 // CFG.setRecipientId("user1");
051 // CFG.setDelivererName("mock");
052 // CFG.setChannel("channel1");
053
054 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
055 }
056
057 @Test
058 public void testCreate() throws Exception {
059 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel2" });
060
061 Collection<RecipientDelivererConfig> deliverers = prefsvc.getDeliverersForRecipient("user1");
062 assertEquals(2, deliverers.size());
063 }
064
065 @Test
066 public void testDelete() throws Exception {
067 prefsvc.removeRecipientDelivererConfigs("user1");
068
069 assertEquals(0, prefsvc.getDeliverersForRecipient("user1").size());
070 }
071
072 @Test(expected = RiceRuntimeException.class)
073 public void testDuplicateCreate() throws Exception {
074 // duplicate channel/deliverer entry
075 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
076 }
077
078 @Test(expected = DataIntegrityViolationException.class)
079 public void testInvalidUpdate() throws Exception {
080 // null channel
081 prefsvc.saveRecipientDelivererConfig("user1", null, new String[] { "channel2" });
082 }
083
084 @Test
085 public void testGetDeliverersForRecipientAndChannel() {
086 Collection<RecipientDelivererConfig> cfgs = prefsvc.getDeliverersForRecipientAndChannel("user1", "channel1");
087 assertEquals(1, cfgs.size());
088 assertEquals("mock", cfgs.iterator().next().getDelivererName());
089 }
090 }