Announcement Announcement Module
Collapse
No announcement yet.
Is there a tool that allows for pre-populating an LDAP Server Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a tool that allows for pre-populating an LDAP Server

    From issues I've experienced with using Spring-LDAP:

    http://raibledesigns.com/page/rd?ent...fuse_dao_layer

    There's no LdapUnit (like DbUnit) to delete/insert users and roles before running tests. I tried to use the LdapTestServer[1] from Acegi, but no dice.

    [1] http://www.nabble.com/LdapTestServer...tf2411240.html

    Do you have any suggestions for pre-populating an LDAP server? I'm currently using DbUnit for Hibernate/iBATIS and I need something similar when testing LDAP.

    Thanks,

  • #2
    One of my coworkers keeps bragging about how wonderful WebObjects is, and how its persistence layer treats ldap like just another database. Your post made me think that perhaps DbUnit could be modified to do ldap as well.

    No help to you at the moment but I thought I'd "share".

    Comment


    • #3
      I don't know of anything quite like DBUnit for LDAP. However you might want to have a look at ddsteps. DDSteps is a framework for data-driven testing and it includes some functionality for pre-populating LDAP data (from Excel sheets) as well as validating the data after the test has been completed.

      The LDAP populating functionality is just a useful extra feature in the framework; it's a very powerful tool for integration and function testing in that it separates the test data from the actual tests.

      Comment


      • #4
        Another alternative is to look at how the integration tests in Spring LDAP are managed. It's a bit verbose, but if you browse the following files in src/itest/java, you'll see how it's done:

        conf/ldapTemplateTestContext.xml
        conf/apacheDsContext.xml
        org/springframework/ldap/ConfigEnvHelper
        org/springframework/ldap/LdapServerManager
        setup_data.ldif
        ldap.properties

        Basically we start a new in-memory server instance for each test, create a partition in it, and load an LDIF file with test data.

        The handling of the server is perhaps slightly non-intuitive. First, you plug in ApacheDS by setting the initialcontext factory to be the ApacheDS ServerContextFactory. You start a server instance by creating an InitialContext. You shut down the server instance by adding a ShutdownConfiguration to the environment and then creating an InitialContext again.

        Here is an example of shutting down the server:

        Code:
        public class LdapServerManager implements InitializingBean {
           ...
           public void shutdown() throws NamingException {
              Properties env = new Properties();
              env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                 ServerContextFactory.class.getName());
              ...
              ShutdownConfiguration configuration = new ShutdownConfiguration();
              env.putAll(configuration.toJndiEnvironment());
        
              new InitialContext(env);
           }
        }
        We start the server simply by configuring it as a Spring bean:

        Code:
        <bean name="serverContext" class="javax.naming.InitialContext">
           <constructor-arg>
              <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
                 <property name="targetObject" ref="configEnvHelper" />
                 <property name="propertyPath" value="env" />
              </bean>
           </constructor-arg>
        </bean>
        
        <bean id="configEnvHelper" class="org.springframework.ldap.ConfigEnvHelper">
           ...
        </bean>
        The configEnvHelper bean sets the initialcontext factory, the server working directory, and other configuration properties in afterPropertiesSet:

        Code:
        public class ConfigEnvHelper implements InitializingBean {
           ...
           public void afterPropertiesSet() throws Exception {
              initialEnv.put(Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName());
              ...
        }
        Admittedly, it's convoluted, but it enables repeatable integration tests towards a real LDAP server without the hassles of installing and maintaining a server. Anyone that checks out the source code get this benefit. Just point to the src/itest/java source folder and run it as a JUnit test.

        Comment

        Working...
        X