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.ken.services.impl;
17  
18  import org.junit.Test;
19  
20  import org.kuali.rice.ken.bo.NotificationChannelBo;
21  import org.kuali.rice.ken.bo.UserChannelSubscriptionBo;
22  import org.kuali.rice.ken.service.UserPreferenceService;
23  import org.kuali.rice.ken.test.KENTestCase;
24  import org.kuali.rice.ken.test.TestConstants;
25  import org.kuali.rice.krad.service.KRADServiceLocator;
26  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
27  import org.kuali.rice.test.BaselineTestCase.Mode;
28  
29  import java.util.Collection;
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          NotificationChannelBo channel = KRADServiceLocator.getDataObjectService().find(NotificationChannelBo.class, VALID_CHANNEL_ID_LONG);
54  
55          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
56          newSub.setUserId(VALID_USER_ID);
57          newSub.setChannel(channel);
58          impl.subscribeToChannel(newSub);
59          UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
60          assertNotNull(sub);
61          assertEquals(VALID_USER_ID, sub.getUserId());
62          assertEquals(VALID_CHANNEL_ID_LONG, sub.getChannel().getId());
63  
64      }
65      @Test
66      public void testGetCurrentSubscriptions() {
67          UserPreferenceService impl = services.getUserPreferenceService();
68  
69          NotificationChannelBo
70                  channel = KRADServiceLocator.getDataObjectService().find(NotificationChannelBo.class, VALID_CHANNEL_ID_LONG);
71  
72          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
73          newSub.setUserId(VALID_USER_ID);
74          newSub.setChannel(channel);
75          impl.subscribeToChannel(newSub);
76          Collection<UserChannelSubscriptionBo> subs = impl.getCurrentSubscriptions(VALID_USER_ID);
77          assertEquals(1, subs.size());
78      }
79  
80      @Test
81      public void testUnsubscribeFromChannel() {
82          UserPreferenceService impl = services.getUserPreferenceService();
83          NotificationChannelBo
84                  channel = KRADServiceLocator.getDataObjectService().find(NotificationChannelBo.class, VALID_CHANNEL_ID_LONG);
85  
86  
87          UserChannelSubscriptionBo newSub = new UserChannelSubscriptionBo();
88          newSub.setUserId(VALID_USER_ID);
89          newSub.setChannel(channel);
90          impl.subscribeToChannel(newSub);
91  
92          UserChannelSubscriptionBo userChannelSubscription = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
93          impl.unsubscribeFromChannel(userChannelSubscription);
94  
95          UserChannelSubscriptionBo sub = impl.getSubscription(VALID_CHANNEL_ID, VALID_USER_ID);
96          assertNull(sub);
97  
98      }
99  
100 }