directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1381998 - /directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
Date Fri, 07 Sep 2012 12:41:45 GMT
Author: elecharny
Date: Fri Sep  7 12:41:45 2012
New Revision: 1381998

URL: http://svn.apache.org/viewvc?rev=1381998&view=rev
Log:
Fixed the And test to work with the new searchEngine

Modified:
    directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java

Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java?rev=1381998&r1=1381997&r2=1381998&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
(original)
+++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/AndCursorTest.java
Fri Sep  7 12:41:45 2012
@@ -26,30 +26,30 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
+import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
+import org.apache.directory.server.core.partition.impl.btree.EntryCursorAdaptor;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.StoreUtils;
 import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
 import org.apache.directory.server.xdbm.search.Evaluator;
-import org.apache.directory.server.xdbm.search.cursor.AndCursor;
-import org.apache.directory.server.xdbm.search.cursor.SubstringCursor;
-import org.apache.directory.server.xdbm.search.evaluator.PresenceEvaluator;
-import org.apache.directory.server.xdbm.search.evaluator.SubstringEvaluator;
+import org.apache.directory.server.xdbm.search.PartitionSearchResult;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
-import org.apache.directory.shared.ldap.model.filter.AndNode;
+import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.filter.ExprNode;
 import org.apache.directory.shared.ldap.model.filter.FilterParser;
-import org.apache.directory.shared.ldap.model.filter.PresenceNode;
-import org.apache.directory.shared.ldap.model.filter.SubstringNode;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schemaextractor.SchemaLdifExtractor;
@@ -173,6 +173,34 @@ public class AndCursorTest
     }
 
 
+    private Cursor<Entry> buildCursor( ExprNode root ) throws Exception
+    {
+        Evaluator<? extends ExprNode> evaluator = evaluatorBuilder.build( root );
+
+        PartitionSearchResult searchResult = new PartitionSearchResult();
+        Set<IndexEntry<String, String>> resultSet = new HashSet<IndexEntry<String,
String>>();
+
+        Set<String> uuids = new HashSet<String>();
+
+        long candidates = cursorBuilder.build( root, uuids );
+
+        for ( String uuid : uuids )
+        {
+            ForwardIndexEntry<String, String> indexEntry = new ForwardIndexEntry<String,
String>();
+            indexEntry.setId( uuid );
+            resultSet.add( indexEntry );
+        }
+
+        searchResult.setResultSet( resultSet );
+        searchResult.setEvaluator( evaluator );
+
+        SearchingOperationContext operationContext = new SearchOperationContext( null );
+
+        return new BaseEntryFilteringCursor( new EntryCursorAdaptor( ( AbstractBTreePartition
) store, searchResult ),
+            operationContext );
+    }
+
+
     @Test
     public void testAndCursorWithCursorBuilder() throws Exception
     {
@@ -180,24 +208,27 @@ public class AndCursorTest
 
         ExprNode exprNode = FilterParser.parse( schemaManager, filter );
 
-        Cursor<IndexEntry<?, String>> cursor = cursorBuilder.build( exprNode
);
+        Cursor<Entry> cursor = buildCursor( exprNode );
 
         cursor.beforeFirst();
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 8 ), cursor.get().getId() );
-        assertEquals( "jack daniels", cursor.get().getKey() );
+        Entry entry = cursor.get();
+        assertEquals( Strings.getUUID( 5 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JOhnny WAlkeR", entry.get( "cn" ).getString() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 6 ), cursor.get().getId() );
-        assertEquals( "jim bean", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 6 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JIM BEAN", entry.get( "cn" ).getString() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 5 ), cursor.get().getId() );
-        assertEquals( "johnny walker", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 8 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "Jack Daniels", entry.get( "cn" ).getString() );
 
         assertFalse( cursor.next() );
         assertFalse( cursor.available() );
@@ -210,47 +241,31 @@ public class AndCursorTest
     @Test
     public void testAndCursorWithManualFilter() throws Exception
     {
-        AndNode andNode = new AndNode();
-
-        List<Evaluator<? extends ExprNode>> evaluators = new ArrayList<Evaluator<?
extends ExprNode>>();
-        Evaluator<? extends ExprNode> eval;
-
-        ExprNode exprNode = new SubstringNode( schemaManager.getAttributeType( "cn" ), "J",
null );
-        eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, schemaManager );
-        Cursor<IndexEntry<String, String>> wrapped = new SubstringCursor( store,
( SubstringEvaluator ) eval );
-
-        /* adding this results in NPE  adding Presence evaluator not 
-         Substring evaluator but adding Substring cursor as wrapped cursor */
-        // evaluators.add( eval ); 
-
-        andNode.addNode( exprNode );
+        ExprNode exprNode = FilterParser.parse( schemaManager, "(&(cn=J*)(sn=*))" );
 
-        exprNode = new PresenceNode( schemaManager.getAttributeType( "sn" ) );
-        eval = new PresenceEvaluator( ( PresenceNode ) exprNode, store, schemaManager );
-        evaluators.add( eval );
-
-        andNode.addNode( exprNode );
-
-        Cursor<IndexEntry<?, Long>> cursor = new AndCursor( wrapped, evaluators
); //cursorBuilder.build( andNode );
+        Cursor<Entry> cursor = buildCursor( exprNode );
 
         cursor.beforeFirst();
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 8 ), cursor.get().getId() );
-        assertEquals( "jack daniels", cursor.get().getKey() );
+        Entry entry = cursor.get();
+        assertEquals( Strings.getUUID( 5 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JOhnny WAlkeR", entry.get( "cn" ).getString() );
 
         cursor.first();
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 6 ), cursor.get().getId() );
-        assertEquals( "jim bean", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 6 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JIM BEAN", entry.get( "cn" ).getString() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 5 ), cursor.get().getId() );
-        assertEquals( "johnny walker", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 8 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "Jack Daniels", entry.get( "cn" ).getString() );
 
         assertFalse( cursor.next() );
         assertFalse( cursor.available() );
@@ -259,20 +274,23 @@ public class AndCursorTest
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 5 ), cursor.get().getId() );
-        assertEquals( "johnny walker", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 8 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "Jack Daniels", entry.get( "cn" ).getString() );
 
         cursor.last();
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 6 ), cursor.get().getId() );
-        assertEquals( "jim bean", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 6 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JIM BEAN", entry.get( "cn" ).getString() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
-        assertEquals( Strings.getUUID( 8 ), cursor.get().getId() );
-        assertEquals( "jack daniels", cursor.get().getKey() );
+        entry = cursor.get();
+        assertEquals( Strings.getUUID( 5 ), entry.get( "entryUUID" ).getString() );
+        assertEquals( "JOhnny WAlkeR", entry.get( "cn" ).getString() );
 
         assertFalse( cursor.previous() );
         assertFalse( cursor.available() );
@@ -286,26 +304,7 @@ public class AndCursorTest
         {
         }
 
-        try
-        {
-            cursor.after( new ForwardIndexEntry() );
-            fail( "should fail with UnsupportedOperationException " );
-        }
-        catch ( UnsupportedOperationException uoe )
-        {
-        }
-
-        try
-        {
-            cursor.before( new ForwardIndexEntry() );
-            fail( "should fail with UnsupportedOperationException " );
-        }
-        catch ( UnsupportedOperationException uoe )
-        {
-        }
-
         cursor.close();
-        wrapped.close();
+        assertTrue( cursor.isClosed() );
     }
-
 }



Mime
View raw message