View Javadoc

1   /**
2    * Copyright 2005-2011 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.ken.services.impl;
17  
18  import org.junit.Test;
19  import org.kuali.rice.ken.bo.NotificationChannelBo;
20  import org.kuali.rice.ken.bo.UserChannelSubscriptionBo;
21  import org.kuali.rice.ken.service.UserPreferenceService;
22  import org.kuali.rice.ken.test.KENTestCase;
23  import org.kuali.rice.ken.test.TestConstants;
24  import org.kuali.rice.ken.util.NotificationConstants;
25  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26  import org.kuali.rice.test.BaselineTestCase.Mode;
27  
28  import java.util.Collection;
29  import java.util.HashMap;
30  
31  import static org.junit.Assert.*;
32  
33  /**
34   * This class tests the user preferences service impl.
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @BaselineMode(Mode.CLEAR_DB)
38  public class UserPreferenceServiceImplTest extends KENTestCase {
39      public static final String VALID_USER_ID = TestConstants.TEST_USER_ONE;
40      public static final String VALID_CHANNEL_ID = TestConstants.VALID_CHANNEL_ONE_ID.toString();
41      public static final Long VALID_CHANNEL_ID_LONG = TestConstants.VALID_CHANNEL_ONE_ID;
42      //public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME;
43      public static final String[] CHANNEL_SELECTED = { TestConstants.VALID_CHANNEL_ONE_ID.toString() };
44      //public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY;
45      public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE;
46  
47      public UserPreferenceServiceImplTest() {
48      }
49  
50      @Test
51      public void testSubscribeToChannel() {
52          UserPreferenceService impl = services.getUserPreferenceService();
53          HashMap primaryKeys = new HashMap();
54          primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
55          NotificationChannelBo
56                  channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
57  
58          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
59          newSub.setUserId(VALID_USER_ID);
60          newSub.setChannel(channel);
61          impl.subscribeToChannel(newSub);
62          UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
63          assertNotNull(sub);
64          assertEquals(VALID_USER_ID, sub.getUserId());
65          assertEquals(VALID_CHANNEL_ID_LONG, sub.getChannel().getId());
66  
67      }
68      @Test
69      public void testGetCurrentSubscriptions() {
70          UserPreferenceService impl = services.getUserPreferenceService();
71          HashMap primaryKeys = new HashMap();
72          primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
73          NotificationChannelBo
74                  channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
75  
76          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
77          newSub.setUserId(VALID_USER_ID);
78          newSub.setChannel(channel);
79          impl.subscribeToChannel(newSub);
80          Collection<UserChannelSubscriptionBo> subs = impl.getCurrentSubscriptions(VALID_USER_ID);
81          assertEquals(1, subs.size());
82      }
83  
84      @Test
85      public void testUnsubscribeFromChannel() {
86          UserPreferenceService impl = services.getUserPreferenceService();
87          HashMap primaryKeys = new HashMap();
88          primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, VALID_CHANNEL_ID_LONG);
89          NotificationChannelBo
90                  channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
91  
92  
93          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
94          newSub.setUserId(VALID_USER_ID);
95          newSub.setChannel(channel);
96          impl.subscribeToChannel(newSub);
97  
98          UserChannelSubscriptionBo userChannelSubscription = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
99          impl.unsubscribeFromChannel(userChannelSubscription);
100 
101         UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
102         assertNull(sub);
103 
104     }
105 
106 }