001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software distributed under the License
012: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
013: * or implied. See the License for the specific language governing permissions and limitations under
014: * the License.
015: *
016: */
017:
018: package org.apache.lenya.ac.impl;
019:
020: import java.io.File;
021:
022: import org.apache.lenya.ac.AccessControlException;
023: import org.apache.lenya.ac.Role;
024: import org.apache.lenya.ac.file.FileRole;
025: import org.apache.lenya.ac.file.FileRoleManager;
026:
027: /**
028: * Role manager test.
029: *
030: * @version $Id: RoleManagerTest.java 485769 2006-12-11 17:41:23Z andreas $
031: */
032: public class RoleManagerTest extends AbstractAccessControlTest {
033:
034: /**
035: * Run the test
036: * @throws AccessControlException if an error occurs
037: */
038: final public void testInstance() throws AccessControlException {
039: File configDir = getAccreditablesDirectory();
040: FileRoleManager _manager = FileRoleManager.instance(
041: getAccreditableManager(), configDir, getLogger());
042: assertNotNull(_manager);
043:
044: FileRoleManager anotherManager = FileRoleManager.instance(
045: getAccreditableManager(), configDir, getLogger());
046: assertNotNull(anotherManager);
047: assertEquals(_manager, anotherManager);
048: }
049:
050: /**
051: * Test getRoles()
052: */
053: final public void testGetRoles() {
054: // do nothing
055: }
056:
057: /**
058: * Test add(Role)
059: * @throws AccessControlException if an error occurs
060: */
061: final public void testAddRole() throws AccessControlException {
062: File configDir = getAccreditablesDirectory();
063: String name = "test";
064: FileRoleManager _manager = null;
065: _manager = FileRoleManager.instance(getAccreditableManager(),
066: configDir, getLogger());
067: assertNotNull(_manager);
068: Role role = new FileRole(getAccreditableManager()
069: .getRoleManager(), getLogger(), name);
070: _manager.add(role);
071:
072: assertTrue(_manager.getRoles().length > 0);
073: }
074:
075: /**
076: * Test for void remove(Role)
077: * @throws AccessControlException if an error occurs.
078: */
079: final public void testRemoveRole() throws AccessControlException {
080: File configDir = getAccreditablesDirectory();
081: String name = "test2";
082: Role role = new FileRole(getAccreditableManager()
083: .getRoleManager(), getLogger(), name);
084: FileRoleManager _manager = null;
085:
086: try {
087: _manager = FileRoleManager.instance(
088: getAccreditableManager(), configDir, getLogger());
089: } catch (AccessControlException e) {
090: e.printStackTrace();
091: }
092:
093: assertNotNull(_manager);
094:
095: Role[] roles = _manager.getRoles();
096: int roleCountBefore = roles.length;
097:
098: _manager.add(role);
099: _manager.remove(role);
100:
101: roles = _manager.getRoles();
102: int roleCountAfter = roles.length;
103:
104: assertEquals(roleCountBefore, roleCountAfter);
105: }
106: }
|