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