Source Code Cross Referenced for FileUserTest.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » ac » file » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.lenya.ac.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        /* $Id: FileUserTest.java 485769 2006-12-11 17:41:23Z andreas $  */
020:
021:        package org.apache.lenya.ac.file;
022:
023:        import java.io.File;
024:        import java.util.HashMap;
025:        import java.util.Iterator;
026:        import java.util.Map;
027:
028:        import org.apache.avalon.framework.container.ContainerUtil;
029:        import org.apache.lenya.ac.AccessControlException;
030:        import org.apache.lenya.ac.Group;
031:        import org.apache.lenya.ac.User;
032:        import org.apache.lenya.ac.UserType;
033:        import org.apache.lenya.ac.impl.AbstractAccessControlTest;
034:
035:        /**
036:         * File user test.
037:         * 
038:         * @version $Id: FileUserTest.java 485769 2006-12-11 17:41:23Z andreas $
039:         */
040:        public class FileUserTest extends AbstractAccessControlTest {
041:            private HashMap groups = new HashMap();
042:
043:            /**
044:             * (non-Javadoc)
045:             * @see junit.framework.TestCase#setUp()
046:             */
047:            public void setUp() throws Exception {
048:                super .setUp();
049:            }
050:
051:            /**
052:             * Get all Groups
053:             * 
054:             * @return A map of the groups
055:             */
056:            final public Map getGroups() {
057:                return this .groups;
058:            }
059:
060:            /**
061:             * Create and save a user
062:             * 
063:             * @param userName The user name
064:             * @param fullName The full name
065:             * @param email The email
066:             * @param password The password
067:             * 
068:             * @return a <code>FileUser</code>
069:             * 
070:             * @throws AccessControlException if an error occurs
071:             */
072:            final public FileUser createAndSaveUser(String userName,
073:                    String fullName, String email, String password)
074:                    throws AccessControlException {
075:
076:                String editorGroupName = "editorGroup";
077:                String adminGroupName = "adminGroup";
078:
079:                FileGroup editorGroup = new FileGroup(getAccreditableManager()
080:                        .getGroupManager(), getLogger(), editorGroupName);
081:                ContainerUtil.enableLogging(editorGroup, getLogger());
082:                FileGroup adminGroup = new FileGroup(getAccreditableManager()
083:                        .getGroupManager(), getLogger(), adminGroupName);
084:                ContainerUtil.enableLogging(adminGroup, getLogger());
085:                this .groups.put(editorGroupName, editorGroup);
086:                this .groups.put(adminGroupName, adminGroup);
087:
088:                FileUser user = new FileUser(getAccreditableManager()
089:                        .getUserManager(), getLogger(), userName, fullName,
090:                        email, password);
091:                ContainerUtil.enableLogging(user, getLogger());
092:
093:                editorGroup.add(user);
094:                adminGroup.add(user);
095:
096:                editorGroup.save();
097:                adminGroup.save();
098:                user.save();
099:
100:                FileUserManager _manager = getUserManager();
101:                _manager.add(user);
102:
103:                return user;
104:            }
105:
106:            /**
107:             * Returns the file user manager.
108:             * @return A file user manager.
109:             * @throws AccessControlException if an error occurs.
110:             */
111:            protected FileUserManager getUserManager()
112:                    throws AccessControlException {
113:                UserType[] userTypes = { FileAccreditableManager
114:                        .getDefaultUserType() };
115:                FileUserManager _manager = FileUserManager.instance(
116:                        getAccreditableManager(), getAccreditablesDirectory(),
117:                        userTypes, getLogger());
118:                return _manager;
119:            }
120:
121:            /**
122:             * Load a user.
123:             * 
124:             * @param userName the name of the user
125:             * 
126:             * @return a <code>FileUser</code>
127:             * 
128:             * @throws AccessControlException if an error occurs
129:             */
130:            final public FileUser loadUser(String userName)
131:                    throws AccessControlException {
132:                FileUserManager _manager = getUserManager();
133:                return (FileUser) _manager.getUser(userName);
134:            }
135:
136:            /**
137:             * Test save
138:             * 
139:             * @throws AccessControlException if an error occurs
140:             */
141:            final public void testSave() throws AccessControlException {
142:                String userName = "aliceTest";
143:                createAndSaveUser(userName, "Alice Wonderland",
144:                        "alice@wonderland.org", "secret");
145:
146:                File configDir = getAccreditablesDirectory();
147:                File xmlFile = new File(configDir, userName + ".iml");
148:                assertTrue(xmlFile.exists());
149:            }
150:
151:            /**
152:             * Test getEmail
153:             * 
154:             * @throws AccessControlException if an error occurs
155:             */
156:            final public void testGetEmail() throws AccessControlException {
157:                String userID = "aliceTest";
158:                String email = "alice@wonderland.org";
159:                User user = createAndSaveUser(userID, "Alice Wonderland",
160:                        email, "secret");
161:                assertTrue(user.getEmail().equals(email));
162:                user = loadUser(userID);
163:                assertTrue(user.getEmail().equals(email));
164:            }
165:
166:            /**
167:             * Test getName
168:             * 
169:             * @throws AccessControlException if an error occurs
170:             */
171:            final public void testGetName() throws AccessControlException {
172:                String userID = "aliceTest";
173:                String userName = "Alice Wonderland";
174:                FileUser user = createAndSaveUser(userID, userName,
175:                        "alice@wonderland.org", "secret");
176:                assertTrue(user.getName().equals(userName));
177:                user = loadUser(userID);
178:                assertTrue(user.getName().equals(userName));
179:            }
180:
181:            /**
182:             * Test getGroups
183:             * 
184:             * @throws AccessControlException if an error occurs
185:             */
186:            final public void testGetGroups() throws AccessControlException {
187:                FileUser user = createAndSaveUser("aliceTest",
188:                        "Alice Wonderland", "alice@wonderland.org", "secret");
189:
190:                for (Iterator i = getGroups().values().iterator(); i.hasNext();) {
191:                    Group group = (Group) i.next();
192:                    assertTrue(group.contains(user));
193:                }
194:            }
195:
196:            /**
197:             * Test getId
198:             * 
199:             * @throws AccessControlException if an error occurs
200:             */
201:            final public void testGetId() throws AccessControlException {
202:                String id = "aliceTest";
203:                FileUser user = createAndSaveUser(id, "Alice Wonderland",
204:                        "alice@wonderland.org", "secret");
205:                assertTrue(user.getId().equals(id));
206:            }
207:
208:            /**
209:             * Test delete
210:             * 
211:             * @throws AccessControlException if an error occurs
212:             */
213:            final public void testDelete() throws AccessControlException {
214:                String id = "albert";
215:                FileUser user = createAndSaveUser(id, "Albert Einstein",
216:                        "albert@physics.org", "secret");
217:                FileUserManager _manager = getUserManager();
218:                assertNotNull(_manager);
219:
220:                assertNotNull(_manager.getUser(id));
221:                user.delete();
222:                _manager.remove(user);
223:                assertNull(_manager.getUser(id));
224:            }
225:
226:            /**
227:             * Test authenticate
228:             * 
229:             * @throws AccessControlException if an error occurs
230:             */
231:            final public void testAuthenticate() throws AccessControlException {
232:                String password = "daisy";
233:                FileUser user = createAndSaveUser("mickey", "Mickey Mouse",
234:                        "mickey@mouse.com", password);
235:                assertTrue(user.authenticate(password));
236:
237:                FileUserManager _manager = getUserManager();
238:                assertNotNull(_manager);
239:
240:                User lenya = _manager.getUser("lenya");
241:                assertNotNull(lenya);
242:                assertTrue(lenya.authenticate("levi"));
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.