KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jguard > ext > authentication > AuthenticationHelperTest


1 package net.sf.jguard.ext.authentication;
2
3 import java.util.List JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import junit.framework.TestCase;
7 import net.sf.jguard.core.CoreConstants;
8 import net.sf.jguard.ext.SecurityConstants;
9 import net.sf.jguard.ext.authentication.manager.AuthenticationHelper;
10
11 public class AuthenticationHelperTest extends TestCase {
12
13     public void testLoadConfiguration() {
14
15         String JavaDoc fileLocation = getClass().getResource("/jGuardAuthentication.xml").toString() ;
16         String JavaDoc appHomePath = "";
17
18         Map JavaDoc authenticationConfiguration = null;
19         try{
20             authenticationConfiguration = AuthenticationHelper.loadConfiguration(fileLocation, appHomePath);
21         } catch (Throwable JavaDoc t){
22             fail("Authentication configuration loading failed : " + t.getMessage());
23         }
24         assertNotNull("authentication Map must be initialized", authenticationConfiguration);
25
26         assertEquals("true", authenticationConfiguration.get(CoreConstants.DEBUG));
27         assertEquals("false", authenticationConfiguration.get(CoreConstants.INCLUDE_OLD_CONFIG));
28         assertEquals("false", authenticationConfiguration.get(CoreConstants.INCLUDE_CONFIG_FROM_JAVA_PARAM));
29         assertEquals("false", authenticationConfiguration.get(SecurityConstants.INCLUDE_POLICY_FROM_JAVA_PARAM));
30         assertEquals("MD5", authenticationConfiguration.get(SecurityConstants.DIGEST_ALGORITHM));
31         assertEquals("qsd846sdq6ds4", authenticationConfiguration.get(SecurityConstants.SALT));
32
33         assertEquals("net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager", authenticationConfiguration.get(SecurityConstants.AUTHENTICATION_MANAGER));
34         Map JavaDoc authenticationManagerOptions = (Map JavaDoc)authenticationConfiguration.get(SecurityConstants.AUTHENTICATION_MANAGER_OPTIONS);
35         assertNotNull("AuthenticationManager options map must be initialized", authenticationManagerOptions);
36         assertEquals("WEB-INF/conf/jGuard/jGuardUsersPrincipals.xml", authenticationManagerOptions.get(SecurityConstants.AUTHENTICATION_XML_FILE_LOCATION));
37
38         List JavaDoc loginModules = (List JavaDoc)authenticationConfiguration.get(CoreConstants.LOGIN_MODULES);
39         assertEquals(2, loginModules.size());
40
41         Map JavaDoc loginModuleMap = (Map JavaDoc)loginModules.get(1);
42         assertEquals("net.sf.jguard.ext.authentication.loginmodules.XmlLoginModule", loginModuleMap.get(CoreConstants.NAME));
43         assertEquals("REQUIRED", loginModuleMap.get(CoreConstants.FLAG));
44         Map JavaDoc loginModuleOptions = (Map JavaDoc)loginModuleMap.get(CoreConstants.LOGIN_MODULE_OPTIONS);
45         assertNotNull("LoginModule options map must be initialized", loginModuleOptions);
46         assertEquals("false", loginModuleOptions.get("debug"));
47
48     }
49
50 }
51
Popular Tags