1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
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
43 public static final String[] CHANNEL_SELECTED = { TestConstants.VALID_CHANNEL_ONE_ID.toString() };
44
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 }