001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.service.impl;
017:
018: import java.util.ArrayList;
019:
020: import org.kuali.core.bo.user.UniversalUser;
021: import org.kuali.core.service.AuthorizationService;
022: import org.kuali.core.service.UniversalUserService;
023: import org.kuali.kfs.context.KualiTestBase;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.test.ConfigureContext;
026: import org.kuali.test.fixtures.UserNameFixture;
027:
028: @ConfigureContext
029: public class AuthorizationServiceImplTest extends KualiTestBase {
030:
031: private static final String KNOWN_ACTION = "initiate";
032: private static final String KNOWN_TARGETTYPE = "InternalBillingDocument";
033:
034: UniversalUser knownUser;
035:
036: @Override
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: // Make a new instance here because this test would have nasty side-effects on the KualiUser instance in the session.
041: knownUser = SpringContext.getBean(UniversalUserService.class)
042: .getUniversalUser(
043: UserNameFixture.KHUNTLEY
044: .getAuthenticationUserId());
045: }
046:
047: public final void testIsAuthorized_nullUser() {
048: boolean failedAsExpected = false;
049:
050: try {
051: SpringContext.getBean(AuthorizationService.class)
052: .isAuthorized(null, KNOWN_ACTION, KNOWN_TARGETTYPE);
053: } catch (IllegalArgumentException e) {
054: failedAsExpected = true;
055: }
056:
057: assertTrue(failedAsExpected);
058: }
059:
060: public final void testIsAuthorized_blankAction() {
061: boolean failedAsExpected = false;
062:
063: try {
064: SpringContext.getBean(AuthorizationService.class)
065: .isAuthorized(knownUser, " ", KNOWN_TARGETTYPE);
066: } catch (IllegalArgumentException e) {
067: failedAsExpected = true;
068: }
069:
070: assertTrue(failedAsExpected);
071: }
072:
073: public final void testIsAuthorized_blankTargetType() {
074: boolean failedAsExpected = false;
075:
076: try {
077: SpringContext.getBean(AuthorizationService.class)
078: .isAuthorized(knownUser, KNOWN_ACTION, " ");
079: } catch (IllegalArgumentException e) {
080: failedAsExpected = true;
081: }
082:
083: assertTrue(failedAsExpected);
084: }
085:
086: public final void testIsAuthorized_grouplessUser() {
087: knownUser.setGroups(new ArrayList());
088: assertFalse(SpringContext
089: .getBean(AuthorizationService.class)
090: .isAuthorized(knownUser, KNOWN_ACTION, KNOWN_TARGETTYPE));
091: }
092:
093: public final void testIsAuthorized_unknownAction() {
094: knownUser.setGroups(new ArrayList());
095: assertFalse(SpringContext.getBean(AuthorizationService.class)
096: .isAuthorized(knownUser, "foo", KNOWN_TARGETTYPE));
097: }
098:
099: public final void testIsAuthorized_unknownTargetType() {
100: knownUser.setGroups(new ArrayList());
101: assertFalse(SpringContext.getBean(AuthorizationService.class)
102: .isAuthorized(knownUser, KNOWN_ACTION, "foo"));
103: }
104:
105: public final void testIsAuthorized() {
106: assertTrue(SpringContext
107: .getBean(AuthorizationService.class)
108: .isAuthorized(knownUser, KNOWN_ACTION, KNOWN_TARGETTYPE));
109: }
110: }
|