directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r892670 - in /directory/shared/branches/shared-schema/ldap-schema-loader/src: main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java test/java/org/apache/directory/server/schema/SchemaManagerLoadTest.java
Date Sun, 20 Dec 2009 22:27:11 GMT
Author: elecharny
Date: Sun Dec 20 22:27:10 2009
New Revision: 892670

URL: http://svn.apache.org/viewvc?rev=892670&view=rev
Log:
o Added the schema dependencies management
o Added the loaded schema to the registries
o Handled the invalid schema loading
o Fixed tests and added a new one

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=892670&r1=892669&r2=892670&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
Sun Dec 20 22:27:10 2009
@@ -211,6 +211,10 @@
 
     private void addSchemaObjects( Schema schema, Registries registries ) throws Exception
     {
+        // Create a content container for this schema
+        registries.addSchema( schema.getSchemaName() );
+        
+        // And inject any existig SchemaObject into the registries 
         addComparators( schema, registries );
         addNormalizers( schema, registries );
         addSyntaxCheckers( schema, registries );
@@ -540,7 +544,10 @@
         // Load the schemas
         for ( Schema schema : schemas )
         {
-            load( clonedRegistries, schema );
+            if ( !load( clonedRegistries, schema ) && ( ! errors.isEmpty() ) )
+            {
+                return false;
+            }
         }
 
         // Build the cross references
@@ -656,6 +663,24 @@
         else
         {
             LOG.info( "Loading {} enabled schema: \n{}", schema.getSchemaName(), schema );
+            
+            // Check that the dependencies, if any, are correct
+            if ( schema.getDependencies() != null )
+            {
+                for ( String dependency : schema.getDependencies() )
+                {
+                    if ( schemaLoader.getSchema( dependency ) == null )
+                    {
+                        // The dependency has not been loaded.
+                        String msg = "Cannot load the Schema " + schema.getSchemaName()
+                            + " as one of its dependencies has not been loaded";
+                        LOG.info( msg );
+                        Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.OTHER
);
+                        errors.add( error );
+                        return false;
+                    }
+                }
+            }
 
             registries.schemaLoaded( schema );
             addSchemaObjects( schema, registries );

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=892670&r1=892669&r2=892670&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
Sun Dec 20 22:27:10 2009
@@ -653,25 +653,28 @@
     {
         LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
         SchemaManager schemaManager = new DefaultSchemaManager( loader );
-
+        
         assertTrue( schemaManager.load( "system" ) );
-        assertTrue( schemaManager.load( "core", "nis", "cosine", "InetOrgPerson" ) );
+        
+        // Try to load a disabled schema when the registries does
+        // ot allow disabled schema to be loaded
+        assertFalse( schemaManager.load( "core", "nis", "cosine", "InetOrgPerson" ) );
 
-        assertTrue( schemaManager.getErrors().isEmpty() );
-        assertEquals( 142, schemaManager.getAttributeTypeRegistry().size() );
+        assertFalse( schemaManager.getErrors().isEmpty() );
+        assertEquals( 38, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( 35, schemaManager.getComparatorRegistry().size() );
         assertEquals( 35, schemaManager.getMatchingRuleRegistry().size() );
         assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
-        assertEquals( 50, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( 9, schemaManager.getObjectClassRegistry().size() );
         assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
         assertEquals( 59, schemaManager.getLdapSyntaxRegistry().size() );
-        assertEquals( 286, schemaManager.getGlobalOidRegistry().size() );
+        assertEquals( 141, schemaManager.getGlobalOidRegistry().size() );
 
-        assertEquals( 4, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
-        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
-        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
-        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
     }
 
 
@@ -713,4 +716,61 @@
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "InetOrgPerson" ) );
         assertNotNull( schemaManager.getRegistries().getLoadedSchema( "empty" ) );
     }
+    
+    
+    /**
+     * Test that we can load a new schema
+     */
+    @Test
+    public void loadNewSchema() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        Schema dummy = new DefaultSchema( "dummy" );
+
+        assertTrue( schemaManager.load( dummy ) );
+
+        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.getGlobalOidRegistry().size() );
+
+        assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNotNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
+    }
+    
+    
+    /**
+     * Test that we can't load a new schema with bad dependencies
+     */
+    @Test
+    public void loadNewSchemaBadDependencies() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+
+        Schema dummy = new DefaultSchema( "dummy" );
+        dummy.addDependencies( "bad" );
+
+        assertFalse( schemaManager.load( dummy ) );
+
+        assertFalse( 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.getGlobalOidRegistry().size() );
+
+        assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
+        assertNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
+    }
 }



Mime
View raw message