directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r763449 - in /directory/apacheds/branches/apacheds-replication/ldap-api-test: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/directory/ src/test/java/org/apache/directory/shared/ src/t...
Date Wed, 08 Apr 2009 23:08:46 GMT
Author: elecharny
Date: Wed Apr  8 23:08:45 2009
New Revision: 763449

URL: http://svn.apache.org/viewvc?rev=763449&view=rev
Log:
Added the first test for the LDAP api

Added:
    directory/apacheds/branches/apacheds-replication/ldap-api-test/   (with props)
    directory/apacheds/branches/apacheds-replication/ldap-api-test/pom.xml
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/
    directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java

Propchange: directory/apacheds/branches/apacheds-replication/ldap-api-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr  8 23:08:45 2009
@@ -0,0 +1,4 @@
+target
+.classpath
+.project
+.settings

Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/pom.xml?rev=763449&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/pom.xml (added)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/pom.xml Wed Apr  8 23:08:45
2009
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+  http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-parent</artifactId>
+    <version>1.5.5-SNAPSHOT</version>
+  </parent>
+  <artifactId>ldap-api-test</artifactId>
+  <name>LDAP API unit test</name>
+  <packaging>jar</packaging>
+
+  <description>
+    LDAP API testing framework for Apache Directory Server.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-io</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-net</groupId>
+      <artifactId>commons-net</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-server-jndi</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-server-integ</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-interceptor-kerberos</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core-integ</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-schema-extras</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-client-api</artifactId>
+      <version>${org.apache.directory.shared.version}</version>
+      <scope>test</scope>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-bootstrap-partition</artifactId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*ISuite.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
+

Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=763449&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
(added)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
Wed Apr  8 23:08:45 2009
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.client.api;
+
+import java.io.IOException;
+
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.integ.SiRunner;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.shared.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.client.api.exception.LdapException;
+import org.apache.directory.shared.ldap.client.api.messages.BindResponse;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test the LdapConnection class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@RunWith ( SiRunner.class ) 
+@CleanupLevel ( Level.CLASS )
+public class LdapConnectionTest
+{
+    /** The server instance */
+    public static LdapService ldapService;
+
+    
+    /**
+     * Test a successful bind request
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testBindRequest()
+    {
+        LdapConnection connection = new LdapConnection( "localhost", ldapService.getPort()
);
+        
+        try
+        {
+            assertTrue( connection.connect() );
+        }
+        catch ( IOException ioe )
+        {
+            fail();
+        }
+        
+        try
+        {
+            BindResponse bindResponse = connection.bind( "uid=admin,ou=system", "secret"
);
+            
+            assertNotNull( bindResponse );
+            
+            //connection.unBind();
+        }
+        catch ( LdapException le )
+        {
+            fail();
+        }
+        finally
+        {
+            try
+            {
+                connection.close();
+            }
+            catch( IOException ioe )
+            {
+                fail();
+            }
+        }
+    }
+}

Added: directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java?rev=763449&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java
(added)
+++ directory/apacheds/branches/apacheds-replication/ldap-api-test/src/test/java/org/apache/directory/shared/client/api/unit/AbstractServerTest.java
Wed Apr  8 23:08:45 2009
@@ -0,0 +1,444 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.client.api.unit;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.jndi.CoreContextFactory;
+import org.apache.directory.server.ldap.LdapService;
+import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.cramMD5.CramMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.digestMD5.DigestMd5MechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.gssapi.GssapiMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
+import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
+import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.server.ldap.handlers.extended.StoredProcedureExtendedOperationHandler;
+import org.apache.directory.server.protocol.shared.transport.TcpTransport;
+import org.apache.directory.shared.ldap.constants.SupportedSaslMechanisms;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
+import org.apache.mina.util.AvailablePortFinder;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A simple testcase for testing the LDAP client API
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractServerTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( AbstractServerTest.class );
+    private static final List<LdifEntry> EMPTY_LIST = Collections.unmodifiableList(
new ArrayList<LdifEntry>( 0 ) );
+
+    /** the context root for the system partition */
+    protected static LdapContext sysRoot;
+
+    /** the context root for the rootDSE */
+    protected static CoreSession rootDSE;
+
+    /** the context root for the schema */
+    protected static LdapContext schemaRoot;
+
+    /** flag whether to delete database files for each test or not */
+    protected static boolean doDelete = true;
+
+    protected static int port = -1;
+
+    private static int start;
+    private static long t0;
+    protected static int nbTests = 10000;
+    protected  static DirectoryService directoryService;
+    protected NioSocketAcceptor socketAcceptor;
+    protected static LdapService ldapService;
+
+    private static final String CTX_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
+
+    /**
+     * If there is an LDIF file with the same name as the test class 
+     * but with the .ldif extension then it is read and the entries 
+     * it contains are added to the server.  It appears as though the
+     * administor adds these entries to the server.
+     *
+     * @param verifyEntries whether or not all entry additions are checked
+     * to see if they were in fact correctly added to the server
+     * @return a list of entries added to the server in the order they were added
+     * @throws NamingException of the load fails
+     */
+    protected List<LdifEntry> loadTestLdif( boolean verifyEntries ) throws Exception
+    {
+        return loadLdif( getClass().getResourceAsStream( getClass().getSimpleName() + ".ldif"
), verifyEntries );
+    }
+
+
+    /**
+     * Loads an LDIF from an input stream and adds the entries it contains to 
+     * the server.  It appears as though the administrator added these entries
+     * to the server.
+     *
+     * @param in the input stream containing the LDIF entries to load
+     * @param verifyEntries whether or not all entry additions are checked
+     * to see if they were in fact correctly added to the server
+     * @return a list of entries added to the server in the order they were added
+     * @throws NamingException of the load fails
+     */
+    protected List<LdifEntry> loadLdif( InputStream in, boolean verifyEntries ) throws
Exception
+    {
+        if ( in == null )
+        {
+            return EMPTY_LIST;
+        }
+        
+        LdifReader ldifReader = new LdifReader( in );
+        List<LdifEntry> entries = new ArrayList<LdifEntry>();
+
+        for ( LdifEntry entry:ldifReader )
+        {
+            rootDSE.add( 
+                new DefaultServerEntry( directoryService.getRegistries(), entry.getEntry()
) ); 
+            
+            if ( verifyEntries )
+            {
+                verify( entry );
+                LOG.info( "Successfully verified addition of entry {}", entry.getDn() );
+            }
+            else
+            {
+                LOG.info( "Added entry {} without verification", entry.getDn() );
+            }
+            
+            entries.add( entry );
+        }
+        
+        return entries;
+    }
+    
+
+    /**
+     * Verifies that an entry exists in the directory with the 
+     * specified attributes.
+     *
+     * @param entry the entry to verify
+     * @throws NamingException if there are problems accessing the entry
+     */
+    protected void verify( LdifEntry entry ) throws Exception
+    {
+        Entry readEntry = rootDSE.lookup( entry.getDn() );
+        
+        for ( EntryAttribute readAttribute:readEntry )
+        {
+            String id = readAttribute.getId();
+            EntryAttribute origAttribute = entry.getEntry().get( id );
+            
+            for ( Value<?> value:origAttribute )
+            {
+                if ( ! readAttribute.contains( value ) )
+                {
+                    LOG.error( "Failed to verify entry addition of {}. {} attribute in original
" +
+                            "entry missing from read entry.", entry.getDn(), id );
+                    throw new AssertionFailedError( "Failed to verify entry addition of "
+ entry.getDn()  );
+                }
+            }
+        }
+    }
+    
+
+    /**
+     * Common code to get an initial context via a simple bind to the 
+     * server over the wire using the SUN JNDI LDAP provider. Do not use 
+     * this method until after the setUp() method is called to start the
+     * server otherwise it will fail. 
+     *
+     * @return an LDAP context as the the administrator to the rootDSE
+     * @throws NamingException if the server cannot be contacted
+     */
+    protected LdapContext getWiredContext() throws Exception
+    {
+        return getWiredContext( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
+    }
+    
+    
+    /**
+     * Common code to get an initial context via a simple bind to the 
+     * server over the wire using the SUN JNDI LDAP provider. Do not use 
+     * this method until after the setUp() method is called to start the
+     * server otherwise it will fail.
+     *
+     * @param bindPrincipalDn the DN of the principal to bind as
+     * @param password the password of the bind principal
+     * @return an LDAP context as the the administrator to the rootDSE
+     * @throws NamingException if the server cannot be contacted
+     */
+    protected LdapContext getWiredContext( String bindPrincipalDn, String password ) throws
Exception
+    {
+        Hashtable<String, String> env = new Hashtable<String, String>();
+        env.put( Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY );
+        env.put( Context.PROVIDER_URL, "ldap://localhost:" + port );
+        env.put( Context.SECURITY_PRINCIPAL, bindPrincipalDn );
+        env.put( Context.SECURITY_CREDENTIALS, password );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        return new InitialLdapContext( env, null );
+    }
+    
+    
+    /**
+     * Get's the initial context factory for the provider's ou=system context
+     * root.
+     *
+     * @see junit.framework.TestCase#setUp()
+     */
+    @BeforeClass
+    public static void setUp() throws Exception
+    {
+        if ( start == 0 )
+        {
+            t0 = System.currentTimeMillis();
+        }
+
+        start++;
+        directoryService = new DefaultDirectoryService();
+        directoryService.setShutdownHookEnabled( false );
+        port = AvailablePortFinder.getNextAvailable( 1024 );
+        ldapService = new LdapService();
+        ldapService.setTcpTransport( new TcpTransport( port ) );
+        ldapService.setDirectoryService( directoryService );
+
+        setupSaslMechanisms( ldapService );
+
+        doDelete( directoryService.getWorkingDirectory() );
+        configureDirectoryService();
+        directoryService.startup();
+
+        configureLdapServer();
+
+        // TODO shouldn't this be before calling configureLdapServer() ???
+        ldapService.addExtendedOperationHandler( new StartTlsHandler() );
+        ldapService.addExtendedOperationHandler( new StoredProcedureExtendedOperationHandler()
);
+
+        ldapService.start();
+        setContexts( ServerDNConstants.ADMIN_SYSTEM_DN, "secret" );
+    }
+
+
+    private static void setupSaslMechanisms( LdapService server )
+    {
+        Map<String, MechanismHandler> mechanismHandlerMap = new HashMap<String,MechanismHandler>();
+
+        mechanismHandlerMap.put( SupportedSaslMechanisms.PLAIN, new PlainMechanismHandler()
);
+
+        CramMd5MechanismHandler cramMd5MechanismHandler = new CramMd5MechanismHandler();
+        mechanismHandlerMap.put( SupportedSaslMechanisms.CRAM_MD5, cramMd5MechanismHandler
);
+
+        DigestMd5MechanismHandler digestMd5MechanismHandler = new DigestMd5MechanismHandler();
+        mechanismHandlerMap.put( SupportedSaslMechanisms.DIGEST_MD5, digestMd5MechanismHandler
);
+
+        GssapiMechanismHandler gssapiMechanismHandler = new GssapiMechanismHandler();
+        mechanismHandlerMap.put( SupportedSaslMechanisms.GSSAPI, gssapiMechanismHandler );
+
+        NtlmMechanismHandler ntlmMechanismHandler = new NtlmMechanismHandler();
+        // TODO - set some sort of default NtlmProvider implementation here
+        // ntlmMechanismHandler.setNtlmProvider( provider );
+        // TODO - or set FQCN of some sort of default NtlmProvider implementation here
+        // ntlmMechanismHandler.setNtlmProviderFqcn( "com.foo.BarNtlmProvider" );
+        mechanismHandlerMap.put( SupportedSaslMechanisms.NTLM, ntlmMechanismHandler );
+        mechanismHandlerMap.put( SupportedSaslMechanisms.GSS_SPNEGO, ntlmMechanismHandler
);
+
+        ldapService.setSaslMechanismHandlers( mechanismHandlerMap );
+    }
+
+
+    protected static void configureDirectoryService() throws Exception
+    {
+    }
+
+
+    protected static void configureLdapServer()
+    {
+    }
+
+
+    /**
+     * Deletes the Eve working directory.
+     * @param wkdir the directory to delete
+     * @throws IOException if the directory cannot be deleted
+     */
+    protected static void doDelete( File wkdir ) throws IOException
+    {
+        if ( doDelete )
+        {
+            if ( wkdir.exists() )
+            {
+                FileUtils.deleteDirectory( wkdir );
+            }
+
+            if ( wkdir.exists() )
+            {
+                throw new IOException( "Failed to delete: " + wkdir );
+            }
+        }
+    }
+
+
+    /**
+     * Sets the contexts for this base class.  Values of user and password used to
+     * set the respective JNDI properties.  These values can be overriden by the
+     * overrides properties.
+     *
+     * @param user the username for authenticating as this user
+     * @param passwd the password of the user
+     * @throws NamingException if there is a failure of any kind
+     */
+    protected static void setContexts( String user, String passwd ) throws Exception
+    {
+        Hashtable<String, Object> env = new Hashtable<String, Object>();
+        env.put( DirectoryService.JNDI_KEY, directoryService );
+        env.put( Context.SECURITY_PRINCIPAL, user );
+        env.put( Context.SECURITY_CREDENTIALS, passwd );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+        setContexts( env );
+    }
+
+
+    /**
+     * Sets the contexts of this class taking into account the extras and overrides
+     * properties.  
+     *
+     * @param env an environment to use while setting up the system root.
+     * @throws NamingException if there is a failure of any kind
+     */
+    protected static void setContexts( Hashtable<String, Object> env ) throws Exception
+    {
+        Hashtable<String, Object> envFinal = new Hashtable<String, Object>( env
);
+        envFinal.put( Context.PROVIDER_URL, ServerDNConstants.SYSTEM_DN );
+        sysRoot = new InitialLdapContext( envFinal, null );
+
+        envFinal.put( Context.PROVIDER_URL, "" );
+        rootDSE = directoryService.getAdminSession();
+
+        envFinal.put( Context.PROVIDER_URL, ServerDNConstants.OU_SCHEMA_DN );
+        schemaRoot = new InitialLdapContext( envFinal, null );
+    }
+
+
+    /**
+     * Sets the system context root to null.
+     *
+     * @see junit.framework.TestCase#tearDown()
+     */
+    @AfterClass
+    public static void tearDown() throws Exception
+    {
+        ldapService.stop();
+
+        try
+        {
+            directoryService.shutdown();
+        }
+        catch ( Exception e )
+        {
+        }
+
+        sysRoot = null;
+    }
+
+    
+    /**
+     * Imports the LDIF entries packaged with the Eve JNDI provider jar into
+     * the newly created system partition to prime it up for operation.  Note
+     * that only ou=system entries will be added - entries for other partitions
+     * cannot be imported and will blow chunks.
+     *
+     * @throws NamingException if there are problems reading the ldif file and
+     * adding those entries to the system partition
+     * @param in the input stream with the ldif
+     */
+    protected void importLdif( InputStream in ) throws NamingException
+    {
+        try
+        {
+            for ( LdifEntry ldifEntry:new LdifReader( in ) )
+            {
+                rootDSE.add( 
+                    new DefaultServerEntry( 
+                        rootDSE.getDirectoryService().getRegistries(), ldifEntry.getEntry()
) ); 
+            }
+        }
+        catch ( Exception e )
+        {
+            String msg = "failed while trying to parse system ldif file";
+            NamingException ne = new LdapConfigurationException( msg );
+            ne.setRootCause( e );
+            throw ne;
+        }
+    }
+
+    
+    /**
+     * Inject an ldif String into the server. DN must be relative to the
+     * root.
+     * @param ldif the entries to inject
+     * @throws NamingException if the entries cannot be added
+     */
+    protected void injectEntries( String ldif ) throws Exception
+    {
+        LdifReader reader = new LdifReader();
+        List<LdifEntry> entries = reader.parseLdif( ldif );
+
+        for ( LdifEntry entry : entries )
+        {
+            rootDSE.add( 
+                new DefaultServerEntry( 
+                    rootDSE.getDirectoryService().getRegistries(), entry.getEntry() ) );

+        }
+    }
+}



Mime
View raw message