You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/01/28 03:51:25 UTC

svn commit: r148842 - in incubator/directory/apacheds/trunk/core/src: main/java/org/apache/ldap/server/jndi main/java/org/apache/ldap/server/jndi/ibs main/java/org/apache/ldap/server/prefs main/schema test/org/apache/ldap/server/jndi test/org/apache/ldap/server/prefs

Author: akarasulu
Date: Thu Jan 27 18:51:19 2005
New Revision: 148842

URL: http://svn.apache.org/viewcvs?view=rev&rev=148842
Log:
changes ...

 o added preferences schema objects to apache.schema
 o added system preferences root object to system.ldif
 o added preferences class and factory

notes ...

 o still need to figure out how our factory is used instead
 o need more test cases
 o I think the relative lookups of preferences will break if more than 
   one component is used in the relative path - we do not break up


Added:
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/PreferencesUtils.java
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerPreferencesFactory.java
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java
   incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/
   incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/PreferencesUtilsTest.java
   incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerPreferencesFactoryTest.java
   incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java
Modified:
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif
   incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema
   incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java?view=diff&rev=148842&p1=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java&r1=148841&p2=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java&r2=148842
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java	(original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/OperationalAttributeService.java	Thu Jan 27 18:51:19 2005
@@ -270,9 +270,15 @@
         while ( list.hasMore() )
         {
             String attrId = ( String ) list.next();
-            AttributeType type = registry.lookup( attrId );
 
-            if ( type.getUsage() != UsageEnum.USERAPPLICATIONS )
+            AttributeType type = null;
+
+            if ( registry.hasAttributeType( attrId ) )
+            {
+                type = registry.lookup( attrId );
+            }
+
+            if ( type != null && type.getUsage() != UsageEnum.USERAPPLICATIONS )
             {
                 attributes.remove( attrId );
             }

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java?view=diff&rev=148842&p1=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java&r1=148841&p2=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java&r2=148842
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java	(original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/ibs/SchemaService.java	Thu Jan 27 18:51:19 2005
@@ -134,6 +134,7 @@
 
             // construct the set for fast lookups while filtering
             String binaryIds = ( String ) ctx.getEnvironment().get( BINARY_KEY );
+
             if ( binaryIds == null )
             {
                 binaries = Collections.EMPTY_SET;
@@ -141,10 +142,13 @@
             else
             {
                 String[] binaryArray = binaryIds.split( " " );
+
                 binaries = new HashSet( binaryArray.length );
+
                 for ( int ii = 0; ii < binaryArray.length; ii++ )
                 {
                     AttributeType type = registry.lookup( binaryArray[ii] );
+
                     binaries.add( type );
                 }
             }
@@ -154,20 +158,37 @@
              * human readable and those that are in the binaries set
              */
             NamingEnumeration list = entry.getIDs();
+
             while ( list.hasMore() )
             {
                 String id = ( String ) list.next();
-                AttributeType type = registry.lookup( id );
-                boolean isBinary = ! type.getSyntax().isHumanReadible();
 
-                if ( isBinary || binaries.contains( type ) )
+                AttributeType type = null;
+
+                boolean asBinary = false;
+
+                if ( registry.hasAttributeType( id ) )
+                {
+                    type = registry.lookup( id );
+                }
+
+                if ( type != null )
+                {
+                    asBinary = ! type.getSyntax().isHumanReadible();
+
+                    asBinary = asBinary || binaries.contains( type );
+                }
+
+                if ( asBinary )
                 {
                     Attribute attribute = entry.get( id );
+
                     Attribute binary = new LockableAttributeImpl( id );
 
                     for ( int ii = 0; ii < attribute.size(); ii++ )
                     {
                         Object value = attribute.get( ii );
+
                         if ( value instanceof String )
                         {
                             binary.add( ii, ( ( String ) value ).getBytes() );
@@ -179,6 +200,7 @@
                     }
 
                     entry.remove( id );
+
                     entry.put( binary );
                 }
             }

Modified: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif?view=diff&rev=148842&p1=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif&r1=148841&p2=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif&r2=148842
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif	(original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/jndi/system.ldif	Thu Jan 27 18:51:19 2005
@@ -51,3 +51,10 @@
 ou: groups
 uniquemember: uid=akarasulu,ou=users,ou=system
 
+dn: prefNodeName=sysPrefRoot,ou=system
+objectClass: top
+objectClass: prefNode
+objectClass: extensibleObject
+test: abc123
+prefNodeName: sysPrefRoot
+

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/PreferencesUtils.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/PreferencesUtils.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/PreferencesUtils.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,62 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import org.apache.ldap.common.name.LdapName;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PreferencesUtils
+{
+    /** the dn base of the system preference heirarchy */
+    static final String SYSPREF_BASE = "prefNodeName=sysPrefRoot,ou=system";
+
+
+    /**
+     * Translates an absolute system preferences node name into the distinguished
+     * name of the entry corresponding to the preferences node.
+     *
+     * @param absPrefPath the absolute path to the system preferences node
+     * @return the distinguished name of the entry representing the system preferences node
+     * @throws NamingException if there are namespace problems while translating the path
+     */
+    public static Name toSysDn( String absPrefPath ) throws NamingException
+    {
+        LdapName dn = new LdapName( SYSPREF_BASE );
+
+        String[] comps = absPrefPath.split( "/" );
+
+        for ( int ii = 0; ii < comps.length; ii++ )
+        {
+            if ( comps[ii] != null && ! comps[ii].trim().equals( "" ) )
+            {
+                dn.add( "prefNodeName=" + comps[ii] );
+            }
+        }
+
+        return dn;
+    }
+}

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerPreferencesFactory.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerPreferencesFactory.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerPreferencesFactory.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,45 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
+
+import org.apache.ldap.common.NotImplementedException;
+
+
+/**
+ * A preferences factory implementation.  Currently the userRoot() preferences
+ * are not available and will throw NotImplementedExceptions.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerPreferencesFactory implements PreferencesFactory
+{
+    public Preferences systemRoot()
+    {
+        return new ServerSystemPreferences();
+    }
+
+
+    public Preferences userRoot()
+    {
+        throw new NotImplementedException( "userRoot() in org.apache.ldap.server.prefs.ServerPreferencesFactory not implemented!" );
+    }
+}

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,352 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+
+import javax.naming.directory.*;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NameClassPair;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
+
+import org.apache.ldap.common.Lockable;
+import org.apache.ldap.common.message.LockableAttributeImpl;
+import org.apache.ldap.common.message.LockableAttributesImpl;
+import org.apache.ldap.server.jndi.ServerContextFactory;
+
+
+/**
+ * A server side system Perferences implementation.  This implementation
+ * presumes the creation of a root system preferences node in advance.  This
+ * should be included with the system.ldif that is packaged with the server.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerSystemPreferences extends AbstractPreferences
+{
+    /** an empty array of ModificationItems used to get array from list */
+    private static final ModificationItem[] EMPTY_MODS = new ModificationItem[0];
+
+    /** an empty array of Strings used to get array from list */
+    private static final String[] EMPTY_STRINGS = new String[0];
+
+    /** the LDAP context representing this preferences object */
+    private LdapContext ctx;
+
+    /** the changes (ModificationItems) representing cached alterations to preferences */
+    private ArrayList changes = new ArrayList(3);
+
+
+    /**
+     * Creates a preferences object for the system preferences root.
+     */
+    public ServerSystemPreferences()
+    {
+        super( null, "" );
+
+        super.newNode = false;
+
+        Hashtable env = new Hashtable();
+
+        env.put( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName() );
+
+        env.put( Context.PROVIDER_URL, PreferencesUtils.SYSPREF_BASE );
+
+        try
+        {
+            ctx = new InitialLdapContext( env, null );
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * Creates a preferences object using a relative name.
+     */
+    public ServerSystemPreferences( ServerSystemPreferences parent, String name )
+    {
+        super( parent, name );
+
+        LdapContext parentCtx = parent.getLdapContext();
+
+        try
+        {
+            ctx = ( LdapContext ) parentCtx.lookup( "prefNodeName=" + name );
+
+            super.newNode = false;
+        }
+        catch ( NamingException e )
+        {
+            super.newNode = true;
+        }
+
+        if ( super.newNode )
+        {
+            try
+            {
+                setUpNode( name );
+            }
+            catch ( NamingException e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Utility Methods
+    // ------------------------------------------------------------------------
+
+
+    LdapContext getLdapContext()
+    {
+        return ctx;
+    }
+
+
+    /**
+     * Sets up a new Preferences node by injecting the required information
+     * such as the node name attribute and the objectClass attribute.
+     *
+     * @param name the name of the new Preferences node.
+     */
+    private void setUpNode( String name ) throws NamingException
+    {
+        Attributes attrs = new LockableAttributesImpl();
+
+        Attribute attr = new LockableAttributeImpl( ( Lockable ) attrs, "objectClass" );
+
+        attr.add( "top" );
+
+        attr.add( "prefNode" );
+
+        attr.add( "extensibleObject" );
+
+        attrs.put( attr );
+
+        attr = new LockableAttributeImpl( ( Lockable ) attrs, "prefNodeName" );
+
+        attr.add( name );
+
+        attrs.put( attr );
+
+        LdapContext parent = ( ( ServerSystemPreferences ) parent() ).getLdapContext();
+
+        parent.bind( "prefNodeName=" + name, null, attrs );
+
+        ctx = ( LdapContext ) parent.lookup( "prefNodeName=" + name );
+
+        super.newNode = false;
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Protected SPI Methods
+    // ------------------------------------------------------------------------
+
+
+    protected void flushSpi() throws BackingStoreException
+    {
+        if ( ctx == null )
+        {
+            throw new BackingStoreException( "Ldap context not available for " + super.absolutePath() );
+        }
+
+
+        if ( changes.isEmpty() )
+        {
+            return;
+        }
+
+        try
+        {
+            ctx.modifyAttributes( "", ( ModificationItem[] ) changes.toArray( EMPTY_MODS ) );
+        }
+        catch ( NamingException e )
+        {
+            throw new BackingStoreException( e );
+        }
+
+        changes.clear();
+    }
+
+
+    protected void removeNodeSpi() throws BackingStoreException
+    {
+        try
+        {
+            ctx.destroySubcontext( "" );
+        }
+        catch ( NamingException e )
+        {
+            throw new BackingStoreException( e );
+        }
+
+        ctx = null;
+
+        changes.clear();
+    }
+
+
+    protected void syncSpi() throws BackingStoreException
+    {
+        if ( ctx == null )
+        {
+            throw new BackingStoreException( "Ldap context not available for " + super.absolutePath() );
+        }
+
+
+        if ( changes.isEmpty() )
+        {
+            return;
+        }
+
+        try
+        {
+            ctx.modifyAttributes( "", ( ModificationItem[] ) changes.toArray( EMPTY_MODS ) );
+        }
+        catch ( NamingException e )
+        {
+            throw new BackingStoreException( e );
+        }
+
+        changes.clear();
+    }
+
+
+    protected String[] childrenNamesSpi() throws BackingStoreException
+    {
+        ArrayList children = new ArrayList();
+
+        NamingEnumeration list = null;
+
+        try
+        {
+            list = ctx.list( "" );
+
+            while ( list.hasMore() )
+            {
+                NameClassPair ncp = ( NameClassPair ) list.next();
+
+                children.add( ncp.getName() );
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new BackingStoreException( e );
+        }
+
+        return ( String[] ) children.toArray( EMPTY_STRINGS );
+    }
+
+
+    protected String[] keysSpi() throws BackingStoreException
+    {
+        Attributes attrs = null;
+
+        ArrayList keys = new ArrayList();
+
+        try
+        {
+            attrs = ctx.getAttributes( "" );
+
+            NamingEnumeration ids = attrs.getIDs();
+
+            while ( ids.hasMore() )
+            {
+                String id = ( String ) ids.next();
+
+                if ( id.equals( "objectClass" ) || id.equals( "prefNodeName" ) )
+                {
+                    continue;
+                }
+
+                keys.add( id );
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new BackingStoreException( e );
+        }
+
+        return ( String[] ) keys.toArray( EMPTY_STRINGS );
+    }
+
+
+    protected void removeSpi( String key )
+    {
+        Attribute attr = new BasicAttribute( key );
+
+        ModificationItem mi = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+
+        changes.add( mi );
+    }
+
+
+    protected String getSpi( String key )
+    {
+        String value = null;
+
+        try
+        {
+            Attribute attr = ctx.getAttributes( "" ).get( key );
+
+            if ( attr == null )
+            {
+                return null;
+            }
+
+            value = ( String ) attr.get();
+        }
+        catch ( NamingException e )
+        {
+            e.printStackTrace();
+        }
+
+        return value;
+    }
+
+
+    protected void putSpi( String key, String value )
+    {
+        Attribute attr = new BasicAttribute( key );
+
+        attr.add( value );
+
+        ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+
+        changes.add( mi );
+    }
+
+
+    protected AbstractPreferences childSpi( String name )
+    {
+        return new ServerSystemPreferences( this, name );
+    }
+}

Modified: incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema?view=diff&rev=148842&p1=incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema&r1=148841&p2=incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema&r2=148842
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema	(original)
+++ incubator/directory/apacheds/trunk/core/src/main/schema/apache.schema	Thu Jan 27 18:51:19 2005
@@ -70,3 +70,15 @@
     SINGLE-VALUE
     NO-USER-MODIFICATION
     USAGE dSAOperation )
+
+attributetype ( 1.2.6.1.4.1.18060.1.1.1.3.8 NAME 'prefNodeName'
+    DESC 'Attribute to describe the name of a Java Preferences API node'
+    EQUALITY caseExactMatch
+    SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
+    SINGLE-VALUE )
+
+objectclass ( 1.2.6.1.4.1.18060.1.1.1.4.1 NAME 'prefNode'
+    SUP top
+    STRUCTURAL
+    MUST prefNodeName )
+

Modified: incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java?view=diff&rev=148842&p1=incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java&r1=148841&p2=incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java&r2=148842
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java	(original)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/jndi/AbstractJndiTest.java	Thu Jan 27 18:51:19 2005
@@ -29,7 +29,6 @@
 import junit.framework.TestCase;
 import org.apache.commons.io.FileUtils;
 import org.apache.apseda.listener.AvailablePortFinder;
-import org.apache.apseda.listener.AvailablePortFinder;
 
 
 /**
@@ -62,10 +61,12 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        doDelete( new File( "target" + File.separator + "eve" ) );
 
-        extras.put( EnvKeys.LDAP_PORT,
-                String.valueOf( AvailablePortFinder.getNextAvailable( 1024 ) ) );
+        doDelete( new File( "target" + File.separator + "apacheds" ) );
+
+        int port = AvailablePortFinder.getNextAvailable( 1024 );
+
+        extras.put( EnvKeys.LDAP_PORT, String.valueOf( port ) );
 
         setSysRoot( "uid=admin,ou=system", "secret" );
     }
@@ -127,7 +128,7 @@
         envFinal.putAll( extras );
         envFinal.putAll( env );
         envFinal.put( Context.PROVIDER_URL, "ou=system" );
-        envFinal.put( EnvKeys.WKDIR, "target" + File.separator + "eve" );
+        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 );

Added: incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/PreferencesUtilsTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/PreferencesUtilsTest.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/PreferencesUtilsTest.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,81 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import javax.naming.NamingException;
+import javax.naming.Name;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test caseses for preference utility methods.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PreferencesUtilsTest extends TestCase
+{
+    /**
+     * Tests to confirm the toSysDn() method can translate an absolute
+     * preference node path into an LDAP distinguished name.
+     *
+     * @throws NamingException if there are problems transforming the name
+     */
+    public void testToSysDn() throws NamingException
+    {
+        // simple test
+
+        String test = "/org/apache/kerberos/";
+
+        Name dn = PreferencesUtils.toSysDn( test );
+
+        assertEquals( dn.toString(), "prefNodeName=kerberos,prefNodeName=apache,prefNodeName=org," + PreferencesUtils.SYSPREF_BASE );
+
+
+
+        // simple test without trailing '/'
+
+        test = "/org/apache/kerberos";
+
+        dn = PreferencesUtils.toSysDn( test );
+
+        assertEquals( dn.toString(), "prefNodeName=kerberos,prefNodeName=apache,prefNodeName=org," + PreferencesUtils.SYSPREF_BASE );
+
+
+
+        // basis condition tests
+
+        test = "/";
+
+        dn = PreferencesUtils.toSysDn( test );
+
+        assertEquals( dn.toString(), PreferencesUtils.SYSPREF_BASE );
+
+
+
+        // endpoint tests
+
+        test = "//////";
+
+        dn = PreferencesUtils.toSysDn( test );
+
+        assertEquals( dn.toString(), PreferencesUtils.SYSPREF_BASE );
+
+    }
+}

Added: incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerPreferencesFactoryTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerPreferencesFactoryTest.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerPreferencesFactoryTest.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,55 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import java.util.Hashtable;
+import java.util.prefs.Preferences;
+import java.io.File;
+import java.io.IOException;
+import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.NamingException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+import org.apache.ldap.server.jndi.EnvKeys;
+import org.apache.ldap.server.jndi.AbstractJndiTest;
+import org.apache.apseda.listener.AvailablePortFinder;
+import org.apache.commons.io.FileUtils;
+
+
+/**
+ * Test cases for the server PreferencessFactory.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerPreferencesFactoryTest extends AbstractJndiTest
+{
+    public void testSystemRoot()
+    {
+        ServerPreferencesFactory factory = new ServerPreferencesFactory();
+
+        Preferences prefs = factory.systemRoot();
+
+        assertNotNull( prefs );
+
+        assertEquals( "abc123", prefs.get( "test", "blah" ) );
+    }
+}

Added: incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java?view=auto&rev=148842
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java	Thu Jan 27 18:51:19 2005
@@ -0,0 +1,103 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.server.prefs;
+
+
+import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;
+
+import org.apache.ldap.server.jndi.AbstractJndiTest;
+
+
+/**
+ * Tests the ServerSystemPreferences class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerSystemPreferencesTest extends AbstractJndiTest
+{
+    /**
+     * Tests to make sure the system preferences root has entry (test, abc123).
+     */
+    public void testRoot() throws BackingStoreException
+    {
+        ServerSystemPreferences prefs = new ServerSystemPreferences();
+
+        assertEquals( "abc123", prefs.get( "test", "not the value" ) );
+
+        String[] keys = prefs.keys();
+
+        assertEquals( 1, keys.length );
+
+        assertEquals( "test", keys[0] );
+    }
+
+
+    /**
+     * Tests the creation and use of a new preferences node.
+     *
+     * @throws BackingStoreException if there are failures with the store
+     */
+    public void testCreate() throws BackingStoreException
+    {
+        Preferences prefs = new ServerSystemPreferences();
+
+        Preferences testNode = prefs.node( "testNode" );
+
+        testNode.put( "testNodeKey", "testNodeValue" );
+
+        testNode.sync();
+    }
+
+
+
+
+    /**
+     * Tests the creation and use of a new preferences node.
+     *
+     * @throws BackingStoreException if there are failures with the store
+     */
+    public void testCreateAndDestroy() throws BackingStoreException
+    {
+        Preferences prefs = new ServerSystemPreferences();
+
+        Preferences testNode = prefs.node( "testNode" );
+
+        testNode.put( "testNodeKey", "testNodeValue" );
+
+        testNode.sync();
+
+        testNode.putBoolean( "boolKey", true );
+
+        testNode.putByteArray( "arrayKey", new byte[10] );
+
+        testNode.putDouble( "doubleKey", 3.14 );
+
+        testNode.putFloat( "floatKey", ( float ) 3.14 );
+
+        testNode.putInt( "intKey", 345 );
+
+        testNode.putLong( "longKey", 75449559185447L );
+
+        testNode.sync();
+
+        testNode = prefs.node( "testNode" );
+
+        assertEquals( true, testNode.getBoolean( "boolKey", false ) );
+    }
+}