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.ken.services.impl;
017
018 import org.junit.Test;
019 import org.kuali.rice.ken.bo.NotificationChannelBo;
020 import org.kuali.rice.ken.bo.UserChannelSubscriptionBo;
021 import org.kuali.rice.ken.service.UserPreferenceService;
022 import org.kuali.rice.ken.test.KENTestCase;
023 import org.kuali.rice.ken.test.TestConstants;
024 import org.kuali.rice.ken.util.NotificationConstants;
025 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
026 import org.kuali.rice.test.BaselineTestCase.Mode;
027
028 import java.util.Collection;
029 import java.util.HashMap;
030
031 import static org.junit.Assert.*;
032
033 /**
034 * This class tests the user preferences service impl.
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037 @BaselineMode(Mode.CLEAR_DB)
038 public class UserPreferenceServiceImplTest extends KENTestCase {
039 public static final String VALID_USER_ID = TestConstants.TEST_USER_ONE;
040 public static final String VALID_CHANNEL_ID = TestConstants.VALID_CHANNEL_ONE_ID.toString();
041 public static final Long VALID_CHANNEL_ID_LONG = TestConstants.VALID_CHANNEL_ONE_ID;
042 //public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME;
043 public static final String[] CHANNEL_SELECTED = { TestConstants.VALID_CHANNEL_ONE_ID.toString() };
044 //public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY;
045 public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE;
046
047 public UserPreferenceServiceImplTest() {
048 }
049
050 @Test
051 public void testSubscribeToChannel() {
052 UserPreferenceService impl = services.getUserPreferenceService();
053 HashMap primaryKeys = new HashMap();
054 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
055 NotificationChannelBo
056 channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
057
058 UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
059 newSub.setUserId(VALID_USER_ID);
060 newSub.setChannel(channel);
061 impl.subscribeToChannel(newSub);
062 UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
063 assertNotNull(sub);
064 assertEquals(VALID_USER_ID, sub.getUserId());
065 assertEquals(VALID_CHANNEL_ID_LONG, sub.getChannel().getId());
066
067 }
068 @Test
069 public void testGetCurrentSubscriptions() {
070 UserPreferenceService impl = services.getUserPreferenceService();
071 HashMap primaryKeys = new HashMap();
072 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
073 NotificationChannelBo
074 channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
075
076 UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
077 newSub.setUserId(VALID_USER_ID);
078 newSub.setChannel(channel);
079 impl.subscribeToChannel(newSub);
080 Collection<UserChannelSubscriptionBo> subs = impl.getCurrentSubscriptions(VALID_USER_ID);
081 assertEquals(1, subs.size());
082 }
083
084 @Test
085 public void testUnsubscribeFromChannel() {
086 UserPreferenceService impl = services.getUserPreferenceService();
087 HashMap primaryKeys = new HashMap();
088 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
089 NotificationChannelBo
090 channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
091
092
093 UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
094 newSub.setUserId(VALID_USER_ID);
095 newSub.setChannel(channel);
096 impl.subscribeToChannel(newSub);
097
098 UserChannelSubscriptionBo userChannelSubscription = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
099 impl.unsubscribeFromChannel(userChannelSubscription);
100
101 UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
102 assertNull(sub);
103
104 }
105
106 }