directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r1158430 [2/2] - in /directory/apacheds/branches/one-sub-level-index-removal: core-constants/src/main/java/org/apache/directory/server/constants/ jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ ldif-...
Date Tue, 16 Aug 2011 19:56:05 GMT
Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java Tue Aug 16 19:56:04 2011
@@ -26,21 +26,15 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
-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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.csn.CsnFactory;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
@@ -53,20 +47,9 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
-import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.comparators.StringComparator;
 import org.apache.directory.shared.ldap.model.schema.parsers.SyntaxCheckerDescription;
-import org.apache.directory.shared.ldap.schemaextractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -74,96 +57,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class LessEqTest
+public class LessEqTest extends TestBase
 {
-    public static final Logger LOG = LoggerFactory.getLogger( LessEqTest.class );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        // setup the standard registries
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = AndCursorTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
-
-
-    @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( false );
-
-        store.addIndex( new AvlIndex( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.CN_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.POSTALCODE_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
-    }
-
 
     @Test
     public void testCursorIndexed() throws Exception

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java Tue Aug 16 19:56:04 2011
@@ -25,40 +25,21 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexCursor;
-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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
 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.NotNode;
 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.model.schema.syntaxCheckers.UuidSyntaxChecker;
-import org.apache.directory.shared.ldap.schemaextractor.SchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -67,102 +48,19 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class NotCursorTest
+public class NotCursorTest extends TestBase
 {
-    private static final Logger LOG = LoggerFactory.getLogger( NotCursorTest.class.getSimpleName() );
-
     UuidSyntaxChecker uuidSynChecker = new UuidSyntaxChecker();
 
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-    EvaluatorBuilder evaluatorBuilder;
-    CursorBuilder cursorBuilder;
-
-
-    @BeforeClass
-    static public void setup() throws Exception
-    {
-        // setup the standard registries
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = NotCursorTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
+    EvaluatorBuilder<Long> evaluatorBuilder;
+    CursorBuilder<Long> cursorBuilder;
 
 
     @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( false );
-
-        store.addIndex( new AvlIndex( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.CN_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-        
-        StoreUtils.loadExampleData( store, schemaManager );
-
-        evaluatorBuilder = new EvaluatorBuilder( store, schemaManager );
-        cursorBuilder = new CursorBuilder( store, evaluatorBuilder );
-
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
+    public void createBuilders() throws Exception
     {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
+        evaluatorBuilder = new EvaluatorBuilder<Long>( store, schemaManager );
+        cursorBuilder = new CursorBuilder<Long>( store, evaluatorBuilder );
     }
 
 

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java Tue Aug 16 19:56:04 2011
@@ -24,20 +24,13 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.UUID;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.csn.CsnFactory;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
@@ -47,18 +40,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 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;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -66,95 +48,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class OneLevelScopeTest
+public class OneLevelScopeTest extends TestBase
 {
-    public static final Logger LOG = LoggerFactory.getLogger( OneLevelScopeTest.class );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        // setup the standard registries
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = OneLevelScopeTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
-
-
-    @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( true );
-
-        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.CN_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
-    }
-
 
     @Test
     public void testCursorNoDeref() throws Exception
@@ -174,14 +69,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         IndexEntry<Long, Entry, Long> indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( 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( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.next() );
@@ -196,14 +91,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( 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( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.next() );
@@ -219,14 +114,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.previous() );
@@ -241,14 +136,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.previous() );
@@ -263,14 +158,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.previous() );
@@ -285,14 +180,14 @@ public class OneLevelScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( 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( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.next() );

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java Tue Aug 16 19:56:04 2011
@@ -25,21 +25,13 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.xdbm.IndexCursor;
 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.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.entry.Entry;
@@ -47,19 +39,8 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.filter.FilterParser;
 import org.apache.directory.shared.ldap.model.filter.OrNode;
 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;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -72,98 +53,17 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class OrCursorTest
+public class OrCursorTest extends TestBase
 {
-    private static final Logger LOG = LoggerFactory.getLogger( OrCursorTest.class.getSimpleName() );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-    EvaluatorBuilder evaluatorBuilder;
-    CursorBuilder cursorBuilder;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = OrCursorTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
+    EvaluatorBuilder<Long> evaluatorBuilder;
+    CursorBuilder<Long> cursorBuilder;
 
 
     @Before
-    public void createStore() throws Exception
+    public void createBuilder() throws Exception
     {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( false );
-
-        store.addIndex( new AvlIndex( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.CN_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-
-        evaluatorBuilder = new EvaluatorBuilder( store, schemaManager );
-        cursorBuilder = new CursorBuilder( store, evaluatorBuilder );
-
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
+        evaluatorBuilder = new EvaluatorBuilder<Long>( store, schemaManager );
+        cursorBuilder = new CursorBuilder<Long>( store, evaluatorBuilder );
     }
 
 

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java Tue Aug 16 19:56:04 2011
@@ -23,38 +23,18 @@ package org.apache.directory.server.xdbm
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
-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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.filter.PresenceNode;
-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;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -62,95 +42,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class PresenceTest
+public class PresenceTest extends TestBase
 {
-    private static final Logger LOG = LoggerFactory.getLogger( PresenceTest.class.getSimpleName() );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = PresenceTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
-
-
-    @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( false );
-
-        store.addIndex( new AvlIndex( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.CN_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-        
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
-    }
-
 
     @Test
     public void testIndexedServerEntry() throws Exception

Added: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexHelperTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexHelperTest.java?rev=1158430&view=auto
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexHelperTest.java (added)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexHelperTest.java Tue Aug 16 19:56:04 2011
@@ -0,0 +1,147 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.server.xdbm.search.impl;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.junit.Test;
+
+
+/**
+ * Tests {@link RdnIndexHelper}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class RdnIndexHelperTest extends TestBase
+{
+
+    @Test
+    public void test_isDirectDescendantOf_directDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertTrue( helper.isDirectDescendantOf( 0L, 1L ) );
+        assertTrue( helper.isDirectDescendantOf( 1L, 3L ) );
+        assertTrue( helper.isDirectDescendantOf( 3L, 7L ) );
+        assertTrue( helper.isDirectDescendantOf( 7L, 9L ) );
+    }
+
+
+    @Test
+    public void test_isDirectDescendantOf_indirectDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDirectDescendantOf( 0L, 3L ) );
+        assertFalse( helper.isDirectDescendantOf( 0L, 7L ) );
+        assertFalse( helper.isDirectDescendantOf( 0L, 9L ) );
+        assertFalse( helper.isDirectDescendantOf( 1L, 7L ) );
+        assertFalse( helper.isDirectDescendantOf( 1L, 9L ) );
+        assertFalse( helper.isDirectDescendantOf( 3L, 9L ) );
+    }
+
+
+    @Test
+    public void test_isDirectDescendantOf_same() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDirectDescendantOf( 0L, 0L ) );
+        assertFalse( helper.isDirectDescendantOf( 1L, 1L ) );
+    }
+
+
+    @Test
+    public void test_isDirectDescendantOf_noDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDirectDescendantOf( 3L, 4L ) );
+        assertFalse( helper.isDirectDescendantOf( 10L, 11L ) );
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void test_isDirectDescendantOf_nonExistingIds() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDirectDescendantOf( -99L, -999L ) );
+    }
+
+
+    @Test
+    public void test_isDescendantOf_directDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertTrue( helper.isDescendantOf( 0L, 1L ) );
+        assertTrue( helper.isDescendantOf( 1L, 3L ) );
+        assertTrue( helper.isDescendantOf( 3L, 7L ) );
+        assertTrue( helper.isDescendantOf( 7L, 9L ) );
+    }
+
+
+    @Test
+    public void test_isDescendantOf_indirectDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertTrue( helper.isDescendantOf( 0L, 3L ) );
+        assertTrue( helper.isDescendantOf( 0L, 7L ) );
+        assertTrue( helper.isDescendantOf( 0L, 9L ) );
+        assertTrue( helper.isDescendantOf( 1L, 7L ) );
+        assertTrue( helper.isDescendantOf( 1L, 9L ) );
+        assertTrue( helper.isDescendantOf( 3L, 9L ) );
+    }
+
+
+    @Test
+    public void test_isDescendantOf_same() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDescendantOf( 0L, 0L ) );
+        assertFalse( helper.isDescendantOf( 1L, 1L ) );
+    }
+
+
+    @Test
+    public void test_isDescendantOf_noDescendants() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDescendantOf( 3L, 4L ) );
+        assertFalse( helper.isDescendantOf( 10L, 11L ) );
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void test_isDescendantOf_nonExistingIds() throws Exception
+    {
+        RdnIndexHelper<Entry, Long> helper = new RdnIndexHelper<Entry, Long>( store.getRdnIndex(), store.getRootId() );
+
+        assertFalse( helper.isDescendantOf( -99L, -999L ) );
+    }
+
+}
\ No newline at end of file

Added: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexTreeCursorTest.java?rev=1158430&view=auto
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexTreeCursorTest.java (added)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/RdnIndexTreeCursorTest.java Tue Aug 16 19:56:04 2011
@@ -0,0 +1,289 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.server.xdbm.search.impl;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.junit.Test;
+
+
+/**
+ * Tests {@link RdnIndexTreeCursor}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class RdnIndexTreeCursorTest extends TestBase
+{
+
+    // This is how the test data looks like
+    //   ForwardIndexEntry[ ParentIdAndRdn<0, 'o=Good Times Co.'>, 1 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<1, 'ou=Board of Directors'>, 3 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<1, 'ou=Engineering'>, 4 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<1, 'ou=Sales'>, 2 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<2, 'cn=JIM BEAN'>, 6 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<2, 'cn=JOhnny WAlkeR'>, 5 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<3, 'ou=Apache'>, 7 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<3, 'commonName=Jim Bean'>, 10 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<4, 'cn=Jack Daniels'>, 8 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<4, '2.5.4.3=Johnny Walker'>, 11 ]
+    //   ForwardIndexEntry[ ParentIdAndRdn<7, 'commonName=Jim Bean'>, 9 ]
+
+    @Test
+    public void testOneLevelFromContextEntry() throws Exception
+    {
+        IndexCursor<Long, Entry, Long> cursor = store.getRdnIndexHelper().getOneLevelScopeCursor( 1L );
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertHasNext( cursor, 1L, 3L );
+
+        assertHasNext( cursor, 1L, 4L );
+
+        assertHasNext( cursor, 1L, 2L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        assertHasFirst( cursor, 1L, 3L );
+
+        assertHasNext( cursor, 1L, 4L );
+
+        assertHasNext( cursor, 1L, 2L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test afterLast() ---------
+
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertHasPrevious( cursor, 1L, 2L );
+
+        assertHasPrevious( cursor, 1L, 4L );
+
+        assertHasPrevious( cursor, 1L, 3L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        assertHasLast( cursor, 1L, 2L );
+
+        assertHasPrevious( cursor, 1L, 4L );
+
+        assertHasPrevious( cursor, 1L, 3L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testOneLevelFromApache() throws Exception
+    {
+        IndexCursor<Long, Entry, Long> cursor = store.getRdnIndexHelper().getOneLevelScopeCursor( 7L );
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertHasNext( cursor, 7L, 9L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        assertHasFirst( cursor, 7L, 9L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test afterLast() ---------
+
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertHasPrevious( cursor, 7L, 9L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        assertHasLast( cursor, 7L, 9L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testSubLevelFromContextEntry() throws Exception
+    {
+        IndexCursor<Long, Entry, Long> cursor = store.getRdnIndexHelper().getSubLevelScopeCursor( 1L );
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertHasNext( cursor, 1L, 1L );
+        assertHasNext( cursor, 1L, 3L );
+        assertHasNext( cursor, 1L, 7L );
+        assertHasNext( cursor, 1L, 9L );
+        assertHasNext( cursor, 1L, 10L );
+        assertHasNext( cursor, 1L, 4L );
+        assertHasNext( cursor, 1L, 8L );
+        assertHasNext( cursor, 1L, 11L );
+        assertHasNext( cursor, 1L, 2L );
+        assertHasNext( cursor, 1L, 6L );
+        assertHasNext( cursor, 1L, 5L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        assertHasFirst( cursor, 1L, 1L );
+
+        // --------- Test afterLast() ---------
+
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertHasPrevious( cursor, 1L, 5L );
+        assertHasPrevious( cursor, 1L, 6L );
+        assertHasPrevious( cursor, 1L, 2L );
+        assertHasPrevious( cursor, 1L, 11L );
+        assertHasPrevious( cursor, 1L, 8L );
+        assertHasPrevious( cursor, 1L, 4L );
+        assertHasPrevious( cursor, 1L, 10L );
+        assertHasPrevious( cursor, 1L, 9L );
+        assertHasPrevious( cursor, 1L, 7L );
+        assertHasPrevious( cursor, 1L, 3L );
+        assertHasPrevious( cursor, 1L, 1L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        assertHasLast( cursor, 1L, 5L );
+    }
+
+
+    @Test
+    public void testSubLevelFromApache() throws Exception
+    {
+        IndexCursor<Long, Entry, Long> cursor = store.getRdnIndexHelper().getSubLevelScopeCursor( 7L );
+
+        // --------- Test beforeFirst() ---------
+
+        cursor.beforeFirst();
+        assertFalse( cursor.available() );
+
+        assertHasNext( cursor, 7L, 7L );
+        assertHasNext( cursor, 7L, 9L );
+
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+
+        // --------- Test first() ---------
+
+        assertHasFirst( cursor, 7L, 7L );
+
+        // --------- Test afterLast() ---------
+
+        cursor.afterLast();
+        assertFalse( cursor.available() );
+
+        assertHasPrevious( cursor, 7L, 9L );
+        assertHasPrevious( cursor, 7L, 7L );
+
+        assertFalse( cursor.previous() );
+        assertFalse( cursor.available() );
+
+        // --------- Test last() ---------
+
+        assertHasLast( cursor, 7L, 9L );
+
+    }
+
+
+    private void assertHasNext( IndexCursor<Long, Entry, Long> cursor, Long value, Long id ) throws Exception
+    {
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long, Entry, Long> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( value, indexEntry.getValue() );
+        assertEquals( id, indexEntry.getId() );
+    }
+
+
+    private void assertHasPrevious( IndexCursor<Long, Entry, Long> cursor, Long value, Long id ) throws Exception
+    {
+        assertTrue( cursor.previous() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long, Entry, Long> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( value, indexEntry.getValue() );
+        assertEquals( id, indexEntry.getId() );
+    }
+
+
+    private void assertHasFirst( IndexCursor<Long, Entry, Long> cursor, Long value, Long id ) throws Exception
+    {
+        assertTrue( cursor.first() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long, Entry, Long> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( value, indexEntry.getValue() );
+        assertEquals( id, indexEntry.getId() );
+    }
+
+
+    private void assertHasLast( IndexCursor<Long, Entry, Long> cursor, Long value, Long id ) throws Exception
+    {
+        assertTrue( cursor.last() );
+        assertTrue( cursor.available() );
+        IndexEntry<Long, Entry, Long> indexEntry = cursor.get();
+        assertNotNull( indexEntry );
+        assertEquals( value, indexEntry.getValue() );
+        assertEquals( id, indexEntry.getId() );
+    }
+
+}
\ No newline at end of file

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java Tue Aug 16 19:56:04 2011
@@ -23,34 +23,13 @@ package org.apache.directory.server.xdbm
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.io.File;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
-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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 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;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -58,96 +37,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SubstringTest
+public class SubstringTest extends TestBase
 {
-    private static final Logger LOG = LoggerFactory.getLogger( SubstringTest.class.getSimpleName() );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = SubstringTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
-
-
-    @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( false );
-
-        store.addIndex( new AvlIndex( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex( SchemaConstants.CN_AT_OID ) );
-        
-        Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." );
-        ((Partition)store).setSuffixDn( suffixDn );
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-        
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destroyStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
-    }
-
 
     @Test
     public void testIndexedCnStartsWithJ() throws Exception

Modified: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java?rev=1158430&r1=1158429&r2=1158430&view=diff
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java (original)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/SubtreeScopeTest.java Tue Aug 16 19:56:04 2011
@@ -25,20 +25,13 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.UUID;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 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.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.csn.CsnFactory;
 import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
@@ -48,18 +41,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.model.message.SearchScope;
 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;
-import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
-import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
-import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
-import org.apache.directory.shared.util.exception.Exceptions;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -67,95 +49,8 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SubtreeScopeTest
+public class SubtreeScopeTest extends TestBase
 {
-    public static final Logger LOG = LoggerFactory.getLogger( SubtreeScopeTest.class );
-
-    File wkdir;
-    Store<Entry, Long> store;
-    static SchemaManager schemaManager = null;
-
-
-    @BeforeClass
-    public static void setup() throws Exception
-    {
-        String workingDirectory = System.getProperty( "workingDirectory" );
-
-        if ( workingDirectory == null )
-        {
-            String path = SubtreeScopeTest.class.getResource( "" ).getPath();
-            int targetPos = path.indexOf( "target" );
-            workingDirectory = path.substring( 0, targetPos + 6 );
-        }
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
-        extractor.extractOrCopy( true );
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        schemaManager = new DefaultSchemaManager( loader );
-
-        boolean loaded = schemaManager.loadAllEnabled();
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-
-        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
-
-        if ( !loaded )
-        {
-            fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
-        }
-    }
-
-
-    @Before
-    public void createStore() throws Exception
-    {
-        // setup the working directory for the store
-        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
-        wkdir.delete();
-        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
-        wkdir.mkdirs();
-
-        // initialize the store
-        store = new AvlPartition( schemaManager );
-        ((Partition)store).setId( "example" );
-        store.setCacheSize( 10 );
-        store.setPartitionPath( wkdir.toURI() );
-        store.setSyncOnWrite( true );
-
-        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.OU_AT_OID ) );
-        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.CN_AT_OID ) );
-        ((Partition)store).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
-        ((Partition)store).initialize();
-
-        ((Partition)store).initialize();
-
-        StoreUtils.loadExampleData( store, schemaManager );
-        
-        LOG.debug( "Created new store" );
-    }
-
-
-    @After
-    public void destryStore() throws Exception
-    {
-        if ( store != null )
-        {
-            ((Partition)store).destroy();
-        }
-
-        store = null;
-        if ( wkdir != null )
-        {
-            FileUtils.deleteDirectory( wkdir );
-        }
-
-        wkdir = null;
-    }
-
 
     @Test
     public void testCursorNoDeref() throws Exception
@@ -181,14 +76,14 @@ public class SubtreeScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( 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( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.next() );
@@ -210,14 +105,14 @@ public class SubtreeScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( 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( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertFalse( cursor.next() );
@@ -233,14 +128,14 @@ public class SubtreeScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
@@ -262,14 +157,14 @@ public class SubtreeScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
@@ -291,14 +186,14 @@ public class SubtreeScopeTest
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 6L, ( long ) indexEntry.getId() );
+        assertEquals( 5L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         indexEntry = cursor.get();
         assertNotNull( indexEntry );
-        assertEquals( 5L, ( long ) indexEntry.getId() );
+        assertEquals( 6L, ( long ) indexEntry.getId() );
         assertEquals( 2L, ( long ) indexEntry.getValue() );
 
         assertTrue( cursor.previous() );

Added: directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/TestBase.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/TestBase.java?rev=1158430&view=auto
==============================================================================
--- directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/TestBase.java (added)
+++ directory/apacheds/branches/one-sub-level-index-removal/xdbm-partition/src/test/java/org/apache/directory/server/xdbm/search/impl/TestBase.java Tue Aug 16 19:56:04 2011
@@ -0,0 +1,139 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.server.xdbm.search.impl;
+
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
+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.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+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;
+import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.util.exception.Exceptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+
+/**
+ * Base test class to setup and teardown the store.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class TestBase
+{
+    protected File wkdir;
+    protected Store<Entry, Long> store;
+    protected static SchemaManager schemaManager = null;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        // setup the standard registries
+        String workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = TestBase.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+
+        File schemaRepository = new File( workingDirectory, "schema" );
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+        extractor.extractOrCopy( true );
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        schemaManager = new DefaultSchemaManager( loader );
+
+        boolean loaded = schemaManager.loadAllEnabled();
+
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + Exceptions.printErrors( schemaManager.getErrors() ) );
+        }
+
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + Exceptions.printErrors( schemaManager.getErrors() ) );
+        }
+    }
+
+
+    @Before
+    public void createStore() throws Exception
+    {
+        // setup the working directory for the store
+        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
+        wkdir.delete();
+        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
+        wkdir.mkdirs();
+
+        // initialize the store
+        store = new AvlPartition( schemaManager );
+        ( ( Partition ) store ).setId( "example" );
+        store.setCacheSize( 10 );
+        store.setPartitionPath( wkdir.toURI() );
+        store.setSyncOnWrite( true );
+
+        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.OU_AT_OID ) );
+        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.CN_AT_OID ) );
+        store.addIndex( new AvlIndex<String, Entry>( SchemaConstants.POSTALCODE_AT_OID ) );
+        ( ( Partition ) store ).setSuffixDn( new Dn( schemaManager, "o=Good Times Co." ) );
+        ( ( Partition ) store ).initialize();
+
+        ( ( Partition ) store ).initialize();
+
+        StoreUtils.loadExampleData( store, schemaManager );
+    }
+
+
+    @After
+    public void destroyStore() throws Exception
+    {
+        if ( store != null )
+        {
+            ( ( Partition ) store ).destroy();
+        }
+
+        store = null;
+        if ( wkdir != null )
+        {
+            FileUtils.deleteDirectory( wkdir );
+        }
+
+        wkdir = null;
+    }
+
+}
\ No newline at end of file



Mime
View raw message