directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r896599 [29/30] - in /directory/apacheds/trunk: ./ avl-partition/ avl-partition/src/ avl-partition/src/main/ avl-partition/src/main/java/ avl-partition/src/main/java/org/ avl-partition/src/main/java/org/apache/ avl-partition/src/main/java/o...
Date Wed, 06 Jan 2010 18:27:19 GMT
Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/LessEqTest.java Wed Jan  6 18:26:43 2010
@@ -20,51 +20,49 @@
 package org.apache.directory.server.xdbm.search.impl;
 
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.directory.server.xdbm.Store;
-import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.tools.StoreUtils;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
-import org.apache.directory.server.core.entry.ServerEntry;
+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 static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.entry.ServerStringValue;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.tools.StoreUtils;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.filter.LessEqNode;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaUtils;
+import org.apache.directory.shared.ldap.schema.comparators.StringComparator;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.ldap.schema.parsers.SyntaxCheckerDescription;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
-import org.junit.Test;import static org.junit.Assert.assertTrue;import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -77,30 +75,43 @@
 {
     public static final Logger LOG = LoggerFactory.getLogger( LessEqTest.class );
 
-
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
 
 
-    public LessEqTest() throws Exception
+    @BeforeClass
+    public static void setup() throws Exception
     {
         // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+        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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -126,7 +137,7 @@
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.POSTALCODE_AT_OID ) );
 
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
 
@@ -152,9 +163,9 @@
     @Test
     public void testCursorIndexed() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTALCODE_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.POSTALCODE_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.POSTALCODE_AT_OID, new ServerStringValue( at, "3" ) );
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
         LessEqCursor cursor = new LessEqCursor( store, evaluator );
         assertNotNull( cursor );
         assertFalse( cursor.available() );
@@ -163,8 +174,14 @@
 
         // ---------- test bad get() ----------
 
-        try { cursor.get(); fail(); }
-        catch( InvalidCursorPositionException e ) {}
+        try
+        {
+            cursor.get();
+            fail();
+        }
+        catch ( InvalidCursorPositionException e )
+        {
+        }
 
         // ---------- test beforeFirst() ----------
 
@@ -311,7 +328,7 @@
         // ---------- test before() ----------
 
         cursor = new LessEqCursor( store, evaluator );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "2" );
 
         assertFalse( cursor.available() );
@@ -334,7 +351,7 @@
         assertTrue( cursor.isClosed() );
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "7" );
         cursor.before( indexEntry );
         assertFalse( cursor.available() );
@@ -344,7 +361,7 @@
         cursor.close();
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "3" );
         cursor.before( indexEntry );
         assertFalse( cursor.available() );
@@ -356,7 +373,7 @@
         // ---------- test after() ----------
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "1" );
 
         assertFalse( cursor.available() );
@@ -379,7 +396,7 @@
         assertTrue( cursor.isClosed() );
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "7" );
         cursor.after( indexEntry );
         assertFalse( cursor.available() );
@@ -389,7 +406,7 @@
         cursor.close();
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "3" );
         cursor.after( indexEntry );
         assertFalse( cursor.available() );
@@ -403,9 +420,9 @@
     @Test
     public void testCursorNotIndexed() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTOFFICEBOX_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.POSTOFFICEBOX_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.POSTOFFICEBOX_AT_OID, new ServerStringValue( at, "3" ) );
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
         LessEqCursor cursor = new LessEqCursor( store, evaluator );
         assertNotNull( cursor );
         assertFalse( cursor.available() );
@@ -414,8 +431,14 @@
 
         // ---------- test bad get() ----------
 
-        try { cursor.get(); fail(); }
-        catch( InvalidCursorPositionException e ) {}
+        try
+        {
+            cursor.get();
+            fail();
+        }
+        catch ( InvalidCursorPositionException e )
+        {
+        }
 
         // ---------- test beforeFirst() ----------
 
@@ -557,18 +580,30 @@
         // ---------- test before() ----------
 
         cursor = new LessEqCursor( store, evaluator );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "2" );
-        try { cursor.before( indexEntry ); fail( "Should never get here." );}
-        catch ( UnsupportedOperationException e ) {}
+        try
+        {
+            cursor.before( indexEntry );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
 
         // ---------- test after() ----------
 
         cursor = new LessEqCursor( store, evaluator );
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setValue( "2" );
-        try { cursor.after( indexEntry ); fail( "Should never get here." );}
-        catch ( UnsupportedOperationException e ) {}
+        try
+        {
+            cursor.after( indexEntry );
+            fail( "Should never get here." );
+        }
+        catch ( UnsupportedOperationException e )
+        {
+        }
     }
 
 
@@ -576,48 +611,47 @@
     // Evaluator Test Cases
     // -----------------------------------------------------------------------
 
-
     @Test
     public void testEvaluatorIndexed() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTALCODE_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.POSTALCODE_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.POSTALCODE_AT_OID, new ServerStringValue( at, "3" ) );
 
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         assertEquals( node, evaluator.getExpression() );
         assertEquals( SchemaConstants.POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() );
         assertNotNull( evaluator.getNormalizer() );
-        assertNotNull( evaluator.getComparator() );
+        assertNotNull( evaluator.getLdapComparator() );
 
         indexEntry.setId( 1L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 4L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 5L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 6L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 7L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 8L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 9L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 10L );
         assertFalse( evaluator.evaluate( indexEntry ) );
     }
@@ -626,20 +660,20 @@
     @Test
     public void testEvaluatorWithDescendantValue() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.STREET_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.STREET_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.STREET_AT_OID, new ServerStringValue( at, "2" ) );
 
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         assertEquals( node, evaluator.getExpression() );
         assertEquals( SchemaConstants.STREET_AT_OID, evaluator.getAttributeType().getOid() );
         assertNotNull( evaluator.getNormalizer() );
-        assertNotNull( evaluator.getComparator() );
+        assertNotNull( evaluator.getLdapComparator() );
 
         LdapDN dn = new LdapDN( "cn=jane doe,o=good times co." );
-        dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-        ServerEntry attrs = new DefaultServerEntry( registries, dn );
-        attrs.add(  "objectClass", "person" );
+        dn.normalize( schemaManager.getNormalizerMapping() );
+        ServerEntry attrs = new DefaultServerEntry( schemaManager, dn );
+        attrs.add( "objectClass", "person" );
         attrs.add( "c-street", "1" );
         attrs.add( "cn", "jane doe" );
         attrs.add( "sn", "doe" );
@@ -655,15 +689,15 @@
     @Test
     public void testEvaluatorWithoutDescendants() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.C_POSTALCODE_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.C_POSTALCODE_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.C_POSTALCODE_AT_OID, new ServerStringValue( at, "2" ) );
 
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         assertEquals( node, evaluator.getExpression() );
         assertEquals( SchemaConstants.C_POSTALCODE_AT_OID, evaluator.getAttributeType().getOid() );
         assertNotNull( evaluator.getNormalizer() );
-        assertNotNull( evaluator.getComparator() );
+        assertNotNull( evaluator.getLdapComparator() );
 
         indexEntry.setId( 1L );
         assertFalse( evaluator.evaluate( indexEntry ) );
@@ -673,80 +707,104 @@
     @Test
     public void testEvaluatorNotIndexed() throws Exception
     {
-        AttributeType at = attributeRegistry.lookup( SchemaConstants.POSTOFFICEBOX_AT_OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.POSTOFFICEBOX_AT_OID );
         LessEqNode node = new LessEqNode( SchemaConstants.POSTOFFICEBOX_AT_OID, new ServerStringValue( at, "3" ) );
 
-        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, registries );
-        ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        LessEqEvaluator evaluator = new LessEqEvaluator( node, store, schemaManager );
+        ForwardIndexEntry<String, ServerEntry> indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         assertEquals( node, evaluator.getExpression() );
         assertEquals( SchemaConstants.POSTOFFICEBOX_AT_OID, evaluator.getAttributeType().getOid() );
         assertNotNull( evaluator.getNormalizer() );
-        assertNotNull( evaluator.getComparator() );
+        assertNotNull( evaluator.getLdapComparator() );
 
         indexEntry.setId( 1L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 4L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 5L );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 6L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 7L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 8L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 9L );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
-        indexEntry = new ForwardIndexEntry<String,ServerEntry>();
+        indexEntry = new ForwardIndexEntry<String, ServerEntry>();
         indexEntry.setId( 10L );
         assertFalse( evaluator.evaluate( indexEntry ) );
     }
 
 
-    @Test ( expected = IllegalStateException.class )
+    @Test(expected = IllegalStateException.class)
     public void testEvaluatorAttributeNoMatchingRule() throws Exception
     {
-        AttributeType at = new NoMatchingRuleAttributeType();
-        registries.getAttributeTypeRegistry().register( at );
+        LdapSyntax syntax = new BogusSyntax( 1 );
+        AttributeType at = new AttributeType( SchemaConstants.ATTRIBUTE_TYPES_AT_OID + ".2000" );
+        at.addName( "bogus" );
+        at.setSchemaName( "other" );
+        at.setSyntax( syntax );
 
-        LessEqNode node = new LessEqNode( at.getOid(), new ServerStringValue( at, "3" ) );
+        assertTrue( schemaManager.add( syntax ) );
+        assertTrue( schemaManager.add( at ) );
 
-        new LessEqEvaluator( node, store, registries );
-        registries.getAttributeTypeRegistry().unregister( at.getOid() );
+        try
+        {
+            LessEqNode node = new LessEqNode( at.getOid(), new ServerStringValue( at, "3" ) );
+
+            new LessEqEvaluator( node, store, schemaManager );
+        }
+        finally
+        {
+            assertTrue( schemaManager.delete( at ) );
+            assertTrue( schemaManager.delete( syntax ) );
+        }
     }
 
 
     @Test
     public void testEvaluatorAttributeOrderingMatchingRule() throws Exception
     {
-        AttributeType at = new OrderingOnlyMatchingRuleAttributeType();
-        registries.getAttributeTypeRegistry().register( at );
-        registries.getSyntaxRegistry().register( at.getSyntax() );
-        SyntaxCheckerDescription desc = new SyntaxCheckerDescription();
+        LdapSyntax syntax = new BogusSyntax( 2 );
+
+        MatchingRule mr = new MatchingRule( "1.1" );
+        mr.setSyntax( syntax );
+        mr.setLdapComparator( new StringComparator( "1.1" ) );
+
+        AttributeType at = new AttributeType( SchemaConstants.ATTRIBUTE_TYPES_AT_OID + ".3000" );
+        at.addName( "bogus" );
+        at.setSchemaName( "other" );
+        at.setSyntax( syntax );
+        at.setOrdering( mr );
+
+        assertTrue( schemaManager.add( syntax ) );
+        assertTrue( schemaManager.add( mr ) );
+        assertTrue( schemaManager.add( at ) );
+
+        SyntaxCheckerDescription desc = new SyntaxCheckerDescription( at.getSyntax().getOid() );
         desc.setDescription( "bogus" );
         desc.setFqcn( BogusSyntax.class.getName() );
         List<String> names = new ArrayList<String>();
         names.add( "bogus" );
         desc.setNames( names );
-        desc.setNumericOid( at.getSyntax().getOid() );
         desc.setObsolete( false );
-        registries.getSyntaxCheckerRegistry().register( desc, at.getSyntax().getSyntaxChecker() );
 
         LessEqNode node = new LessEqNode( at.getOid(), new ServerStringValue( at, "3" ) );
-        new LessEqEvaluator( node, store, registries );
-        registries.getAttributeTypeRegistry().unregister( at.getOid() );
+        new LessEqEvaluator( node, store, schemaManager );
+        schemaManager.delete( at );
     }
 }

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NestedFilterTest.java Wed Jan  6 18:26:43 2010
@@ -20,39 +20,36 @@
 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.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.entry.ServerEntry;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.schema.ConcreteNameComponentNormalizer;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.search.Optimizer;
 import org.apache.directory.server.xdbm.tools.StoreUtils;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
-import org.apache.directory.shared.ldap.util.StringTools;
-import org.junit.*;
-import static org.junit.Assert.*;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.normalizers.ConcreteNameComponentNormalizer;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -70,34 +67,47 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
     EvaluatorBuilder evaluatorBuilder;
     CursorBuilder cursorBuilder;
     Optimizer optimizer;
-    FilterNormalizingVisitor visitor;
+    static FilterNormalizingVisitor visitor;
 
-    
-    public NestedFilterTest() throws Exception
+    @BeforeClass
+    static public void setup() throws Exception
     {
         // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	String workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = NestedFilterTest.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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
         
-        NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( attributeRegistry, oidRegistry );
-        visitor = new FilterNormalizingVisitor( ncn, registries );
+        NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer( schemaManager );
+        visitor = new FilterNormalizingVisitor( ncn, schemaManager );
     }
 
     
@@ -121,9 +131,9 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         
-        evaluatorBuilder = new EvaluatorBuilder( store, registries );
+        evaluatorBuilder = new EvaluatorBuilder( store, schemaManager );
         cursorBuilder = new CursorBuilder( store, evaluatorBuilder );
         optimizer = new DefaultOptimizer( store );
         

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/NotCursorTest.java Wed Jan  6 18:26:43 2010
@@ -20,30 +20,20 @@
 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.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.entry.ServerEntry;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.IndexCursor;
+import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.search.Evaluator;
 import org.apache.directory.server.xdbm.tools.StoreUtils;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -52,16 +42,18 @@
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.filter.NotNode;
 import org.apache.directory.shared.ldap.filter.SubstringNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -77,28 +69,42 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
     EvaluatorBuilder evaluatorBuilder;
     CursorBuilder cursorBuilder;
 
-    public NotCursorTest() throws Exception
+    @BeforeClass
+    static public void setup() throws Exception
     {
         // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -122,9 +128,9 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         
-        evaluatorBuilder = new EvaluatorBuilder( store, registries );
+        evaluatorBuilder = new EvaluatorBuilder( store, schemaManager );
         cursorBuilder = new CursorBuilder( store, evaluatorBuilder );
         
         LOG.debug( "Created new store" );
@@ -201,7 +207,7 @@
         NotNode notNode = new NotNode();
         
         ExprNode exprNode = new SubstringNode( "cn", "J", null );
-        Evaluator<? extends ExprNode, ServerEntry> eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, registries );
+        Evaluator<? extends ExprNode, ServerEntry> eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, schemaManager );
         notNode.addNode( exprNode );
         
         NotCursor cursor = new NotCursor( store, eval ); //cursorBuilder.build( andNode );

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OneLevelScopeTest.java Wed Jan  6 18:26:43 2010
@@ -20,29 +20,24 @@
 package org.apache.directory.server.xdbm.search.impl;
 
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.directory.server.xdbm.Store;
+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 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.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
 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.tools.StoreUtils;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.core.entry.DefaultServerEntry;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
@@ -50,20 +45,19 @@
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SchemaUtils;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.UUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -79,27 +73,41 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
 
 
-    public OneLevelScopeTest() throws Exception
+    @BeforeClass
+    public static void setup() throws Exception
     {
         // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -123,7 +131,7 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
 
@@ -664,9 +672,9 @@
             SchemaConstants.OU_AT_OID + "=board of directors," +
             SchemaConstants.O_AT_OID  + "=good times co."
         );
-        dn.normalize( attributeRegistry.getNormalizerMapping() );
+        dn.normalize( schemaManager.getNormalizerMapping() );
         
-        ServerEntry attrs = new DefaultServerEntry( registries, dn );
+        ServerEntry attrs = new DefaultServerEntry( schemaManager, dn );
         attrs.add( "objectClass", "alias", "extensibleObject" );
         attrs.add( "cn", "jd" );
         attrs.add( "aliasedObjectName", "cn=Jack Daniels,ou=Engineering,o=Good Times Co." );
@@ -679,9 +687,9 @@
             SchemaConstants.OU_AT_OID + "=board of directors," +
             SchemaConstants.O_AT_OID  + "=good times co."
         );
-        dn.normalize( attributeRegistry.getNormalizerMapping() );
+        dn.normalize( schemaManager.getNormalizerMapping() );
         
-        attrs = new DefaultServerEntry( registries, dn );
+        attrs = new DefaultServerEntry( schemaManager, dn );
         attrs.add( "objectClass", "person" );
         attrs.add( "cn", "jdoe" );
         attrs.add( "sn", "doe" );

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/OrCursorTest.java Wed Jan  6 18:26:43 2010
@@ -19,33 +19,23 @@
  */
 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.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.entry.ServerEntry;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
 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.IndexCursor;
 import org.apache.directory.server.xdbm.search.Evaluator;
 import org.apache.directory.server.xdbm.tools.StoreUtils;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -55,14 +45,16 @@
 import org.apache.directory.shared.ldap.filter.FilterParser;
 import org.apache.directory.shared.ldap.filter.OrNode;
 import org.apache.directory.shared.ldap.filter.SubstringNode;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -84,28 +76,41 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
     EvaluatorBuilder evaluatorBuilder;
     CursorBuilder cursorBuilder;
 
-    public OrCursorTest() throws Exception
+    @BeforeClass
+    public static void setup() throws Exception
     {
-        // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -129,9 +134,9 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         
-        evaluatorBuilder = new EvaluatorBuilder( store, registries );
+        evaluatorBuilder = new EvaluatorBuilder( store, schemaManager );
         cursorBuilder = new CursorBuilder( store, evaluatorBuilder );
         
         LOG.debug( "Created new store" );
@@ -157,7 +162,6 @@
 
     
     @Test
-    @SuppressWarnings( "unchecked" )
     public void testOrCursorUsingCursorBuilder() throws Exception
     {
         String filter = "(|(cn=J*)(sn=W*))";
@@ -253,7 +257,7 @@
         OrNode orNode = new OrNode();
 
         ExprNode exprNode = new SubstringNode( "cn", "J", null );
-        eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, registries );
+        eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, schemaManager );
         Cursor subStrCursor1 = new SubstringCursor( store, ( SubstringEvaluator ) eval );
         cursors.add( subStrCursor1 );
         evaluators.add( eval );  
@@ -267,7 +271,7 @@
         catch( IllegalArgumentException ie ){ }
         
         exprNode = new SubstringNode( "sn", "W", null );
-        eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, registries );
+        eval = new SubstringEvaluator( ( SubstringNode ) exprNode, store, schemaManager );
         evaluators.add( eval );
         Cursor subStrCursor2 = new SubstringCursor( store, ( SubstringEvaluator ) eval );
         cursors.add( subStrCursor2 );

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/PresenceTest.java Wed Jan  6 18:26:43 2010
@@ -20,42 +20,35 @@
 package org.apache.directory.server.xdbm.search.impl;
 
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.xdbm.Store;
-import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.tools.StoreUtils;
+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.entry.ServerEntry;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.tools.StoreUtils;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.commons.io.FileUtils;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.util.Set;
-import java.util.HashSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -70,27 +63,40 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
 
 
-    public PresenceTest() throws Exception
+    @BeforeClass
+    public static void setup() throws Exception
     {
-        // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -114,7 +120,7 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
 
@@ -141,7 +147,7 @@
     public void testIndexedServerEntry() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.CN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -209,7 +215,7 @@
         assertEquals( SchemaConstants.CN_AT_OID, cursor.get().getValue() );
 
         node = new PresenceNode( SchemaConstants.OU_AT_OID );
-        evaluator = new PresenceEvaluator( node, store, registries );
+        evaluator = new PresenceEvaluator( node, store, schemaManager );
         cursor = new PresenceCursor( store, evaluator );
 
         assertTrue( cursor.isElementReused() );
@@ -255,7 +261,7 @@
     public void testNonIndexedServerEntry() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -316,7 +322,7 @@
         // ----------- organizationName attribute
 
         node = new PresenceNode( SchemaConstants.O_AT_OID );
-        evaluator = new PresenceEvaluator( node, store, registries );
+        evaluator = new PresenceEvaluator( node, store, schemaManager );
         cursor = new PresenceCursor( store, evaluator );
 
         assertTrue( cursor.isElementReused() );
@@ -338,7 +344,7 @@
     public void testEvaluatorIndexed() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.CN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         ForwardIndexEntry<String,ServerEntry> entry = new ForwardIndexEntry<String,ServerEntry>();
         entry.setValue( SchemaConstants.CN_AT_OID );
         entry.setId( ( long ) 3 );
@@ -354,7 +360,7 @@
     public void testEvaluatorNotIndexed() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.NAME_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         ForwardIndexEntry<String,ServerEntry> entry = new ForwardIndexEntry<String,ServerEntry>();
         entry.setValue( SchemaConstants.NAME_AT_OID );
         entry.setId( ( long ) 3 );
@@ -365,7 +371,7 @@
         assertTrue( evaluator.evaluate( entry ) );
 
         node = new PresenceNode( SchemaConstants.SEARCHGUIDE_AT_OID );
-        evaluator = new PresenceEvaluator( node, store, registries );
+        evaluator = new PresenceEvaluator( node, store, schemaManager );
         entry = new ForwardIndexEntry<String,ServerEntry>();
         entry.setValue( SchemaConstants.SEARCHGUIDE_AT_OID );
         entry.setId( ( long ) 3 );
@@ -377,7 +383,7 @@
         assertFalse( evaluator.evaluate( entry ) );
 
         node = new PresenceNode( SchemaConstants.ST_AT_OID );
-        evaluator = new PresenceEvaluator( node, store, registries );
+        evaluator = new PresenceEvaluator( node, store, schemaManager );
         entry = new ForwardIndexEntry<String,ServerEntry>();
         entry.setValue( SchemaConstants.ST_AT_OID );
         entry.setId( ( long ) 3 );
@@ -394,7 +400,7 @@
     public void testInvalidCursorPositionException() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
         cursor.get();
     }
@@ -404,7 +410,7 @@
     public void testInvalidCursorPositionException2() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.CN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
         cursor.get();
     }
@@ -414,7 +420,7 @@
     public void testUnsupportBeforeWithoutIndex() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
         // test before()
@@ -428,7 +434,7 @@
     public void testUnsupportAfterWithoutIndex() throws Exception
     {
         PresenceNode node = new PresenceNode( SchemaConstants.SN_AT_OID );
-        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, registries );
+        PresenceEvaluator evaluator = new PresenceEvaluator( node, store, schemaManager );
         PresenceCursor cursor = new PresenceCursor( store, evaluator );
 
         // test before()

Modified: directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java (original)
+++ directory/apacheds/trunk/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java Wed Jan  6 18:26:43 2010
@@ -20,41 +20,35 @@
 package org.apache.directory.server.xdbm.search.impl;
 
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.directory.server.xdbm.Store;
+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.entry.ServerEntry;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.xdbm.tools.StoreUtils;
-import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.bootstrap.ApacheSchema;
-import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
-import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
-import org.apache.directory.server.schema.bootstrap.CollectiveSchema;
-import org.apache.directory.server.schema.bootstrap.CoreSchema;
-import org.apache.directory.server.schema.bootstrap.Schema;
-import org.apache.directory.server.schema.bootstrap.SystemSchema;
-import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
-import org.apache.directory.server.schema.registries.DefaultOidRegistry;
-import org.apache.directory.server.schema.registries.DefaultRegistries;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
-import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.cursor.InvalidCursorPositionException;
 import org.apache.directory.shared.ldap.filter.SubstringNode;
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
 import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import java.io.File;
-import java.util.Set;
-import java.util.HashSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -69,27 +63,40 @@
 
     File wkdir;
     Store<ServerEntry> store;
-    Registries registries = null;
-    AttributeTypeRegistry attributeRegistry;
+    static SchemaManager schemaManager = null;
 
 
-    public SubstringTest() throws Exception
+    @BeforeClass
+    public static void setup() throws Exception
     {
-        // setup the standard registries
-        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
-        OidRegistry oidRegistry = new DefaultOidRegistry();
-        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-
-        // load essential bootstrap schemas
-        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
-        bootstrapSchemas.add( new ApachemetaSchema() );
-        bootstrapSchemas.add( new ApacheSchema() );
-        bootstrapSchemas.add( new CoreSchema() );
-        bootstrapSchemas.add( new SystemSchema() );
-        bootstrapSchemas.add( new CollectiveSchema() );
-        loader.loadWithDependencies( bootstrapSchemas, registries );
-        attributeRegistry = registries.getAttributeTypeRegistry();
+    	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 : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
+        
+        loaded = schemaManager.loadWithDeps( loader.getSchema( "collective" ) );
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( schemaManager.getErrors() ) );
+        }
     }
 
 
@@ -113,7 +120,7 @@
 
         store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
         store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
-        StoreUtils.loadExampleData( store, registries );
+        StoreUtils.loadExampleData( store, schemaManager );
         LOG.debug( "Created new store" );
     }
 
@@ -140,7 +147,7 @@
     public void testIndexedCnStartsWithJ() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "j", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -293,7 +300,7 @@
     public void testIndexedCnStartsWithJim() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "jim", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -386,7 +393,7 @@
     public void testIndexedCnEndsWithBean() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, null, "bean" );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -479,7 +486,7 @@
     public void testNonIndexedSnStartsWithB() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "b", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -542,7 +549,7 @@
     public void testIndexedSnEndsWithEr() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, null, "er" );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         assertEquals( node, evaluator.getExpression() );
@@ -604,7 +611,7 @@
     public void testNonIndexedAttributes() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "walk", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 5L );
         assertTrue( evaluator.evaluate( indexEntry ) );
@@ -616,35 +623,35 @@
         assertFalse( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.SN_AT_OID, "wa", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 5L );
         indexEntry.setObject( store.lookup( 5L ) );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.SEARCHGUIDE_AT_OID, "j", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.ST_AT_OID, "j", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
         assertFalse( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.NAME_AT_OID, "j", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.NAME_AT_OID, "s", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
@@ -656,7 +663,7 @@
     public void testEvaluatorIndexed() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "jim", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         ForwardIndexEntry<String,ServerEntry> indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         assertTrue( evaluator.evaluate( indexEntry ) );
@@ -665,14 +672,14 @@
         assertFalse( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.CN_AT_OID, "j", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
         assertTrue( evaluator.evaluate( indexEntry ) );
 
         node = new SubstringNode( SchemaConstants.CN_AT_OID, "s", null );
-        evaluator = new SubstringEvaluator( node, store, registries );
+        evaluator = new SubstringEvaluator( node, store, schemaManager );
         indexEntry = new ForwardIndexEntry<String,ServerEntry>();
         indexEntry.setId( 6L );
         indexEntry.setObject( store.lookup( 6L ) );
@@ -690,7 +697,7 @@
     public void testInvalidCursorPositionException() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "b", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
         cursor.get();
     }
@@ -700,7 +707,7 @@
     public void testInvalidCursorPositionException2() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "j", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
         cursor.get();
     }
@@ -710,7 +717,7 @@
     public void testUnsupportBeforeWithoutIndex() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "j", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         // test before()
@@ -724,7 +731,7 @@
     public void testUnsupportAfterWithoutIndex() throws Exception
     {
         SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "j", null );
-        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, schemaManager );
         SubstringCursor cursor = new SubstringCursor( store, evaluator );
 
         // test before()



Mime
View raw message