directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r891796 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/schema/
Date Thu, 17 Dec 2009 16:47:43 GMT
Author: elecharny
Date: Thu Dec 17 16:47:42 2009
New Revision: 891796

URL: http://svn.apache.org/viewvc?rev=891796&view=rev
Log:
o Fixed a bug when trying to remove a SyntaxChcker which has been referenced by a delete Syntax
o Removal of dead code in MatchingRule

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java?rev=891796&r1=891795&r2=891796&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerDelTest.java
Thu Dec 17 16:47:42 2009
@@ -110,7 +110,7 @@
     }
 
 
-    private boolean isATPresent( SchemaManager schemaManager, String oid )
+    private boolean isAttributeTypePresent( SchemaManager schemaManager, String oid )
     {
         try
         {
@@ -128,8 +128,46 @@
         }
     }
 
+    
+    private boolean isComparatorPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            LdapComparator<?> comparator = schemaManager.lookupComparatorRegistry(
oid );
+
+            return comparator != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+    
+    private boolean isNormalizerPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            Normalizer normalizer = schemaManager.lookupNormalizerRegistry( oid );
+
+            return normalizer != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
 
-    private boolean isMRPresent( SchemaManager schemaManager, String oid )
+
+    private boolean isMatchingRulePresent( SchemaManager schemaManager, String oid )
     {
         try
         {
@@ -146,15 +184,34 @@
             return false;
         }
     }
+    
+    
+    private boolean isSyntaxPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry( oid );
+
+            return syntax != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
 
     
-    private boolean isCPresent( SchemaManager schemaManager, String oid )
+    private boolean isSyntaxCheckerPresent( SchemaManager schemaManager, String oid )
     {
         try
         {
-            LdapComparator<?> comparator = schemaManager.lookupComparatorRegistry(
oid );
+            SyntaxChecker syntaxChecker = schemaManager.lookupSyntaxCheckerRegistry( oid
);
 
-            return comparator != null;
+            return syntaxChecker != null;
         }
         catch ( NoSuchAttributeException nsae )
         {
@@ -220,7 +277,7 @@
         // It should not fail
         assertTrue( schemaManager.delete( attributeType ) );
 
-        assertFalse( isATPresent( schemaManager, "generationQualifier" ) );
+        assertFalse( isAttributeTypePresent( schemaManager, "generationQualifier" ) );
         assertEquals( atrSize - 1, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
     }
@@ -244,7 +301,7 @@
         // It should fail
         assertFalse( schemaManager.delete( attributeType ) );
 
-        assertTrue( isATPresent( schemaManager, "cn" ) );
+        assertTrue( isAttributeTypePresent( schemaManager, "cn" ) );
         assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
@@ -268,7 +325,7 @@
         // It should fail
         assertFalse( schemaManager.delete( attributeType ) );
 
-        assertFalse( isATPresent( schemaManager, "gecos" ) );
+        assertFalse( isAttributeTypePresent( schemaManager, "gecos" ) );
         assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
@@ -292,7 +349,7 @@
         // It should fail
         assertFalse( schemaManager.delete( attributeType ) );
 
-        assertTrue( isATPresent( schemaManager, "modifiersName" ) );
+        assertTrue( isAttributeTypePresent( schemaManager, "modifiersName" ) );
         assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
@@ -379,7 +436,7 @@
      * can be removed
      */
     @Test
-    public void testDeleteExistingComaparatorUsedByRemovedMatchingRule() throws Exception
+    public void testDeleteExistingComparatorUsedByRemovedMatchingRule() throws Exception
     {
         SchemaManager schemaManager = loadSchema( "system" );
         int ctrSize = schemaManager.getComparatorRegistry().size();
@@ -389,8 +446,8 @@
         String OID = "2.5.13.33";
 
         // Check that the MR and C are present
-        assertTrue( isMRPresent( schemaManager, OID ) );
-        assertTrue( isCPresent( schemaManager, OID ) );
+        assertTrue( isMatchingRulePresent( schemaManager, OID ) );
+        assertTrue( isComparatorPresent( schemaManager, OID ) );
 
         // Now try to remove the C
         LdapComparator<?> lc = schemaManager.lookupComparatorRegistry( OID );
@@ -409,12 +466,12 @@
         assertEquals( mrrSize - 1, schemaManager.getMatchingRuleRegistry().size() );
         assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
 
-        assertFalse( isMRPresent( schemaManager, OID ) );
+        assertFalse( isMatchingRulePresent( schemaManager, OID ) );
         
         // and try to delete the Comparator again
         assertTrue( schemaManager.delete( lc ) );
 
-        assertFalse( isCPresent( schemaManager, OID ) );
+        assertFalse( isComparatorPresent( schemaManager, OID ) );
         assertEquals( ctrSize - 1, schemaManager.getComparatorRegistry().size() );
         assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
     }
@@ -566,6 +623,53 @@
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
 
+    
+    /**
+     * Check that a Normalizer which has been used by a deleted MatchingRule
+     * can be removed
+     */
+    @Test
+    public void testDeleteExistingNormalizerUsedByRemovedMatchingRule() throws Exception
+    {
+        SchemaManager schemaManager = loadSchema( "system" );
+        int nrSize = schemaManager.getNormalizerRegistry().size();
+        int mrrSize = schemaManager.getMatchingRuleRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+        
+        String OID = "2.5.13.33";
+
+        // Check that the MR and N are present
+        assertTrue( isMatchingRulePresent( schemaManager, OID ) );
+        assertTrue( isNormalizerPresent( schemaManager, OID ) );
+
+        // Now try to remove the N
+        Normalizer normalizer = schemaManager.lookupNormalizerRegistry( OID );
+        
+        // shouldn't be deleted cause there is a MR associated with it
+        assertFalse( schemaManager.delete( normalizer ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertFalse( errors.isEmpty() );
+        assertTrue( errors.get( 0 ) instanceof LdapSchemaViolationException );
+
+        // Now delete the using MR : it should be OK
+        MatchingRule mr = new MatchingRule( OID );
+        assertTrue( schemaManager.delete( mr ) );
+
+        assertEquals( mrrSize - 1, schemaManager.getMatchingRuleRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+
+        assertFalse( isMatchingRulePresent( schemaManager, OID ) );
+        
+        // and try to delete the normalizer again
+        assertTrue( schemaManager.delete( normalizer ) );
+
+        assertFalse( isNormalizerPresent( schemaManager, OID ) );
+        assertEquals( nrSize - 1, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+    }
+    
+
     //=========================================================================
     // ObjectClass deletion tests
     //-------------------------------------------------------------------------
@@ -731,6 +835,53 @@
         assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
     }
 
+
+    /**
+     * Check that a SyntaxChecker which has been used by a deleted Syntax
+     * can be removed
+     */
+    @Test
+    public void testDeleteExistingSyntaxCheckerUsedByRemovedSyntax() throws Exception
+    {
+        SchemaManager schemaManager = loadSchema( "system" );
+        int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
+        int srSize = schemaManager.getLdapSyntaxRegistry().size();
+        int goidSize = schemaManager.getGlobalOidRegistry().size();
+        
+        String OID = "1.3.6.1.4.1.1466.115.121.1.33";
+
+        // Check that the S and SC are present
+        assertTrue( isSyntaxCheckerPresent( schemaManager, OID ) );
+        assertTrue( isSyntaxPresent( schemaManager, OID ) );
+
+        // Now try to remove the SC
+        SyntaxChecker sc = schemaManager.lookupSyntaxCheckerRegistry( OID );
+        
+        // shouldn't be deleted cause there is a S associated with it
+        assertFalse( schemaManager.delete( sc ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertFalse( errors.isEmpty() );
+        assertTrue( errors.get( 0 ) instanceof LdapSchemaViolationException );
+
+        // Now delete the using S : it should be OK
+        LdapSyntax syntax = new LdapSyntax( OID );
+        assertTrue( schemaManager.delete( syntax ) );
+
+        assertEquals( srSize - 1, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+
+        assertFalse( isSyntaxPresent( schemaManager, OID ) );
+        
+        // and try to delete the SC again
+        assertTrue( schemaManager.delete( sc ) );
+
+        assertFalse( isSyntaxCheckerPresent( schemaManager, OID ) );
+        assertEquals( scrSize - 1, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
+    }
+    
+
     //=========================================================================
     // SyntaxChecker deletion tests
     //-------------------------------------------------------------------------

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java?rev=891796&r1=891795&r2=891796&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LdapSyntax.java
Thu Dec 17 16:47:42 2009
@@ -220,6 +220,32 @@
             }
         }
     }
+    
+    
+    /**
+     * Remove the SDyntax from the registries, updating the references to
+     * other SchemaObject.
+     * 
+     * If one of the referenced SchemaObject does not exist (), 
+     * an exception is thrown.
+     *
+     * @param registries The Registries
+     * @exception If the Syntx is not valid 
+     */
+    public void removeFromRegistries( List<Throwable> errors, Registries registries
) throws NamingException
+    {
+        if ( registries != null )
+        {
+            /**
+             * Remove the Syntax references (using and usedBy) : 
+             * S -> SC
+             */
+            if ( syntaxChecker != null )
+            {
+                registries.delReference( this, syntaxChecker );
+            }
+        }
+    }
 
 
     /**

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java?rev=891796&r1=891795&r2=891796&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/MatchingRule.java
Thu Dec 17 16:47:42 2009
@@ -28,7 +28,6 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.comparators.ComparableComparator;
 import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
-import org.apache.directory.shared.ldap.schema.registries.MatchingRuleRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 
 
@@ -198,8 +197,6 @@
     {
         if ( registries != null )
         {
-            MatchingRuleRegistry matchingRuleRegistry = registries.getMatchingRuleRegistry();
-
             /**
              * Remove the MR references (using and usedBy) : 
              * MR -> C



Mime
View raw message