You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/06/11 02:47:57 UTC

svn commit: r190051 - in /directory/apacheds/branches/direve-158/main: ./ src/main/java/org/apache/ldap/server/ src/main/java/org/apache/ldap/server/jndi/ src/test/org/apache/ldap/server/ src/test/org/apache/ldap/server/jndi/

Author: trustin
Date: Fri Jun 10 17:47:57 2005
New Revision: 190051

URL: http://svn.apache.org/viewcvs?rev=190051&view=rev
Log:
Fixed all tests.

Modified:
    directory/apacheds/branches/direve-158/main/project.xml
    directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/ServerMain.java
    directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
    directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java

Modified: directory/apacheds/branches/direve-158/main/project.xml
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/project.xml?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/project.xml (original)
+++ directory/apacheds/branches/direve-158/main/project.xml Fri Jun 10 17:47:57 2005
@@ -101,7 +101,7 @@
       <dependency>
         <groupId>directory-protocols</groupId>
         <artifactId>ldap-protocol</artifactId>
-        <version>0.9</version>
+        <version>0.9.1-SNAPSHOT</version>
       </dependency>
       <dependency>
         <groupId>directory-protocols</groupId>

Modified: directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/ServerMain.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/ServerMain.java?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/ServerMain.java (original)
+++ directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/ServerMain.java Fri Jun 10 17:47:57 2005
@@ -36,9 +36,6 @@
  */
 public class ServerMain
 {
-    /** the default LDAP port to use */
-    private static final int LDAP_PORT = 389;
-
     /**
      * Takes a single argument, an optional properties file to load with server
      * startup settings.

Modified: directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java (original)
+++ directory/apacheds/branches/direve-158/main/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java Fri Jun 10 17:47:57 2005
@@ -95,14 +95,12 @@
                     if ( ldapService != null )
                     {
                         minaRegistry.unbind( ldapService );
-
                         ldapService = null;
                     }
 
                     if ( kerberosService != null )
                     {
                         minaRegistry.unbind( kerberosService );
-
                         kerberosService = null;
                     }
                 }
@@ -114,23 +112,21 @@
             catch( Throwable t )
             {
                 NamingException ne = new NamingException( "Failed to shutdown." );
-
                 ne.setRootCause( t );
-
                 throw ne;
             }
             finally
             {
                 ctx = new DeadContext();
-
                 provider = null;
-
                 initialEnv = null;
+                configuration = null;
             }
 
             return ctx;
         }
 
+        boolean firstRun = provider == null;
         ctx = super.getInitialContext( env );
 
         // fire up the front end if we have not explicitly disabled it
@@ -140,7 +136,7 @@
             return ctx;
         }
         
-        if( provider == null )
+        if( firstRun )
         {
             ServerStartupConfiguration cfg =
                 ( ServerStartupConfiguration ) cfg0;

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java (original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/AbstractServerTest.java Fri Jun 10 17:47:57 2005
@@ -17,7 +17,21 @@
 package org.apache.ldap.server;
 
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
+
 import junit.framework.TestCase;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.ldap.common.exception.LdapConfigurationException;
 import org.apache.ldap.common.ldif.LdifIterator;
@@ -25,21 +39,10 @@
 import org.apache.ldap.common.ldif.LdifParserImpl;
 import org.apache.ldap.common.message.LockableAttributesImpl;
 import org.apache.ldap.common.name.LdapName;
-import org.apache.ldap.server.jndi.EnvKeys;
+import org.apache.ldap.server.configuration.MutableServerStartupConfiguration;
+import org.apache.ldap.server.configuration.ShutdownConfiguration;
 import org.apache.mina.util.AvailablePortFinder;
 
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
-import javax.naming.ldap.InitialLdapContext;
-import javax.naming.ldap.LdapContext;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Hashtable;
-
 
 /**
  * A simple testcase for testing JNDI provider functionality.
@@ -55,11 +58,7 @@
     /** flag whether to delete database files for each test or not */
     protected boolean doDelete = true;
 
-    /** extra environment parameters that can be added before setUp */
-    protected Hashtable extras = new Hashtable();
-
-    /** extra environment parameters that can be added before setUp to override values */
-    protected Hashtable overrides = new Hashtable();
+    protected MutableServerStartupConfiguration configuration = new MutableServerStartupConfiguration();
 
     protected int port = -1;
 
@@ -73,18 +72,9 @@
     {
         super.setUp();
 
-        if ( overrides.containsKey( EnvKeys.WKDIR ) )
-        {
-            doDelete( new File( ( String ) overrides.get( EnvKeys.WKDIR ) ) );
-        }
-        else
-        {
-            doDelete( new File( "target" + File.separator + "apacheds" ) );
-        }
-
+        doDelete( configuration.getWorkingDirectory() );
         port = AvailablePortFinder.getNextAvailable( 1024 );
-        
-        extras.put( EnvKeys.LDAP_PORT, String.valueOf( port ) );
+        configuration.setLdapPort( port );
 
         setSysRoot( "uid=admin,ou=system", "secret" );
     }
@@ -121,7 +111,7 @@
      */
     protected LdapContext setSysRoot( String user, String passwd ) throws NamingException
     {
-        Hashtable env = new Hashtable();
+        Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.SECURITY_PRINCIPAL, user );
 
@@ -142,25 +132,14 @@
      */
     protected LdapContext setSysRoot( Hashtable env ) throws NamingException
     {
-        Hashtable envFinal = new Hashtable();
-
-        envFinal.putAll( extras );
-
-        envFinal.putAll( env );
-
+        Hashtable envFinal = new Hashtable( env );
         envFinal.put( Context.PROVIDER_URL, "ou=system" );
-
-        envFinal.put( EnvKeys.WKDIR, "target" + File.separator + "apacheds" );
-
         envFinal.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" );
 
-        envFinal.putAll( overrides );
-
         return sysRoot = new InitialLdapContext( envFinal, null );
     }
 
 
-
     /**
      * Sets the system context root to null.
      *
@@ -176,7 +155,7 @@
 
         env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" );
 
-        env.put( EnvKeys.SHUTDOWN, "" );
+        env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
 
         env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
 
@@ -185,8 +164,8 @@
         try { new InitialContext( env ); } catch( Exception e ) {}
 
         sysRoot = null;
-
-        Runtime.getRuntime().gc();
+        doDelete( configuration.getWorkingDirectory() );
+        configuration = new MutableServerStartupConfiguration();
     }
 
 

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java (original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/DisableAnonBindTest.java Fri Jun 10 17:47:57 2005
@@ -17,8 +17,6 @@
 package org.apache.ldap.server;
 
 
-import java.io.File;
-import java.io.IOException;
 import java.util.Hashtable;
 
 import javax.naming.Context;
@@ -37,11 +35,9 @@
 {
     /**
      * Cleans up old database files on creation.
-     * @throws IOException 
      */
-    public DisableAnonBindTest() throws IOException
+    public DisableAnonBindTest()
     {
-        doDelete( new File( "target" + File.separator + "server" ) );
     }
 
 
@@ -50,13 +46,12 @@
      *
      * @throws Exception
      */
-    protected void setUp() throws Exception
+    public void setUp() throws Exception
     {
         if ( getName().equals( "testDisableAnonymousBinds" ) )
         {
-            extras.put( EnvKeys.DISABLE_ANONYMOUS, "true" );
+            configuration.setAllowAnonymousAccess( false );
         }
-
         super.setUp();
     }
 
@@ -79,19 +74,13 @@
 
         env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
 
-        InitialContext ctx = null;
-
         try
         {
-            ctx = new InitialContext( env );
-
+            new InitialContext( env );
             fail( "If anonymous binds are disabled we should never get here!" );
         }
         catch ( NoPermissionException e )
         {
-            assertNull( ctx );
-
-            assertNotNull( e );
         }
     }
 }

Modified: directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java?rev=190051&r1=190050&r2=190051&view=diff
==============================================================================
--- directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java (original)
+++ directory/apacheds/branches/direve-158/main/src/test/org/apache/ldap/server/jndi/ServerContextFactoryTest.java Fri Jun 10 17:47:57 2005
@@ -17,13 +17,21 @@
 package org.apache.ldap.server.jndi;
 
 
-import org.apache.ldap.server.AbstractCoreTest;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import javax.naming.directory.*;
-import java.util.Hashtable;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.ldap.server.AbstractCoreTest;
+import org.apache.ldap.server.configuration.MutableContextPartitionConfiguration;
 
 
 /**
@@ -36,82 +44,91 @@
 {
     public ServerContextFactoryTest()
     {
-        BasicAttributes attrs = new BasicAttributes( true );
+    }
 
-        BasicAttribute attr = new BasicAttribute( "objectClass" );
+    public void setUp() throws Exception
+    {
+        BasicAttributes attrs;
+        Set indexedAttrs;
+        Set pcfgs = new HashSet();
+
+        MutableContextPartitionConfiguration pcfg;
+        
+        // Add partition 'testing'
+        pcfg = new MutableContextPartitionConfiguration();
+        pcfg.setName( "testing" );
+        pcfg.setSuffix( "ou=testing" );
+        
+        indexedAttrs = new HashSet();
+        indexedAttrs.add( "ou" );
+        indexedAttrs.add( "objectClass" );
+        pcfg.setIndexedAttributes( indexedAttrs );
 
+        attrs = new BasicAttributes( true );
+        BasicAttribute attr = new BasicAttribute( "objectClass" );
         attr.add( "top" );
-
         attr.add( "organizationalUnit" );
-
         attr.add( "extensibleObject" );
-
         attrs.put( attr );
-
         attr = new BasicAttribute( "ou" );
-
         attr.add( "testing" );
-
         attrs.put( attr );
-
-        extras.put( EnvKeys.PARTITIONS, "testing example MixedCase" );
-
-        extras.put( EnvKeys.SUFFIX + "testing", "ou=testing" );
-
-        extras.put( EnvKeys.INDICES + "testing", "ou objectClass" );
-
-        extras.put( EnvKeys.ATTRIBUTES + "testing", attrs );
-
+        pcfg.setContextEntry( attrs );
+        
+        pcfgs.add( pcfg );
+        
+        // Add partition 'example'
+        pcfg = new MutableContextPartitionConfiguration();
+        pcfg.setName( "example" );
+        pcfg.setSuffix( "dc=example" );
+        
+        indexedAttrs = new HashSet();
+        indexedAttrs.add( "ou" );
+        indexedAttrs.add( "dc" );
+        indexedAttrs.add( "objectClass" );
+        pcfg.setIndexedAttributes( indexedAttrs );
+        
         attrs = new BasicAttributes( true );
-
         attr = new BasicAttribute( "objectClass" );
-
         attr.add( "top" );
-
         attr.add( "domain" );
-
         attr.add( "extensibleObject" );
-
         attrs.put( attr );
-
         attr = new BasicAttribute( "dc" );
-
         attr.add( "example" );
-
         attrs.put( attr );
-
-        extras.put( EnvKeys.SUFFIX + "example", "dc=example" );
-
-        extras.put( EnvKeys.INDICES + "example", "ou dc objectClass" );
-
-        extras.put( EnvKeys.ATTRIBUTES + "example", attrs );
+        pcfg.setContextEntry( attrs );
+        
+        pcfgs.add( pcfg );
+
+        // Add partition 'MixedCase'
+        pcfg = new MutableContextPartitionConfiguration();
+        pcfg.setName( "example" );
+        pcfg.setSuffix( "dc=MixedCase" );
+        
+        indexedAttrs = new HashSet();
+        indexedAttrs.add( "dc" );
+        indexedAttrs.add( "objectClass" );
+        pcfg.setIndexedAttributes( indexedAttrs );
 
         attrs = new BasicAttributes( true );
-
         attr = new BasicAttribute( "objectClass" );
-
         attr.add( "top" );
-
         attr.add( "domain" );
-
         attr.add( "extensibleObject" );
-
         attrs.put( attr );
-
         attr = new BasicAttribute( "dc" );
-
         attr.add( "MixedCase" );
-
         attrs.put( attr );
+        pcfg.setContextEntry( attrs );
+        
+        pcfgs.add( pcfg );
+        
+        configuration.setContextPartitionConfigurations( pcfgs );
 
-        extras.put( EnvKeys.SUFFIX + "MixedCase", "dc=MixedCase" );
-
-        extras.put( EnvKeys.INDICES + "MixedCase", "dc objectClass" );
-
-        extras.put( EnvKeys.ATTRIBUTES + "MixedCase", attrs );
+        super.setUp();
     }
 
-
     /**
      * Makes sure the system context has the right attributes and values.
      *
@@ -164,7 +181,7 @@
 
     public void testAppPartitionExample() throws NamingException
     {
-        Hashtable env = new Hashtable();
+        Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "dc=example" );
 
@@ -198,7 +215,7 @@
 
     public void testAppPartitionTesting() throws NamingException
     {
-        Hashtable env = new Hashtable();
+        Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "ou=testing" );
 
@@ -232,7 +249,7 @@
 
     public void testAppPartitionMixedCase() throws NamingException
     {
-        Hashtable env = new Hashtable();
+        Hashtable env = new Hashtable( configuration.toJndiEnvironment() );
 
         env.put( Context.PROVIDER_URL, "dc=MixedCase" );