From c34db326f8816950779c38e06b17380422d53581 Mon Sep 17 00:00:00 2001 From: Robert Sanders Date: Mon, 21 Mar 2005 03:20:19 +0000 Subject: [PATCH] Provide hook to get a client-side version of the DirContext. --- .../providers/dao/ldap/BaseLdapTestCase.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/sandbox/src/test/java/org/acegisecurity/providers/dao/ldap/BaseLdapTestCase.java b/sandbox/src/test/java/org/acegisecurity/providers/dao/ldap/BaseLdapTestCase.java index 2fa87e6097..a9083f95e3 100644 --- a/sandbox/src/test/java/org/acegisecurity/providers/dao/ldap/BaseLdapTestCase.java +++ b/sandbox/src/test/java/org/acegisecurity/providers/dao/ldap/BaseLdapTestCase.java @@ -1,14 +1,10 @@ package net.sf.acegisecurity.providers.dao.ldap; import java.util.Hashtable; - import javax.naming.Context; import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; - -import org.apache.ldap.server.jndi.EnvKeys; - import junit.framework.TestCase; /** Important note: this class merely defines certain @@ -16,22 +12,34 @@ import junit.framework.TestCase; */ public class BaseLdapTestCase extends TestCase { + // static finalizers, they'd be nice, as LdapTestHelper + // never seems to get the chance to cleanup after itself protected static LdapTestHelper ldapTestHelper = new LdapTestHelper(); - /** Create and return a Hashtable with standard JNDI settings for our tests. */ - protected Hashtable getEnvironment() { - Hashtable env = new Hashtable(); - env.put( Context.PROVIDER_URL, "ou=system" ); - env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" ); - env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" ); - env.put( Context.SECURITY_CREDENTIALS, "secret" ); - env.put( EnvKeys.WKDIR, ldapTestHelper.getTempDirectoryPath() ); - return env; + protected DirContext ctx; + + protected void setUp() throws NamingException { + ctx = getClientContext(); } - /** Create and return a Hashtable with standard JNDI settings for our tests. - * @throws NamingException */ - protected DirContext getInitialDirContext() throws NamingException { - return new InitialDirContext( getEnvironment() ); + protected void tearDown() throws NamingException { + ctx.close(); + ctx = null; } + + + protected DirContext getClientContext() throws NamingException { + Hashtable env = new Hashtable(); + env.put( Context.PROVIDER_URL, "ldap://localhost:389/ou=system" ); + env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); + //env.put( Context.SECURITY_PRINCIPAL, "uid=admin" ); + //env.put( Context.SECURITY_CREDENTIALS, "secret" ); + return new InitialDirContext( env ); + } + + /** @return The server context for LDAP ops. used for things like addding/removing users. */ + protected DirContext getServerContext() { + return ldapTestHelper.getServerContext(); + } + }