001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ken.services.impl;
017
018 import org.junit.Test;
019 import org.kuali.rice.ken.bo.NotificationChannel;
020 import org.kuali.rice.ken.bo.NotificationProducer;
021 import org.kuali.rice.ken.test.KENTestCase;
022 import org.kuali.rice.ken.test.TestConstants;
023 import org.kuali.rice.ken.util.NotificationConstants;
024 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
025 import org.kuali.rice.test.BaselineTestCase.Mode;
026
027 import java.util.HashMap;
028
029 import static org.junit.Assert.assertFalse;
030 import static org.junit.Assert.assertTrue;
031
032 /**
033 * This class tests the authz aspects of KEN
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
037 public class NotificationAuthorizationServiceImplTest extends KENTestCase {
038
039 public NotificationAuthorizationServiceImplTest() {
040 }
041
042 @Test
043 public void testIsProducerAuthorizedForNotificationChannel_validInput() {
044 HashMap<String, Long> primaryKeys = new HashMap<String, Long>();
045 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.CHANNEL_ID_1);
046 NotificationChannel channel = (NotificationChannel) services.getGenericDao().findByPrimaryKey(NotificationChannel.class, primaryKeys);
047
048 primaryKeys.clear();
049 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.PRODUCER_3.getId());
050 NotificationProducer producer = (NotificationProducer) services.getGenericDao().findByPrimaryKey(NotificationProducer.class, primaryKeys);
051
052 assertTrue(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
053 }
054
055 @Test
056 public void testIsProducerAuthorizedForNotificationChannel_invalidInput() {
057 HashMap primaryKeys = new HashMap();
058 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID, TestConstants.CHANNEL_ID_1);
059 NotificationChannel channel = (NotificationChannel) services.getGenericDao().findByPrimaryKey(NotificationChannel.class, primaryKeys);
060
061 primaryKeys.clear();
062 primaryKeys.put(NotificationConstants.BO_PROPERTY_NAMES.ID,TestConstants. PRODUCER_4.getId());
063 NotificationProducer producer = (NotificationProducer) services.getGenericDao().findByPrimaryKey(NotificationProducer.class, primaryKeys);
064
065 assertFalse(services.getNotificationAuthorizationService().isProducerAuthorizedToSendNotificationForChannel(producer, channel));
066 }
067
068 @Test
069 public void testIsUserAdministrator_validAdmin() {
070 assertTrue(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.ADMIN_USER_1));
071 }
072
073 @Test
074 public void testIsUserAdministrator_nonAdmin() {
075 assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.NON_ADMIN_USER_1));
076 }
077
078 @Test
079 public void testIsUserAdministrator_invalidUser() {
080 assertFalse(services.getNotificationAuthorizationService().isUserAdministrator(TestConstants.INVALID_USER_1));
081 }
082 }