1 17 18 package org.apache.lenya.ac.impl; 19 20 import java.io.File ; 21 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.lenya.ac.AccessControlException; 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.FileRole; 29 import org.apache.lenya.ac.file.FileUserManager; 30 import org.apache.lenya.ac.ldap.LDAPUser; 31 import org.apache.lenya.cms.PublicationHelper; 32 import org.apache.lenya.cms.publication.Publication; 33 import org.apache.lenya.cms.publication.PublicationException; 34 import org.apache.lenya.cms.publication.PublicationFactory; 35 36 41 public class LDAPUserTest extends AccessControlTest { 42 46 public LDAPUserTest(String arg0) { 47 super(arg0); 48 } 49 50 54 public static void main(String [] args) { 55 PublicationHelper.extractPublicationArguments(args); 56 junit.textui.TestRunner.run(LDAPUserTest.class); 57 } 58 59 62 protected void setUp() throws Exception { 63 super.setUp(); 64 } 65 66 69 public void tearDown() throws Exception { 70 super.tearDown(); 71 } 72 73 80 final public Publication getPublication() throws PublicationException { 81 String publicationId = "default"; 82 String servletContextPath = 83 "/home/egli/build/jakarta-tomcat-4.1.21-LE-jdk14/webapps/lenya/"; 84 85 return PublicationFactory.getPublication( 86 publicationId, 87 servletContextPath); 88 } 89 90 99 final public void createAndSaveUser( 100 String userName, 101 String email, 102 String ldapId) 103 throws AccessControlException, ConfigurationException { 104 String editorGroupName = "editorGroup"; 105 String adminGroupName = "adminGroup"; 106 String editorRoleName = "editorRole"; 107 String adminRoleName = "adminRole"; 108 109 File configDir = getAccreditablesDirectory(); 110 FileRole editorRole = new FileRole(); 111 editorRole.setName(editorRoleName); 112 editorRole.setConfigurationDirectory(configDir); 113 114 FileRole adminRole = new FileRole(); 115 adminRole.setName(adminRoleName); 116 adminRole.setConfigurationDirectory(configDir); 117 118 FileGroup editorGroup = new FileGroup(configDir, editorGroupName); 119 FileGroup adminGroup = new FileGroup(configDir, adminGroupName); 120 121 LDAPUser user = new LDAPUser(configDir, userName, email, ldapId); 122 123 editorRole.save(); 124 adminRole.save(); 125 126 132 editorGroup.save(); 133 adminGroup.save(); 134 135 adminGroup.add(user); 136 user.save(); 137 } 138 139 146 final public LDAPUser loadUser(String userName) 147 throws AccessControlException { 148 UserType[] userTypes = { FileAccreditableManager.getDefaultUserType() }; 149 FileUserManager manager = FileUserManager.instance(getAccreditablesDirectory(), userTypes); 150 151 return (LDAPUser)manager.getUser(userName); 152 } 153 154 164 167 final public void testSetFullName() { 168 } 170 171 180 186 final public void testGetLdapId() 187 throws ConfigurationException, AccessControlException { 188 String userName = "felix"; 189 String ldapId = "m400032"; 190 createAndSaveUser(userName, "felix@wyona.com", ldapId); 191 192 LDAPUser user = null; 193 user = loadUser(userName); 194 assertNotNull(user); 195 assertEquals(ldapId, user.getLdapId()); 196 } 197 198 204 final public void testSetLdapId() 205 throws ConfigurationException, AccessControlException { 206 String userName = "felix"; 207 String newLdapId = "foo"; 208 createAndSaveUser(userName, "felix@wyona.com", "bar"); 209 210 LDAPUser user = null; 211 user = loadUser(userName); 212 assertNotNull(user); 213 user.setLdapId(newLdapId); 214 user.save(); 215 user = null; 216 user = loadUser(userName); 217 assertNotNull(user); 218 assertEquals(newLdapId, user.getLdapId()); 219 } 220 221 227 final public void testSave() 228 throws ConfigurationException, AccessControlException { 229 String userName = "felix"; 230 createAndSaveUser(userName, "felix@wyona.com", "m400032"); 231 232 User user = null; 233 user = loadUser(userName); 234 assertNotNull(user); 235 } 236 237 241 final public void testDelete() { 242 } 244 } 245 | Popular Tags |