KickJava   Java API By Example, From Geeks To Geeks.

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


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 /* $Id: RoleManagerTest.java 42625 2004-03-04 15:45:03Z egli $ */
19
20 package org.apache.lenya.ac.impl;
21
22 import java.io.File JavaDoc;
23
24 import org.apache.lenya.ac.AccessControlException;
25 import org.apache.lenya.ac.Role;
26 import org.apache.lenya.ac.file.FileRole;
27 import org.apache.lenya.ac.file.FileRoleManager;
28 import org.apache.lenya.cms.PublicationHelper;
29
30 public class RoleManagerTest extends AccessControlTest {
31     /**
32      * Constructor for RoleManagerTest.
33      * @param arg0 command line args
34      */

35     public RoleManagerTest(String JavaDoc arg0) {
36         super(arg0);
37     }
38
39     /**
40      * DOCUMENT ME!
41      *
42      * @param args DOCUMENT ME!
43      */

44     public static void main(String JavaDoc[] args) {
45         PublicationHelper.extractPublicationArguments(args);
46         junit.textui.TestRunner.run(RoleManagerTest.class);
47     }
48
49     /**
50      * DOCUMENT ME!
51      *
52      * @throws AccessControlException DOCUMENT ME!
53      */

54     final public void testInstance() throws AccessControlException {
55         File JavaDoc configDir = getAccreditablesDirectory();
56         FileRoleManager manager = FileRoleManager.instance(configDir);
57         assertNotNull(manager);
58
59         FileRoleManager anotherManager = FileRoleManager.instance(configDir);
60         assertNotNull(anotherManager);
61         assertEquals(manager, anotherManager);
62     }
63
64     /**
65      * DOCUMENT ME!
66      */

67     final public void testGetRoles() {
68     }
69
70     /**
71      * Test add(Role)
72      *
73      * @throws AccessControlException if an error occurs
74      */

75     final public void testAddRole() throws AccessControlException {
76         File JavaDoc configDir = getAccreditablesDirectory();
77         String JavaDoc name = "test";
78         FileRoleManager manager = null;
79         manager = FileRoleManager.instance(configDir);
80         assertNotNull(manager);
81         Role role = new FileRole(manager.getConfigurationDirectory(), name);
82         manager.add(role);
83
84         assertTrue(manager.getRoles().length > 0);
85     }
86
87     /**
88      * Test for void remove(Role)
89      *
90      */

91     final public void testRemoveRole() throws AccessControlException {
92         File JavaDoc configDir = getAccreditablesDirectory();
93         String JavaDoc name = "test2";
94         Role role = new FileRole(configDir, name);
95         FileRoleManager manager = null;
96
97         try {
98             manager = FileRoleManager.instance(configDir);
99         } catch (AccessControlException e) {
100             e.printStackTrace();
101         }
102
103         assertNotNull(manager);
104
105         Role[] roles = manager.getRoles();
106         int roleCountBefore = roles.length;
107
108         manager.add(role);
109         manager.remove(role);
110
111         roles = manager.getRoles();
112         int roleCountAfter = roles.length;
113
114         assertEquals(roleCountBefore, roleCountAfter);
115     }
116 }
117
Popular Tags