directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r892246 - in /directory/apacheds/branches/apacheds-schema: core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ core-integ/src/main/java/org/apache/directory/server/core/integ/ core-integ/src/test/java/or...
Date Fri, 18 Dec 2009 13:36:26 GMT
Author: elecharny
Date: Fri Dec 18 13:36:26 2009
New Revision: 892246

URL: http://svn.apache.org/viewvc?rev=892246&view=rev
Log:
o Added tests for the disableSchema operation
o Fixed a big in the disableSchema method in the server

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java?rev=892246&r1=892245&r2=892246&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/SchemaSynchronizer.java
Fri Dec 18 13:36:26 2009
@@ -466,7 +466,16 @@
                
                 if ( disabledInMods != null )
                 {
-                    isNewStateDisabled = "TRUE".equalsIgnoreCase( disabledInMods.getString()
);
+                    Value<?> val = disabledInMods.get();
+                    
+                    if ( val == null )
+                    {
+                        isNewStateDisabled = false;
+                    }
+                    else
+                    {
+                        isNewStateDisabled = "TRUE".equalsIgnoreCase( val.getString() );
+                    }
                 }
 
                 if ( isCurrentlyDisabled && !isNewStateDisabled )

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=892246&r1=892245&r2=892246&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
Fri Dec 18 13:36:26 2009
@@ -331,6 +331,17 @@
     
     
     /**
+     * A helper method which tells if a schema is loaded.
+     */
+    public static boolean isLoaded( DirectoryService service, String schemaName )
+    {
+        Schema schema = service.getSchemaManager().getLoadedSchema( schemaName );
+        
+        return ( schema != null );
+    }
+    
+    
+    /**
      * A helper method which tells if a schema is enabled. A shema must be
      * loaded and enabled.
      */

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java?rev=892246&r1=892245&r2=892246&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
Fri Dec 18 13:36:26 2009
@@ -80,9 +80,11 @@
 public class MetaSchemaHandlerIT extends AbstractMetaSchemaObjectHandlerIT
 {
     /** a test attribute in the test schema: uidNumber in nis schema */
-    private static final String NIS_ATTR_OID = "1.3.6.1.1.1.1.0";
     private static final String UID_NUMBER_ATTR = "uidnumber";
     
+    /** Another test attribute : krb5principalName taken from the Krb5Kdc schema */
+    private static final String KRB5_PRINCIPAL_NAME_ATTR = "krb5PrincipalName";
+    
     public static DirectoryService service;
 
 
@@ -104,6 +106,20 @@
     }
 
     
+    private void createDisabledBrokenSchema() throws Exception
+    {
+        LdapContext schemaRoot = getSchemaContext( service );
+
+        // Create the schema
+        Attributes dummySchema = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
+            "cn: broken",
+            MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
+        
+        schemaRoot.createSubcontext( "cn=broken", dummySchema );
+    }
+    
     // -----------------------------------------------------------------------
     // Enabling Schema tests
     // -----------------------------------------------------------------------
@@ -213,9 +229,130 @@
         // TODO : create a special Schema colliding with an existing one
     }
 
+    
     // -----------------------------------------------------------------------
     // Disabling Schema tests
     // -----------------------------------------------------------------------
+    /**
+     * Checks to make sure updates disabling a metaSchema object in
+     * the schema partition triggers the loading of that schema into
+     * the global registries.
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testDisableExistingSchema() throws Exception
+    {
+        // Check that the krb5kdc schema is loaded
+        assertTrue( IntegrationUtils.isLoaded( service, "krb5kdc" ) );
+
+        // check that the krb5kdc schema is enabled
+        assertTrue( IntegrationUtils.isEnabled( service, "krb5kdc" ) );
+        
+        // double check and make sure an attribute from that schema is 
+        // in the AttributeTypeRegistry
+        assertTrue( service.getSchemaManager().getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR
) );
+        
+        // now disable the krb5kdc schema
+        IntegrationUtils.disableSchema( service, "krb5kdc" );
+        
+        // now test that the schema is not enabled 
+        assertTrue( IntegrationUtils.isDisabled( service, "krb5kdc" ) );
+        
+        // double check and make sure the test attribute from the 
+        // test schema is now loaded and present within the attr registry
+        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR
) );
+    }
+
+
+    /**
+     * Checks that trying to disable a non existing schema does not work
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testDisableNotExistingSchema() throws Exception
+    {
+        // check that the 'wrong' schema is not loaded
+        assertFalse( IntegrationUtils.isLoaded( service, "wrong" ) );
+        
+        // now disable the 'wrong' schema
+        try
+        {
+            IntegrationUtils.disableSchema( service, "wrong" );
+            fail();
+        }
+        catch ( LdapNameNotFoundException lnnfe )
+        {
+            // Expected
+            assertTrue( true );
+        }
+        
+        // Test again that the schema is not loaded 
+        assertFalse( IntegrationUtils.isLoaded( service, "wrong" ) );
+    }
+
+    
+    /**
+     * Checks to make sure that if we try to disable an already disabled
+     * schema, we don't do anything.
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testDisableSchemaAlreadyDisabled() throws Exception
+    {
+        // check that the nis schema is loaded
+        assertTrue( IntegrationUtils.isLoaded(  service, "nis" ) );
+        
+        // Check that it's not enabled
+        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
+        
+        // double check and make sure an attribute from that schema is 
+        // not in the AttributeTypeRegistry
+        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
+        
+        // now disable the test schema again
+        IntegrationUtils.disableSchema( service, "nis" );
+
+        // now test that the schema is not loaded 
+        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
+        
+        // double check and make sure the test attribute from the 
+        // test schema is not loaded and present within the attr registry
+        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
+    }
+
+    
+    /**
+     * Checks that if we disable a schema which will break the registries, we get 
+     * an error. 
+     *
+     * @throws Exception on error
+     */
+    @Test
+    public void testDisableSchemaBreakingRegistries() throws Exception
+    {
+        // check that the nis schema is loaded
+        assertTrue( IntegrationUtils.isLoaded(  service, "system" ) );
+        
+        // Check that it's enabled
+        assertTrue( IntegrationUtils.isEnabled( service, "system" ) );
+        
+        // double check and make sure an attribute from that schema is 
+        // in the AttributeTypeRegistry
+        assertTrue( service.getSchemaManager().getAttributeTypeRegistry().contains( "cn"
) );
+        
+        // now disable the system schema : it should break the registries, thus being rejected
+        IntegrationUtils.disableSchema( service, "system" );
+
+        // now test that the schema is not loaded 
+        assertTrue( IntegrationUtils.isEnabled( service, "system" ) );
+        
+        // double check and make sure the test attribute from the 
+        // test schema is loaded and present within the attr registry
+        assertTrue( service.getSchemaManager().getAttributeTypeRegistry().contains( "cn"
) );
+    }
 
     // -----------------------------------------------------------------------
     // Schema Add Tests
@@ -474,74 +611,6 @@
     }
 
     
-
-    
-    /**
-     * Checks to make sure that if we try to disable an already disabled
-     * schema, we don't do anything.
-     *
-     * @throws Exception on error
-     */
-    @Test
-    public void testDisableSchemaAlreadyDisabled() throws Exception
-    {
-        // check that the nis schema is not loaded
-        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
-        
-        // double check and make sure an attribute from that schema is 
-        // not in the AttributeTypeRegistry
-        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
-        
-        // now disable the test schema
-        IntegrationUtils.disableSchema( service, "nis" );
-        
-        // now test that the schema is loaded 
-        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
-        
-        // and disable it again (it should not do anything)
-        IntegrationUtils.disableSchema( service, "nis" );
-        
-        // and test again that the schema is still disabled
-        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
-        
-        // double check and make sure the test attribute from the 
-        // test schema is now loaded and present within the attr registry
-        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
-    }
-
-    
-    /**
-     * Checks to make sure an attempt to disable a metaSchema fails if 
-     * that schema has dependents which are enabled.
-     *
-     * @throws Exception on error
-     */
-    @Test
-    public void testDisableSchema() throws Exception
-    {
-        // let's enable the test schema
-        testEnableExistingSchema();
-        
-        // check that the nis schema is enabled
-        assertTrue( IntegrationUtils.isEnabled( service, "nis" ) );
-        
-        // double check and make sure an attribute from that schema is 
-        // in the AttributeTypeRegistry
-        assertTrue( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
-        
-        // now disable the test schema 
-        IntegrationUtils.disableSchema( service, "samba" );
-        IntegrationUtils.disableSchema( service, "nis" );
-        
-        // now test that the schema is NOT loaded 
-        assertTrue( IntegrationUtils.isDisabled( service, "nis" ) );
-        
-        // double check and make sure the test attribute from the test  
-        // schema is now NOT loaded and present within the attr registry
-        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR
) );
-    }
-
-    
     /**
      * Checks to make sure updates disabling a metaSchema object in
      * the schema partition triggers the unloading of that schema from



Mime
View raw message