directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r887566 - in /directory/shared/branches/shared-schema/ldap-schema-loader/src: main/java/org/apache/directory/shared/schema/ test/java/org/apache/directory/server/schema/
Date Sat, 05 Dec 2009 17:56:19 GMT
Author: elecharny
Date: Sat Dec  5 17:56:19 2009
New Revision: 887566

URL: http://svn.apache.org/viewvc?rev=887566&view=rev
Log:
o Fixed the load( schema...) method which was throwing a NPE
o Split the load tests class in two and added some more tests

Added:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadWithDepsTest.java
Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=887566&r1=887565&r2=887566&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Sat Dec  5 17:56:19 2009
@@ -388,6 +388,12 @@
     {
         boolean loaded = false;
 
+        // Reset the errors if not null
+        if ( errors != null )
+        {
+            errors.clear();
+        }
+
         // Work on a cloned and relaxed registries
         Registries clonedRegistries = cloneRegistries();
         clonedRegistries.setRelaxed();
@@ -399,7 +405,7 @@
         }
 
         // Build the cross references
-        List<Throwable> errors = clonedRegistries.buildReferences();
+        errors = clonedRegistries.buildReferences();
 
         if ( errors.isEmpty() )
         {
@@ -409,6 +415,7 @@
             if ( errors.isEmpty() )
             {
                 // We are golden : let's apply the schema in the real registries
+                registries.setRelaxed();
 
                 // Load the schemas
                 for ( Schema schema : schemas )
@@ -417,7 +424,8 @@
                 }
 
                 // Build the cross references
-                registries.buildReferences();
+                errors = registries.buildReferences();
+                registries.setStrict();
 
                 loaded = true;
             }
@@ -451,6 +459,12 @@
      */
     private boolean load( Registries registries, Schema schema ) throws Exception
     {
+        if ( schema == null )
+        {
+            LOG.info( "The schema is null" );
+            return false;
+        }
+
         // First avoid loading twice the same schema
         if ( registries.isSchemaLoaded( schema.getSchemaName() ) )
         {

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java?rev=887566&r1=887565&r2=887566&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java
Sat Dec  5 17:56:19 2009
@@ -21,6 +21,7 @@
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -31,6 +32,8 @@
 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.registries.DefaultSchema;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 import org.junit.AfterClass;
@@ -44,8 +47,6 @@
  *  Server API
  *     boolean load( Schema... schemas ) throws Exception
  *     boolean load( String... schemas ) throws Exception
- *     boolean loadWithDeps( Schema... schemas ) throws Exception
- *     boolean loadWithDeps( String... schemas ) throws Exception
  *     boolean loadDisabled( Schema... schemas ) throws Exception
  *     boolean loadDisabled( String... schemas ) throws Exception
  *     boolean loadAllEnabled() throws Exception
@@ -53,10 +54,112 @@
  *  Studio API :
  *     boolean loadRelaxed( Schema... schemas ) throws Exception
  *     boolean loadRelaxed( String... schemas ) throws Exception
- *     boolean loadWithDepsRelaxed( Schema... schemas ) throws Exception
- *     boolean loadWithDepsRelaxed( String... schemas ) throws Exception
  *     boolean loadAllEnabledRelaxed() throws Exception 
- *
+ *     
+ * We check the resulting number of SchemaObjects in the registries. Those number are :
+ * 
+ * Apache :
+ *   AT :  53
+ *   C  :   8
+ *   MR :   8
+ *   N  :   8
+ *   OC :  17
+ *   SC :   3
+ *   S  :   7
+ *   OID:  85
+ *   
+ * ApacheDns :
+ *   AT :  16
+ *   OC :  11
+ *   OID:  27
+ *   
+ * ApacheMeta :
+ *   AT :  31
+ *   C  :   5
+ *   MR :   5
+ *   N  :   7
+ *   OC :  13
+ *   SC :   4
+ *   S  :   5
+ *   OID:  54
+ * 
+ * AutoFs :
+ *   AT :   1
+ *   OC :   2
+ *   OID:   3
+ * 
+ * Collective :
+ *   AT :  13
+ *   OID:  13
+ * 
+ * Corba :
+ *   AT :   2
+ *   OC :   3
+ *   OID:   5
+ * 
+ * Core :
+ *   AT :  54
+ *   OC :  27
+ *   OID:  81
+ * 
+ * Cosine :
+ *   AT :  41
+ *   OC :  13
+ *   OID:  54
+ * 
+ * Dhcp :
+ *   AT :  39
+ *   OC :  12
+ *   OID:  51
+ * 
+ * InetOrgPerson :
+ *   AT :   9
+ *   OC :   1
+ *   OID:  10
+ * 
+ * Java :
+ *   AT :   7
+ *   OC :   5
+ *   OID:  12
+ * 
+ * Krb5Kdc :
+ *   AT :  15
+ *   OC :   3
+ *   OID:  18
+ * 
+ * Mozilla :
+ *   AT :  17
+ *   OC :   1
+ *   OID:  18
+ * 
+ * Nis :
+ *   AT :  27
+ *   C  :   1
+ *   MR :   1
+ *   N  :   1
+ *   OC :  13
+ *   SC :   2
+ *   S  :   2
+ *   OID:  43
+ * 
+ * Other :
+ *   OID:   0
+ * 
+ * Samba :
+ *   AT :  37
+ *   OC :  11
+ *   OID:  48
+ * 
+ * System :
+ *   AT :  38
+ *   C  :  35
+ *   MR :  35
+ *   N  :  35
+ *   OC :   9
+ *   SC :  59
+ *   S  :  59
+ *   OID: 141
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
@@ -111,7 +214,7 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "system" );
+        assertTrue( schemaManager.load( "system" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 38, schemaManager.getAttributeTypeRegistry().size() );
@@ -137,7 +240,11 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "core" );
+        // Check that we can't load a schema without its dependencies
+        assertFalse( schemaManager.load( "core" ) );
+
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 92, schemaManager.getAttributeTypeRegistry().size() );
@@ -164,7 +271,9 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "apache" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "apache" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 145, schemaManager.getAttributeTypeRegistry().size() );
@@ -192,7 +301,8 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "apacheMeta" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "apacheMeta" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 69, schemaManager.getAttributeTypeRegistry().size() );
@@ -219,7 +329,9 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "Java" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "Java" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 99, schemaManager.getAttributeTypeRegistry().size() );
@@ -240,7 +352,8 @@
 
     /**
      * test loading the "other" schema, which depends on "system", "core",
-     * "apache" and "apacheMeta"
+     * "apache" and "apacheMeta". As we don't have any cross dependencies
+     * with any of this other schemas, we can only load core and system
      */
     @Test
     public void testLoadOther() throws Exception
@@ -248,23 +361,23 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "other" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "other" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
-        assertEquals( 176, schemaManager.getAttributeTypeRegistry().size() );
-        assertEquals( 48, schemaManager.getComparatorRegistry().size() );
-        assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() );
-        assertEquals( 50, schemaManager.getNormalizerRegistry().size() );
-        assertEquals( 66, schemaManager.getObjectClassRegistry().size() );
-        assertEquals( 66, schemaManager.getSyntaxCheckerRegistry().size() );
-        assertEquals( 71, schemaManager.getLdapSyntaxRegistry().size() );
-        assertEquals( 361, schemaManager.getOidRegistry().size() );
+        assertEquals( 92, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 36, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 222, schemaManager.getOidRegistry().size() );
 
-        assertEquals( 5, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
-        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apache" ) );
-        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apacheMeta" ) );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "other" ) );
     }
 
@@ -278,7 +391,9 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "cosine" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "cosine" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 133, schemaManager.getAttributeTypeRegistry().size() );
@@ -307,7 +422,10 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "InetOrgPerson" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "cosine" ) );
+        assertTrue( schemaManager.load( "InetOrgPerson" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
@@ -336,7 +454,9 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "Collective" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "Collective" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 105, schemaManager.getAttributeTypeRegistry().size() );
@@ -364,7 +484,9 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "Krb5Kdc" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "Krb5Kdc" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 107, schemaManager.getAttributeTypeRegistry().size() );
@@ -393,22 +515,26 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "nis" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core" ) );
+        assertTrue( schemaManager.load( "cosine" ) );
+        assertTrue( schemaManager.load( "nis" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
-        assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
-        assertEquals( 0, schemaManager.getComparatorRegistry().size() );
-        assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
-        assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
-        assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
-        assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
-        assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
-        assertEquals( 0, schemaManager.getOidRegistry().size() );
-
-        assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
-        assertNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
-        assertNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
-        assertNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertEquals( 133, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 49, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 276, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "nis" ) );
     }
 
 
@@ -421,19 +547,22 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "bad" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "bad" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
-        assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
-        assertEquals( 0, schemaManager.getComparatorRegistry().size() );
-        assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
-        assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
-        assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
-        assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
-        assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
-        assertEquals( 0, schemaManager.getOidRegistry().size() );
+        assertEquals( 38, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 9, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 141, schemaManager.getOidRegistry().size() );
 
-        assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "bad" ) );
     }
 
 
@@ -446,7 +575,8 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "core", "InetOrgPerson" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core", "cosine", "InetOrgPerson" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
@@ -475,7 +605,8 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "core", "bad", "InetOrgPerson" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core", "bad", "cosine", "InetOrgPerson" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
@@ -504,7 +635,8 @@
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
-        schemaManager.loadWithDeps( "core", "nis", "InetOrgPerson" );
+        assertTrue( schemaManager.load( "system" ) );
+        assertTrue( schemaManager.load( "core", "nis", "cosine", "InetOrgPerson" ) );
 
         assertTrue( schemaManager.getErrors().isEmpty() );
         assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
@@ -522,4 +654,44 @@
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
     }
+
+
+    //---------------------------------------------------------------------------
+    // Test the load( Schema... ) method
+    //---------------------------------------------------------------------------
+    /**
+     * test loading the "InetOrgPerson", "core" and an empty schema. The empty schema
+     * should be present in the registries, as it's a vaid schema
+     */
+    @Test
+    public void testLoadSchemasWithDepsCoreInetOrgPersonAndBad() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        Schema system = loader.getSchema( "system" );
+        Schema core = loader.getSchema( "core" );
+        Schema empty = new DefaultSchema( "empty" );
+        Schema cosine = loader.getSchema( "cosine" );
+        Schema inetOrgPerson = loader.getSchema( "InetOrgPerson" );
+
+        assertTrue( schemaManager.load( system, core, empty, cosine, inetOrgPerson ) );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 286, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 5, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "empty" ) );
+    }
 }

Added: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadWithDepsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadWithDepsTest.java?rev=887566&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadWithDepsTest.java
(added)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerLoadWithDepsTest.java
Sat Dec  5 17:56:19 2009
@@ -0,0 +1,517 @@
+/*
+ *  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.schema;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+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.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * A test class for SchemaManager loadWithDeps() method. We test those methods here :
+ * 
+ *  Server API
+ *     boolean loadWithDeps( Schema... schemas ) throws Exception
+ *     boolean loadWithDeps( String... schemas ) throws Exception
+ *
+ *  Studio API :
+ *     boolean loadWithDepsRelaxed( Schema... schemas ) throws Exception
+ *     boolean loadWithDepsRelaxed( String... schemas ) throws Exception
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaManagerLoadWithDepsTest
+{
+    // A directory in which the ldif files will be stored
+    private static String workingDirectory;
+
+    // The schema repository
+    private static File schemaRepository;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = SchemaManagerLoadWithDepsTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+
+        schemaRepository = new File( workingDirectory, "schema" );
+
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( schemaRepository );
+
+        SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory
) );
+        extractor.extractOrCopy();
+    }
+
+
+    @AfterClass
+    public static void cleanup() throws IOException
+    {
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( schemaRepository );
+    }
+
+
+    //-------------------------------------------------------------------------
+    // Test the load( String... schemaName) method
+    //-------------------------------------------------------------------------
+    /**
+     * test loading the "system" schema 
+     */
+    @Test
+    public void testLoadSystem() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "system" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 38, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 9, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 141, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+    }
+
+
+    /**
+     * test loading the "core" schema, which depends on "system"
+     */
+    @Test
+    public void testLoadCore() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "core" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 92, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 36, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 222, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 2, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+    }
+
+
+    /**
+     * test loading the "apache" schema, which depends on "system" and "core"
+     */
+    @Test
+    public void testLoadApache() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "apache" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 145, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 43, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 43, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 43, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 53, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 62, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 66, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 307, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apache" ) );
+    }
+
+
+    /**
+     * test loading the "apacheMeta" schema, which depends on "system"
+     */
+    @Test
+    public void testLoadApacheMeta() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "apacheMeta" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 69, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 40, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 40, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 42, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 22, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 63, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 64, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 195, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 2, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apachemeta" ) );
+    }
+
+
+    /**
+     * test loading the "java" schema, which depends on "system" and "core"
+     */
+    @Test
+    public void testLoadJava() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "Java" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 99, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 41, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 234, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "Java" ) );
+    }
+
+
+    /**
+     * test loading the "other" schema, which depends on "system", "core",
+     * "apache" and "apacheMeta"
+     */
+    @Test
+    public void testLoadOther() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "other" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 176, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 48, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 48, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 50, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 66, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 66, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 71, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 361, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 5, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apache" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "apacheMeta" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "other" ) );
+    }
+
+
+    /**
+     * test loading the "cosine" schema, which depends on "system" and "core"
+     */
+    @Test
+    public void testLoadCosine() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "cosine" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 133, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 49, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 276, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+    }
+
+
+    /**
+     * test loading the "InetOrgPerson" schema, which depends on "system", "core"
+     * and "cosine"
+     */
+    @Test
+    public void testLoadInetOrgPerson() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "InetOrgPerson" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 286, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 4, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+    }
+
+
+    /**
+     * test loading the "Collective" schema, which depends on "system" and "core"
+     */
+    @Test
+    public void testLoadCollective() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "Collective" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 105, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 36, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 235, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "collective" ) );
+    }
+
+
+    /**
+     * test loading the "Krb5Kdc" schema, which depends on "system" and "core"
+     */
+    @Test
+    public void testLoadKrb5Kdc() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "Krb5Kdc" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 107, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 39, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 240, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "Krb5Kdc" ) );
+    }
+
+
+    /**
+     * test loading the "nis" schema, which depends on "system", "core" and "cosine",
+     * but is disabled
+     */
+    @Test
+    public void testLoadNis() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "nis" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 0, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 0, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+    }
+
+
+    /**
+     * Test loading a wrong schema
+     */
+    @Test
+    public void testLoadWrongSchema() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "bad" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 0, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 0, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
+    }
+
+
+    /**
+     * test loading the "InetOrgPerson" and "core" schema, which depends on "system" and
"cosine"
+     */
+    @Test
+    public void testLoadCoreAndInetOrgPerson() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "core", "InetOrgPerson" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 286, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 4, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+    }
+
+
+    /**
+     * test loading the "InetOrgPerson", "core" and a bad schema
+     */
+    @Test
+    public void testLoadCoreInetOrgPersonAndBad() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "core", "bad", "InetOrgPerson" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 286, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 4, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+    }
+
+
+    /**
+     * test loading the "InetOrgPerson", "core" and a disabled schema
+     */
+    @Test
+    public void testLoadCoreInetOrgPersonAndNis() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        schemaManager.loadWithDeps( "core", "nis", "InetOrgPerson" );
+
+        assertTrue( schemaManager.getErrors().isEmpty() );
+        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( 35, schemaManager.getComparatorRegistry().size() );
+        assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( 286, schemaManager.getOidRegistry().size() );
+
+        assertEquals( 4, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+    }
+}



Mime
View raw message