directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r148916 - in incubator/directory/apacheds/trunk/core: . src/main/java/org/apache/ldap/server/prefs src/test/org/apache/ldap/server/prefs
Date Fri, 28 Jan 2005 19:49:37 GMT
Author: akarasulu
Date: Fri Jan 28 11:49:36 2005
New Revision: 148916

URL: http://svn.apache.org/viewcvs?view=rev&rev=148916
Log:
checking in with one test still failing
Added:
   incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/package.html
Modified:
   incubator/directory/apacheds/trunk/core/project.properties
   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/ServerSystemPreferencesTest.java

Modified: incubator/directory/apacheds/trunk/core/project.properties
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/project.properties?view=diff&rev=148916&p1=incubator/directory/apacheds/trunk/core/project.properties&r1=148915&p2=incubator/directory/apacheds/trunk/core/project.properties&r2=148916
==============================================================================
--- incubator/directory/apacheds/trunk/core/project.properties	(original)
+++ incubator/directory/apacheds/trunk/core/project.properties	Fri Jan 28 11:49:36 2005
@@ -31,3 +31,6 @@
 maven.ldap.server.schema.deps.dhcp=system,core
 
 maven.license.licenseFile=${basedir}/../LICENSE.txt
+
+maven.junit.sysproperties=java.util.prefs.PreferencesFactory
+java.util.prefs.PreferencesFactory=org.apache.ldap.server.prefs.ServerPreferencesFactory

Modified: 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=diff&rev=148916&p1=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java&r1=148915&p2=incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java&r2=148916
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java
(original)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/ServerSystemPreferences.java
Fri Jan 28 11:49:36 2005
@@ -19,6 +19,8 @@
 
 import java.util.Hashtable;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.prefs.AbstractPreferences;
 import java.util.prefs.BackingStoreException;
 
@@ -58,6 +60,9 @@
     /** the changes (ModificationItems) representing cached alterations to preferences */
     private ArrayList changes = new ArrayList(3);
 
+    /** maps changes based on key: key->list of mods (on same key) */
+    private HashMap keyToChange = new HashMap(3);
+
 
     /**
      * Creates a preferences object for the system preferences root.
@@ -194,6 +199,8 @@
         }
 
         changes.clear();
+
+        keyToChange.clear();
     }
 
 
@@ -211,6 +218,8 @@
         ctx = null;
 
         changes.clear();
+
+        keyToChange.clear();
     }
 
 
@@ -237,6 +246,8 @@
         }
 
         changes.clear();
+
+        keyToChange.clear();
     }
 
 
@@ -305,7 +316,30 @@
 
         ModificationItem mi = new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
 
+        addDelta( mi );
+    }
+
+
+    private void addDelta( ModificationItem mi )
+    {
+        String key = mi.getAttribute().getID();
+
+        List deltas = null;
+
         changes.add( mi );
+
+        if ( keyToChange.containsKey( key ) )
+        {
+            deltas = ( List ) keyToChange.get( key );
+        }
+        else
+        {
+            deltas = new ArrayList();
+        }
+
+        deltas.add( mi );
+
+        keyToChange.put( key, deltas );
     }
 
 
@@ -317,6 +351,25 @@
         {
             Attribute attr = ctx.getAttributes( "" ).get( key );
 
+            if ( keyToChange.containsKey( key ) )
+            {
+                List mods = ( List ) keyToChange.get( key );
+
+                for ( int ii = 0; ii < mods.size(); ii++ )
+                {
+                    ModificationItem mi = ( ModificationItem ) mods.get( ii );
+
+                    if ( mi.getModificationOp() == DirContext.REMOVE_ATTRIBUTE )
+                    {
+                        attr = null;
+                    }
+                    else
+                    {
+                        attr = mi.getAttribute();
+                    }
+                }
+            }
+
             if ( attr == null )
             {
                 return null;
@@ -341,7 +394,7 @@
 
         ModificationItem mi = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
 
-        changes.add( mi );
+        addDelta( mi );
     }
 
 

Added: incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/package.html
Url: http://svn.apache.org/viewcvs/incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/package.html?view=auto&rev=148916
==============================================================================
--- (empty file)
+++ incubator/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/prefs/package.html
Fri Jan 28 11:49:36 2005
@@ -0,0 +1,10 @@
+Platform independent server side Preferences implementation based on ApacheDS.
+The data is backed by the directory using a specific LDAP schema to map
+preferences to the LDAP/X.500 namespace.  To make sure you're preferences are
+using the right preferences factory implementation please check to see the
+following property is set to our implementation:
+
+java.util.prefs.PreferencesFactory=org.apache.ldap.server.prefs.ServerPreferencesFactory
+
+
+

Modified: 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=diff&rev=148916&p1=incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java&r1=148915&p2=incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java&r2=148916
==============================================================================
--- incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java
(original)
+++ incubator/directory/apacheds/trunk/core/src/test/org/apache/ldap/server/prefs/ServerSystemPreferencesTest.java
Fri Jan 28 11:49:36 2005
@@ -65,6 +65,47 @@
     }
 
 
+    /**
+     * Tests the creation and use of a new preferences node.
+     *
+     * @throws BackingStoreException if there are failures with the store
+     */
+    public void testCreateAndSet() 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 ) );
+
+        assertTrue( 3.14 == testNode.getDouble( "doubleKey", 9.20 ) );
+
+        assertTrue( (float) 3.14 == testNode.getFloat( "floatKey", (float) 3.90 ) );
+
+        assertEquals( 345, testNode.getInt( "intKey", 87 ) );
+
+        assertEquals( 75449559185447L, testNode.getLong( "longKey", 75449547L ) );
+    }
 
 
     /**
@@ -72,7 +113,7 @@
      *
      * @throws BackingStoreException if there are failures with the store
      */
-    public void testCreateAndDestroy() throws BackingStoreException
+    public void testCreateAndRemove() throws BackingStoreException
     {
         Preferences prefs = new ServerSystemPreferences();
 
@@ -99,5 +140,52 @@
         testNode = prefs.node( "testNode" );
 
         assertEquals( true, testNode.getBoolean( "boolKey", false ) );
+
+        assertTrue( 3.14 == testNode.getDouble( "doubleKey", 9.20 ) );
+
+        assertTrue( (float) 3.14 == testNode.getFloat( "floatKey", (float) 3.90 ) );
+
+        assertEquals( 345, testNode.getInt( "intKey", 87 ) );
+
+        assertEquals( 75449559185447L, testNode.getLong( "longKey", 75449547L ) );
+
+        testNode.remove( "doubleKey" );
+
+        testNode.remove( "arrayKey" );
+
+        assertEquals( "no value", testNode.get( "doubleKey", "no value" ) );
+
+        assertEquals( "no value", testNode.get( "arrayKey", "no value" ) );
+
+        testNode.sync();
+
+        assertEquals( "no value", testNode.get( "doubleKey", "no value" ) );
+
+        assertEquals( "no value", testNode.get( "arrayKey", "no value" ) );
+    }
+
+
+    /**
+     * Checks to see that setting the system property utilized the right factory
+     * implementation to generate ServerSystemPreferences.
+     */
+    public void testForFactoryUse()
+    {
+        String fqcn = ServerPreferencesFactory.class.getName();
+
+        System.setProperty( "java.util.prefs.PreferencesFactory", fqcn );
+
+        Preferences prefs = Preferences.systemRoot();
+
+        assertEquals( ServerSystemPreferences.class, prefs.getClass() );
+    }
+
+
+    /**
+     * Requests a deep node from the preferences API after setting the
+     */
+    public void testNewDeepNode()
+    {
+
     }
 }

Mime
View raw message