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
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.lenya.ac.impl;
020:
021: import java.io.File;
022:
023: import org.apache.lenya.ac.AccessControlException;
024: import org.apache.lenya.ac.Group;
025: import org.apache.lenya.ac.User;
026: import org.apache.lenya.ac.UserManager;
027: import org.apache.lenya.ac.UserType;
028: import org.apache.lenya.ac.file.FileAccreditableManager;
029: import org.apache.lenya.ac.file.FileGroup;
030: import org.apache.lenya.ac.file.FileGroupManager;
031: import org.apache.lenya.ac.file.FileRole;
032: import org.apache.lenya.ac.file.FileUser;
033: import org.apache.lenya.ac.file.FileUserManager;
034:
035: /**
036: * User manager test.
037: *
038: * @version $Id: UserManagerTest.java 485769 2006-12-11 17:41:23Z andreas $
039: */
040: public class UserManagerTest extends AbstractAccessControlTest {
041:
042: /**
043: * @see junit.framework.TestCase#setUp()
044: */
045: public void setUp() throws Exception {
046: super .setUp();
047: }
048:
049: /**
050: * Run the test
051: * @throws AccessControlException if an error occurs
052: */
053: final public void testInstance() throws AccessControlException {
054: UserManager _manager = getAccreditableManager()
055: .getUserManager();
056: assertNotNull(_manager);
057: }
058:
059: /**
060: * Load the configuration for the test
061: * @throws AccessControlException if an error occurs
062: */
063: final public void testLoadConfig() throws AccessControlException {
064: FileAccreditableManager accreditableManager = (FileAccreditableManager) getAccreditableManager();
065: File configDir = accreditableManager
066: .getConfigurationDirectory();
067:
068: String userName = "aliceTest";
069: String editorGroupId = "editorGroup";
070: String adminGroupId = "adminGroup";
071: String editorRoleId = "editorRole";
072: String adminRoleId = "adminRole";
073:
074: FileRole editorRole = new FileRole(getAccreditableManager()
075: .getRoleManager(), getLogger(), editorRoleId);
076: FileRole adminRole = new FileRole(getAccreditableManager()
077: .getRoleManager(), getLogger(), adminRoleId);
078:
079: User user = new FileUser(getAccreditableManager()
080: .getUserManager(), getLogger(), userName,
081: "Alice in Wonderland", "alice@test.com", "secret");
082:
083: editorRole.save();
084: adminRole.save();
085:
086: Group editorGroup = new FileGroup(getAccreditableManager()
087: .getGroupManager(), getLogger(), editorGroupId);
088:
089: // editorGroup.addRole(editorRole);
090: editorGroup.add(user);
091:
092: FileGroup adminGroup = new FileGroup(getAccreditableManager()
093: .getGroupManager(), getLogger(), adminGroupId);
094:
095: // adminGroup.addRole(editorRole);
096: // adminGroup.addRole(adminRole);
097: editorGroup.save();
098: adminGroup.save();
099: adminGroup.add(user);
100: user.save();
101:
102: FileGroupManager groupManager = null;
103: UserManager userManager = getAccreditableManager()
104: .getUserManager();
105: assertNotNull(userManager);
106:
107: groupManager = FileGroupManager.instance(
108: getAccreditableManager(), configDir, getLogger());
109: assertNotNull(groupManager);
110:
111: Group fetchedGroup = groupManager.getGroup(editorGroupId);
112: assertTrue(editorGroup.equals(fetchedGroup));
113:
114: fetchedGroup = groupManager.getGroup(adminGroupId);
115: assertTrue(adminGroup.equals(fetchedGroup));
116: }
117:
118: /**
119: * Test getUser()
120: * @throws AccessControlException if an error occurs
121: */
122: final public void testGetUser() throws AccessControlException {
123: FileAccreditableManager accrMgr = (FileAccreditableManager) getAccreditableManager();
124: File configDir = accrMgr.getConfigurationDirectory();
125: String userName = "aliceTest";
126: FileUser user = new FileUser(getAccreditableManager()
127: .getUserManager(), getLogger(), userName,
128: "Alice in Wonderland", "alice@wonderland.com", "secret");
129: UserType[] userTypes = { FileAccreditableManager
130: .getDefaultUserType() };
131: FileUserManager _manager = FileUserManager.instance(
132: getAccreditableManager(), configDir, userTypes,
133: getLogger());
134: assertNotNull(_manager);
135: _manager.add(user);
136:
137: User otherUser = _manager.getUser(userName);
138: assertEquals(user, otherUser);
139: assertEquals(user.getDescription(), otherUser.getDescription());
140: assertEquals(user.getEmail(), otherUser.getEmail());
141: assertEquals(user.getEncryptedPassword(),
142: ((AbstractUser) otherUser).getEncryptedPassword());
143: }
144: }
|