1 17 18 package org.apache.lenya.ac.impl; 19 20 import java.io.File ; 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 39 public class UserManagerTest extends AccessControlTest { 40 41 45 public UserManagerTest(String arg0) { 46 super(arg0); 47 } 48 49 54 public static void main(String [] args) { 55 PublicationHelper.extractPublicationArguments(args); 56 junit.textui.TestRunner.run(UserManagerTest.class); 57 } 58 59 63 protected void setUp() throws Exception { 64 super.setUp(); 65 } 66 67 72 final public void testInstance() throws AccessControlException { 73 File configDir = getAccreditablesDirectory(); 74 UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() }; 75 FileUserManager manager = FileUserManager.instance(configDir, userTypes); 76 assertNotNull(manager); 77 } 78 79 84 final public void testLoadConfig() throws AccessControlException { 85 File configDir = getAccreditablesDirectory(); 86 87 String userName = "alice"; 88 String editorGroupId = "editorGroup"; 89 String adminGroupId = "adminGroup"; 90 String editorRoleId = "editorRole"; 91 String 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.add(user); 106 107 FileGroup adminGroup = new FileGroup(configDir, adminGroupId); 108 109 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 136 final public void testGetUser() throws AccessControlException { 137 File configDir = getAccreditablesDirectory(); 138 String 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 |