directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r649872 - in /directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src: main/java/org/apache/directory/server/xdbm/search/impl/ test/java/org/apache/directory/server/xdbm/search/impl/
Date Sun, 20 Apr 2008 02:58:14 GMT
Author: akarasulu
Date: Sat Apr 19 19:58:12 2008
New Revision: 649872

URL: http://svn.apache.org/viewvc?rev=649872&view=rev
Log:
lots of code coverage for OneLevelCursor and OneLevelEvaluator

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java
      - copied, changed from r649838, directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java?rev=649872&r1=649871&r2=649872&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeCursor.java
Sat Apr 19 19:58:12 2008
@@ -38,9 +38,13 @@
  */
 public class OneLevelScopeCursor extends AbstractCursor<IndexEntry<?, Attributes>>
 {
+    /** Error message for unsupported operations */
     private static final String UNSUPPORTED_MSG =
         "Scope Cursors are not ordered and do not support positioning by element.";
 
+    /** The entry database/store */
+    private final Store<Attributes> db;
+
     /** A onelevel ScopeNode Evaluator */
     private final OneLevelScopeEvaluator evaluator;
 
@@ -66,6 +70,7 @@
      */
     public OneLevelScopeCursor( Store<Attributes> db, OneLevelScopeEvaluator evaluator
) throws Exception
     {
+        this.db = db;
         this.evaluator = evaluator;
         scopeCursor = db.getOneLevelIndex().forwardCursor( evaluator.getBaseId() );
 
@@ -144,11 +149,29 @@
             afterLast();
         }
 
-        available = cursor.previous();
-
         // if we're using the scopeCursor (1st Cursor) then return result as is
         if ( cursor == scopeCursor )
         {
+            /*
+             * If dereferencing is enabled then we must ignore alias entries, not
+             * returning them as part of the results.
+             */
+            if ( evaluator.isDereferencing() )
+            {
+                // advance until nothing is available or until we find a non-alias
+                while ( available = cursor.previous() )
+                {
+                    if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null
)
+                    {
+                        break;
+                    }
+                }
+            }
+            else
+            {
+                available = cursor.previous();
+            }
+
             return available;
         }
 
@@ -158,11 +181,21 @@
          * scopeCursor and try a previous call after positioning past it's 
          * last element.
          */
-        if ( ! available )
+        if ( ! ( available = cursor.previous() ) )
         {
             cursor = scopeCursor;
             cursor.afterLast();
-            return available = cursor.previous();
+
+            // advance until nothing is available or until we find a non-alias
+            while ( available = cursor.previous() )
+            {
+                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                {
+                    break;
+                }
+            }
+
+            return available;
         }
 
         return true;
@@ -175,10 +208,27 @@
         if ( cursor == null )
         {
             beforeFirst();
-            return scopeCursor.next();
         }
 
-        available = cursor.next();
+        /*
+         * If dereferencing is enabled then we must ignore alias entries, not
+         * returning them as part of the results.
+         */
+        if ( evaluator.isDereferencing() )
+        {
+            // advance until nothing is available or until we find a non-alias
+            while ( available = cursor.next() )
+            {
+                if ( db.getAliasIndex().reverseLookup( cursor.get().getId() ) == null )
+                {
+                    break;
+                }
+            }
+        }
+        else
+        {
+            available = cursor.next();
+        }
 
         // if we're using dereferencedCursor (2nd) then we return the result
         if ( cursor == dereferencedCursor )

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java?rev=649872&r1=649871&r2=649872&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeEvaluator.java
Sat Apr 19 19:58:12 2008
@@ -25,7 +25,6 @@
 import org.apache.directory.shared.ldap.filter.ScopeNode;
 import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.Store;
-import org.apache.directory.server.xdbm.Index;
 
 
 /**
@@ -45,11 +44,8 @@
     /** True if the scope requires alias dereferencing while searching */
     private final boolean dereferencing;
 
-    /** The one level alias index used for scope expansion */
-    private final Index<Long,E> aliasIndex;
-
-    /** The one level scope index for parent-child mappings */
-    private final Index<Long,E> scopeIndex;
+    /** the entry db storing entries */
+    private final Store<E> db;
 
 
     /**
@@ -68,11 +64,10 @@
             throw new IllegalStateException( "ScopeNode is not of onelevel scope." );
         }
 
+        this.db = db;
         baseId = db.getEntryId( node.getBaseDn() );
-        scopeIndex = db.getOneLevelIndex();
         dereferencing = node.getDerefAliases().isDerefInSearching() ||
             node.getDerefAliases().isDerefAlways();
-        aliasIndex = db.getOneAliasIndex();
     }
 
 
@@ -87,7 +82,7 @@
      */
     public boolean evaluate( IndexEntry<?,E> candidate ) throws Exception
     {
-        boolean isChild = scopeIndex.has( baseId, candidate.getId() );
+        boolean isChild = db.getOneLevelIndex().has( baseId, candidate.getId() );
 
         /*
          * The candidate id could be any entry in the db.  If search
@@ -104,7 +99,7 @@
          * candidate id is an alias, if so we reject it since aliases should
          * not be returned.
          */
-        if ( null != aliasIndex.reverseLookup( candidate.getId() ) )
+        if ( null != db.getAliasIndex().reverseLookup( candidate.getId() ) )
         {
             return false;
         }
@@ -128,7 +123,7 @@
          * the lookup returns true accepting the candidate.  Otherwise the
          * candidate is rejected with a false return because it is not in scope.
          */
-        return aliasIndex.has( baseId, candidate.getId() );
+        return db.getOneAliasIndex().has( baseId, candidate.getId() );
     }
 
 
@@ -138,12 +133,22 @@
     }
 
 
+    /**
+     * Gets the id of the search base associated with the ScopeNode expression.
+     *
+     * @return identifier of the search base
+     */
     public Long getBaseId()
     {
         return baseId;
     }
 
 
+    /**
+     * Gets whether or not dereferencing is enabled for this evaluator.
+     *
+     * @return true if dereferencing is enabled, false otherwise
+     */
     public boolean isDereferencing()
     {
         return dereferencing;

Copied: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java
(from r649838, directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java&r1=649838&r2=649872&rev=649872&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java
Sat Apr 19 19:58:12 2008
@@ -35,6 +35,8 @@
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.ScopeNode;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.After;
@@ -43,7 +45,6 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
 
 import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchControls;
@@ -53,14 +54,14 @@
 
 
 /**
- * Tests to for SubtreeScopeEvaluator and SubtreeScopeCursor.
+ * Tests to for OneLevelScopeEvaluator and OneLevelScopeCursor.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $$Rev$$
  */
-public class SubtreeScopeTest
+public class OneLevelScopeTest
 {
-    public static final Logger LOG = LoggerFactory.getLogger( SubtreeScopeTest.class );
+    public static final Logger LOG = LoggerFactory.getLogger( OneLevelScopeTest.class );
 
 
     File wkdir;
@@ -69,7 +70,7 @@
     AttributeTypeRegistry attributeRegistry;
 
 
-    public SubtreeScopeTest() throws Exception
+    public OneLevelScopeTest() throws Exception
     {
         // setup the standard registries
         BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
@@ -137,9 +138,9 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
 
         assertTrue( cursor.isElementReused() );
 
@@ -168,7 +169,7 @@
 
         // --------- Test first() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.first();
 
@@ -190,7 +191,7 @@
 
         // --------- Test afterLast() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         cursor.afterLast();
         assertFalse( cursor.available() );
 
@@ -213,7 +214,7 @@
 
         // --------- Test last() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.last();
 
@@ -235,7 +236,7 @@
 
         // --------- Test previous() before positioning ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.previous();
 
@@ -254,6 +255,175 @@
 
         assertFalse( cursor.previous() );
         assertFalse( cursor.available() );
+
+        // --------- Test next() before positioning ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.next();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 2L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 2L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testCursorNoDerefReturnAliases() throws Exception
+    {
+        ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
+            SchemaConstants.OU_AT_OID + "=engineering," +
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
+
+        assertTrue( cursor.isElementReused() );
+
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long,Attributes> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.first();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test afterLast() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.last();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test previous() before positioning ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.previous();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test next() before positioning ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.next();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 11L, ( long ) indexEntry.getId() );
+        assertEquals( 4L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
     }
 
 
@@ -262,9 +432,9 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.DEREF_IN_SEARCHING,
             SchemaConstants.OU_AT_OID + "=board of directors," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
 
         assertTrue( cursor.isElementReused() );
 
@@ -285,14 +455,22 @@
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 9L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
-        assertTrue( cursor.next() );
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.first();
+
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 10L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.next() );
@@ -305,15 +483,208 @@
         assertFalse( cursor.next() );
         assertFalse( cursor.available() );
 
+        // --------- Test afterLast() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 7L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.last();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 7L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test previous() before positioning ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.previous();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 7L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testCursorWithDereferencing2() throws Exception
+    {
+        ScopeNode node = new ScopeNode( AliasDerefMode.DEREF_IN_SEARCHING,
+            SchemaConstants.OU_AT_OID + "=apache," +
+            SchemaConstants.OU_AT_OID + "=board of directors," +
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
+
+        assertTrue( cursor.isElementReused() );
+
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long,Attributes> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
         // --------- Test first() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.first();
 
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test afterLast() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.last();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test previous() before positioning ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.previous();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 7L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testCursorWithDereferencing3() throws Exception
+    {
+        LdapDN dn = new LdapDN(
+            SchemaConstants.CN_AT_OID + "=jd," +
+            SchemaConstants.OU_AT_OID + "=board of directors," +
+            SchemaConstants.O_AT_OID  + "=good times co."
+        );
+        AttributesImpl attrs = new AttributesImpl( "objectClass", "alias", true );
+        attrs.get( "objectClass" ).add( "extensibleObject" );
+        attrs.put( "cn", "jd" );
+        attrs.put( "aliasedObjectName", "cn=Jack Daniels,ou=Engineering,o=Good Times Co."
);
+        store.add( dn, attrs );
+
+        dn = new LdapDN(
+            SchemaConstants.CN_AT_OID + "=jdoe," +
+            SchemaConstants.OU_AT_OID + "=board of directors," +
+            SchemaConstants.O_AT_OID  + "=good times co."
+        );
+        attrs = new AttributesImpl( "objectClass", "person", true );
+        attrs.put( "cn", "jdoe" );
+        attrs.put( "sn", "doe" );
+        store.add( dn, attrs );
+
+        ScopeNode node = new ScopeNode( AliasDerefMode.DEREF_IN_SEARCHING,
+            SchemaConstants.OU_AT_OID + "=board of directors," +
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
+
+        assertTrue( cursor.isElementReused() );
+
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long,Attributes> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
         assertEquals( 7L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
@@ -321,14 +692,43 @@
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 9L, ( long ) indexEntry.getId() );
+        assertEquals( 13L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        cursor = new OneLevelScopeCursor( store, evaluator );
+        assertFalse( cursor.available() );
+        cursor.first();
+
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 7L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 10L, ( long ) indexEntry.getId() );
+        assertEquals( 13L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.next() );
@@ -338,12 +738,19 @@
         assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
+        assertEquals( 3L, ( long ) indexEntry.getValue() );
+
         assertFalse( cursor.next() );
         assertFalse( cursor.available() );
 
         // --------- Test afterLast() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         cursor.afterLast();
         assertFalse( cursor.available() );
 
@@ -351,21 +758,21 @@
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 10L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 9L, ( long ) indexEntry.getId() );
+        assertEquals( 13L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
@@ -380,28 +787,28 @@
 
         // --------- Test last() ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.last();
 
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 10L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 9L, ( long ) indexEntry.getId() );
+        assertEquals( 13L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
@@ -416,28 +823,28 @@
 
         // --------- Test previous() before positioning ---------
 
-        cursor = new SubtreeScopeCursor( store, evaluator );
+        cursor = new OneLevelScopeCursor( store, evaluator );
         assertFalse( cursor.available() );
         cursor.previous();
 
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 8L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 10L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 9L, ( long ) indexEntry.getId() );
+        assertEquals( 13L, ( long ) indexEntry.getId() );
         assertEquals( 3L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
@@ -457,8 +864,8 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
 
         ForwardIndexEntry<Long,Attributes> indexEntry = new ForwardIndexEntry<Long,Attributes>();
         indexEntry.setId( 6L );
@@ -471,19 +878,28 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.DEREF_ALWAYS,
             SchemaConstants.OU_AT_OID + "=engineering," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
         assertEquals( node, evaluator.getExpression() );
 
+        /*
+         * Although immediately subordinate to the base, the OneLevelEvaluator
+         * will not accept an alias candidate because aliases are not returned
+         * when alias dereferencing while searching is enabled.
+         */
         ForwardIndexEntry<Long,Attributes> indexEntry = new ForwardIndexEntry<Long,Attributes>();
         indexEntry.setId( 11L );
-        assertTrue( evaluator.evaluate( indexEntry ) );
+        assertFalse( evaluator.evaluate( indexEntry ) );
 
         indexEntry = new ForwardIndexEntry<Long,Attributes>();
         indexEntry.setId( 8L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
         indexEntry = new ForwardIndexEntry<Long,Attributes>();
+        indexEntry.setId( 5L );
+        assertTrue( evaluator.evaluate( indexEntry ) );
+
+        indexEntry = new ForwardIndexEntry<Long,Attributes>();
         indexEntry.setId( 6L );
         assertFalse( evaluator.evaluate( indexEntry ) );
     }
@@ -494,9 +910,9 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
         cursor.get();
     }
 
@@ -506,9 +922,9 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
 
         // test before()
         ForwardIndexEntry<Long,Attributes> entry = new ForwardIndexEntry<Long,Attributes>();
@@ -522,9 +938,9 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        SubtreeScopeCursor cursor = new SubtreeScopeCursor( store, evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
+        OneLevelScopeEvaluator<Attributes> evaluator = new OneLevelScopeEvaluator<Attributes>(
store, node );
+        OneLevelScopeCursor cursor = new OneLevelScopeCursor( store, evaluator );
 
         // test after()
         ForwardIndexEntry<Long,Attributes> entry = new ForwardIndexEntry<Long,Attributes>();
@@ -538,8 +954,7 @@
     {
         ScopeNode node = new ScopeNode( AliasDerefMode.NEVER_DEREF_ALIASES,
             SchemaConstants.OU_AT_OID + "=sales," +
-            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.ONELEVEL_SCOPE
);
-        SubtreeScopeEvaluator<Attributes> evaluator = new SubtreeScopeEvaluator<Attributes>(
store, node );
-        assertNull( evaluator );
+            SchemaConstants.O_AT_OID  + "=good times co.", SearchControls.SUBTREE_SCOPE );
+        new OneLevelScopeEvaluator<Attributes>( store, node );
     }
-}
+}
\ No newline at end of file



Mime
View raw message