KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > impl > UserManagerTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  */

17
18 package org.apache.lenya.ac.impl;
19
20 import java.io.File JavaDoc;
21
22 import org.apache.lenya.ac.AccessControlException;
23 import org.apache.lenya.ac.Group;
24 import org.apache.lenya.ac.User;
25 import org.apache.lenya.ac.UserType;
26 import org.apache.lenya.ac.file.FileAccreditableManager;
27 import org.apache.lenya.ac.file.FileGroup;
28 import org.apache.lenya.ac.file.FileGroupManager;
29 import org.apache.lenya.ac.file.FileRole;
30 import org.apache.lenya.ac.file.FileUser;
31 import org.apache.lenya.ac.file.FileUserManager;
32 import org.apache.lenya.cms.PublicationHelper;
33
34 /**
35  * User manager test.
36  *
37  * @version $Id: UserManagerTest.java 43670 2004-09-10 14:29:22Z andreas $
38  */

39 public class UserManagerTest extends AccessControlTest {
40
41     /**
42      * Constructor for UserManagerTest.
43      * @param arg0 command line args
44      */

45     public UserManagerTest(String JavaDoc arg0) {
46         super(arg0);
47     }
48
49     /**
50      * DOCUMENT ME!
51      *
52      * @param args DOCUMENT ME!
53      */

54     public static void main(String JavaDoc[] args) {
55         PublicationHelper.extractPublicationArguments(args);
56         junit.textui.TestRunner.run(UserManagerTest.class);
57     }
58
59     /**
60      * (non-Javadoc)
61      * @see junit.framework.TestCase#setUp()
62      */

63     protected void setUp() throws Exception JavaDoc {
64         super.setUp();
65     }
66
67     /**
68      * DOCUMENT ME!
69      *
70      * @throws AccessControlException DOCUMENT ME!
71      */

72     final public void testInstance() throws AccessControlException {
73         File JavaDoc configDir = getAccreditablesDirectory();
74         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
75         FileUserManager manager = FileUserManager.instance(configDir, userTypes);
76         assertNotNull(manager);
77     }
78
79     /**
80      * DOCUMENT ME!
81      *
82      * @throws AccessControlException DOCUMENT ME!
83      */

84     final public void testLoadConfig() throws AccessControlException {
85         File JavaDoc configDir = getAccreditablesDirectory();
86
87         String JavaDoc userName = "alice";
88         String JavaDoc editorGroupId = "editorGroup";
89         String JavaDoc adminGroupId = "adminGroup";
90         String JavaDoc editorRoleId = "editorRole";
91         String JavaDoc adminRoleId = "adminRole";
92
93         FileRole editorRole = new FileRole(configDir, editorRoleId);
94         FileRole adminRole = new FileRole(configDir, adminRoleId);
95
96         User user =
97             new FileUser(configDir, userName, "Alice in Wonderland", "alice@test.com", "secret");
98
99         editorRole.save();
100         adminRole.save();
101
102         Group editorGroup = new FileGroup(configDir, editorGroupId);
103
104         // editorGroup.addRole(editorRole);
105
editorGroup.add(user);
106
107         FileGroup adminGroup = new FileGroup(configDir, adminGroupId);
108
109         // adminGroup.addRole(editorRole);
110
// adminGroup.addRole(adminRole);
111
editorGroup.save();
112         adminGroup.save();
113         adminGroup.add(user);
114         user.save();
115
116         FileGroupManager groupManager = null;
117         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
118         FileUserManager userManager = FileUserManager.instance(configDir, userTypes);
119         assertNotNull(userManager);
120
121         groupManager = FileGroupManager.instance(configDir);
122         assertNotNull(groupManager);
123
124         Group fetchedGroup = groupManager.getGroup(editorGroupId);
125         assertTrue(editorGroup.equals(fetchedGroup));
126
127         fetchedGroup = groupManager.getGroup(adminGroupId);
128         assertTrue(adminGroup.equals(fetchedGroup));
129     }
130
131     /**
132      * DOCUMENT ME!
133      *
134      * @throws AccessControlException DOCUMENT ME!
135      */

136     final public void testGetUser() throws AccessControlException {
137         File JavaDoc configDir = getAccreditablesDirectory();
138         String JavaDoc userName = "testuser";
139         FileUser user =
140             new FileUser(
141                 configDir,
142                 userName,
143                 "Alice in Wonderland",
144                 "alice@wonderland.com",
145                 "secret");
146         UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() };
147         FileUserManager manager = FileUserManager.instance(configDir, userTypes);
148         assertNotNull(manager);
149         manager.add(user);
150
151         User otherUser = manager.getUser(userName);
152         assertEquals(user, otherUser);
153         assertEquals(user.getDescription(), otherUser.getDescription());
154         assertEquals(user.getEmail(), otherUser.getEmail());
155         assertEquals(user.getEncryptedPassword(), ((AbstractUser) otherUser).getEncryptedPassword());
156     }
157 }
158
Popular Tags