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.NotificationProducerBo;
21 import org.kuali.rice.ken.test.KENTestCase;
22 import org.kuali.rice.ken.test.TestConstants;
23 import org.kuali.rice.ken.util.NotificationConstants;
24 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
25 import org.kuali.rice.test.BaselineTestCase.Mode;
26
27 import java.util.HashMap;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32
33
34
35
36 @BaselineMode(Mode.CLEAR_DB)
37 public class NotificationAuthorizationServiceImplTest extends KENTestCase {
38
39 public NotificationAuthorizationServiceImplTest() {
40 }
41
42 @Test
43 public void testIsProducerAuthorizedForNotificationChannel_validInput() {
44 HashMap<String, Long> primaryKeys = new HashMap<String, Long>();
45 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.CHANNEL_ID_1);
46 NotificationChannelBo
47 channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
48
49 primaryKeys.clear();
50 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.PRODUCER_3.getId());
51 NotificationProducerBo
52 producer = (NotificationProducerBo) services.getGenericDao().findByPrimaryKey(NotificationProducerBo.class, primaryKeys);
53
54 assertTrue(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
55 }
56
57 @Test
58 public void testIsProducerAuthorizedForNotificationChannel_invalidInput() {
59 HashMap primaryKeys = new HashMap();
60 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.CHANNEL_ID_1);
61 NotificationChannelBo
62 channel = (NotificationChannelBo) services.getGenericDao().findByPrimaryKey(NotificationChannelBo.class, primaryKeys);
63
64 primaryKeys.clear();
65 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID,TestConstants. PRODUCER_4.getId());
66 NotificationProducerBo
67 producer = (NotificationProducerBo) services.getGenericDao().findByPrimaryKey(NotificationProducerBo.class, primaryKeys);
68
69 assertFalse(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
70 }
71
72 @Test
73 public void testIsUserAdministrator_validAdmin() {
74 assertTrue(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.ADMIN_USER_1));
75 }
76
77 @Test
78 public void testIsUserAdministrator_nonAdmin() {
79 assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.NON_ADMIN_USER_1));
80 }
81
82 @Test
83 public void testIsUserAdministrator_invalidUser() {
84 assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.INVALID_USER_1));
85 }
86 }