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
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
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 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 }