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.NotificationChannel;
20  import org.kuali.rice.ken.bo.NotificationProducer;
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   * This class tests the authz aspects of KEN
34   * @author Kuali Rice Team (rice.collab@kuali.org)
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  	NotificationChannel channel = (NotificationChannel) services.getGenericDao().findByPrimaryKey(NotificationChannel.class, primaryKeys);
47  
48  	primaryKeys.clear();
49  	primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.PRODUCER_3.getId());
50  	NotificationProducer producer = (NotificationProducer) services.getGenericDao().findByPrimaryKey(NotificationProducer.class, primaryKeys);
51  
52  	assertTrue(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
53      }
54  
55      @Test
56      public void testIsProducerAuthorizedForNotificationChannel_invalidInput() {
57  	HashMap primaryKeys = new HashMap();
58  	primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.CHANNEL_ID_1);
59  	NotificationChannel channel = (NotificationChannel) services.getGenericDao().findByPrimaryKey(NotificationChannel.class, primaryKeys);
60  
61  	primaryKeys.clear();
62  	primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID,TestConstants. PRODUCER_4.getId());
63  	NotificationProducer producer = (NotificationProducer) services.getGenericDao().findByPrimaryKey(NotificationProducer.class, primaryKeys);
64  
65  	assertFalse(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
66      }
67  
68      @Test
69      public void testIsUserAdministrator_validAdmin() {
70  	assertTrue(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.ADMIN_USER_1));
71      }
72  
73      @Test
74      public void testIsUserAdministrator_nonAdmin() {
75  	assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.NON_ADMIN_USER_1));
76      }
77  
78      @Test
79      public void testIsUserAdministrator_invalidUser() {
80  	assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.INVALID_USER_1));
81      }
82  }