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  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.krad.service.KRADServiceLocator;
24  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
25  import org.kuali.rice.test.BaselineTestCase.Mode;
26  
27  import static org.junit.Assert.assertFalse;
28  import static org.junit.Assert.assertTrue;
29  
30  /**
31   * This class tests the authz aspects of KEN
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @BaselineMode(Mode.CLEAR_DB)
35  public class NotificationAuthorizationServiceImplTest extends KENTestCase {
36  
37      public NotificationAuthorizationServiceImplTest() {
38      }
39  
40      @Test
41      public void testIsProducerAuthorizedForNotificationChannel_validInput() {
42  
43          NotificationChannelBo channel = KRADServiceLocator.getDataObjectService().find(NotificationChannelBo.class,
44                  TestConstants.CHANNEL_ID_1);
45          NotificationProducerBo producer = KRADServiceLocator.getDataObjectService().find(NotificationProducerBo.class,
46                  TestConstants.PRODUCER_3.getId());
47  
48  	    assertTrue(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
49      }
50  
51      @Test
52      public void testIsProducerAuthorizedForNotificationChannel_invalidInput() {
53  
54          NotificationChannelBo channel = KRADServiceLocator.getDataObjectService().find(NotificationChannelBo.class, TestConstants.CHANNEL_ID_1);
55          NotificationProducerBo producer = KRADServiceLocator.getDataObjectService().find(NotificationProducerBo.class, TestConstants.PRODUCER_4.getId());
56  
57  	    assertFalse(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
58      }
59  
60      @Test
61      public void testIsUserAdministrator_validAdmin() {
62  	    assertTrue(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.ADMIN_USER_1));
63      }
64  
65      @Test
66      public void testIsUserAdministrator_nonAdmin() {
67  	    assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.NON_ADMIN_USER_1));
68      }
69  
70      @Test
71      public void testIsUserAdministrator_invalidUser() {
72  	    assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.INVALID_USER_1));
73      }
74  }