directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889575 - 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/ ldap/src/main/java/org/apache/directory/shared/ldap/sche...
Date Fri, 11 Dec 2009 11:13:14 GMT
Author: elecharny
Date: Fri Dec 11 11:13:14 2009
New Revision: 889575

URL: http://svn.apache.org/viewvc?rev=889575&view=rev
Log:
o Fixed the name collision discovery, which was missing
o Added some test for AttributeType and Syntax
o Added a setNames(String...) method to SchemaObject for convenience
o Improved the Error handling in register()

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchemaObjectRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java?rev=889575&r1=889574&r2=889575&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
Fri Dec 11 11:13:14 2009
@@ -468,6 +468,40 @@
     }
 
 
+    /**
+     * Try to inject an AttributeType whith a already attributed name
+     */
+    @Test
+    public void testAddAttributeTypeNameAlreadyExist() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int atrSize = schemaManager.getAttributeTypeRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        AttributeType attributeType = new AttributeType( "1.1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( "2.5.13.1" );
+        attributeType.setSubstringOid( "2.5.13.1" );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setNames( "Test", "cn" );
+
+        // It should fail
+        assertFalse( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+
+        // The AT must not be there
+        assertFalse( isATPresent( schemaManager, "1.1.1.0" ) );
+
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
     //-------------------------------------------------------------------------
     // Then, with a superior
     //-------------------------------------------------------------------------
@@ -843,7 +877,8 @@
     // Syntax addition tests
     //-------------------------------------------------------------------------
     /**
-     * Try to inject a new valid Syntax
+     * Try to inject a new valid Syntax, with no SC : the associated SC 
+     * will be the default OctetString SC
      */
     @Test
     public void testAddValidSyntax() throws Exception
@@ -853,7 +888,6 @@
         int goidSize = schemaManager.getOidRegistry().size();
 
         LdapSyntax syntax = new LdapSyntax( "1.1.0" );
-        //syntax.setSyntaxChecker( new RegexSyntaxChecker( "1.1.0" ) );
 
         // It should not fail
         assertTrue( schemaManager.add( syntax ) );
@@ -872,6 +906,31 @@
     }
 
 
+    /**
+     * Try to inject a Syntax with an existing OID
+     */
+    @Test
+    public void testAddSyntaxExistingOid() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int sSize = schemaManager.getLdapSyntaxRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        LdapSyntax syntax = new LdapSyntax( "2.5.4.3" );
+
+        // It should fail
+        assertFalse( schemaManager.add( syntax ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
+
+        assertTrue( error instanceof LdapSchemaViolationException );
+        assertEquals( sSize, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+    }
+
+
     //=========================================================================
     // SyntaxChecker addition tests
     //-------------------------------------------------------------------------

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java?rev=889575&r1=889574&r2=889575&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/AbstractSchemaObject.java
Fri Dec 11 11:13:14 2009
@@ -304,6 +304,32 @@
 
 
     /**
+     * Sets the list of names for this SchemaObject. The names are
+     * lowercased and trimmed.
+     *  
+     * @param names The list of names.
+     */
+    public void setNames( String... names )
+    {
+        if ( names == null )
+        {
+            return;
+        }
+
+        if ( !isReadOnly )
+        {
+            for ( String name : names )
+            {
+                if ( name != null )
+                {
+                    this.names.add( name );
+                }
+            }
+        }
+    }
+
+
+    /**
      * Gets a short description about this SchemaObject.
      * 
      * @return a short description about this SchemaObject

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchemaObjectRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchemaObjectRegistry.java?rev=889575&r1=889574&r2=889575&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchemaObjectRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultSchemaObjectRegistry.java
Fri Dec 11 11:13:14 2009
@@ -27,6 +27,8 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.LoadableSchemaObject;
 import org.apache.directory.shared.ldap.schema.SchemaObject;
 import org.apache.directory.shared.ldap.schema.SchemaObjectType;
@@ -195,7 +197,7 @@
         {
             String msg = schemaObjectType.name() + " with OID " + oid + " already registered!";
             LOG.warn( msg );
-            throw new NamingException( msg );
+            throw new LdapSchemaViolationException( msg, ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS
);
         }
 
         byName.put( oid, schemaObject );
@@ -206,7 +208,18 @@
          */
         for ( String name : schemaObject.getNames() )
         {
-            byName.put( StringTools.trim( StringTools.toLowerCase( name ) ), schemaObject
);
+            String lowerName = StringTools.trim( StringTools.toLowerCase( name ) );
+
+            if ( byName.containsKey( lowerName ) )
+            {
+                String msg = schemaObjectType.name() + " with name " + name + " already registered!";
+                LOG.warn( msg );
+                throw new LdapSchemaViolationException( msg, ResultCodeEnum.ATTRIBUTE_OR_VALUE_EXISTS
);
+            }
+            else
+            {
+                byName.put( lowerName, schemaObject );
+            }
         }
 
         // And register the oid -> schemaObject relation

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=889575&r1=889574&r2=889575&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Fri Dec 11 11:13:14 2009
@@ -1480,56 +1480,65 @@
                 String msg = "Registering of " + schemaObject.getObjectType() + ":" + schemaObject.getOid()
                     + "failed, it's already present in the Registries";
                 LOG.error( msg );
-                throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+                Throwable error = new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
+                errors.add( error );
+                return;
             }
         }
 
-        // First call the specific registry's register method
-        switch ( schemaObject.getObjectType() )
+        try
         {
-            case ATTRIBUTE_TYPE:
-                attributeTypeRegistry.register( ( AttributeType ) schemaObject );
-                break;
+            // First call the specific registry's register method
+            switch ( schemaObject.getObjectType() )
+            {
+                case ATTRIBUTE_TYPE:
+                    attributeTypeRegistry.register( ( AttributeType ) schemaObject );
+                    break;
 
-            case COMPARATOR:
-                comparatorRegistry.register( ( LdapComparator<?> ) schemaObject );
-                break;
+                case COMPARATOR:
+                    comparatorRegistry.register( ( LdapComparator<?> ) schemaObject
);
+                    break;
 
-            case DIT_CONTENT_RULE:
-                ditContentRuleRegistry.register( ( DITContentRule ) schemaObject );
-                break;
+                case DIT_CONTENT_RULE:
+                    ditContentRuleRegistry.register( ( DITContentRule ) schemaObject );
+                    break;
 
-            case DIT_STRUCTURE_RULE:
-                ditStructureRuleRegistry.register( ( DITStructureRule ) schemaObject );
-                break;
+                case DIT_STRUCTURE_RULE:
+                    ditStructureRuleRegistry.register( ( DITStructureRule ) schemaObject
);
+                    break;
 
-            case LDAP_SYNTAX:
-                ldapSyntaxRegistry.register( ( LdapSyntax ) schemaObject );
-                break;
+                case LDAP_SYNTAX:
+                    ldapSyntaxRegistry.register( ( LdapSyntax ) schemaObject );
+                    break;
 
-            case MATCHING_RULE:
-                matchingRuleRegistry.register( ( MatchingRule ) schemaObject );
-                break;
+                case MATCHING_RULE:
+                    matchingRuleRegistry.register( ( MatchingRule ) schemaObject );
+                    break;
 
-            case MATCHING_RULE_USE:
-                matchingRuleUseRegistry.register( ( MatchingRuleUse ) schemaObject );
-                break;
+                case MATCHING_RULE_USE:
+                    matchingRuleUseRegistry.register( ( MatchingRuleUse ) schemaObject );
+                    break;
 
-            case NAME_FORM:
-                nameFormRegistry.register( ( NameForm ) schemaObject );
-                break;
+                case NAME_FORM:
+                    nameFormRegistry.register( ( NameForm ) schemaObject );
+                    break;
 
-            case NORMALIZER:
-                normalizerRegistry.register( ( Normalizer ) schemaObject );
-                break;
+                case NORMALIZER:
+                    normalizerRegistry.register( ( Normalizer ) schemaObject );
+                    break;
 
-            case OBJECT_CLASS:
-                objectClassRegistry.register( ( ObjectClass ) schemaObject );
-                break;
+                case OBJECT_CLASS:
+                    objectClassRegistry.register( ( ObjectClass ) schemaObject );
+                    break;
 
-            case SYNTAX_CHECKER:
-                syntaxCheckerRegistry.register( ( SyntaxChecker ) schemaObject );
-                break;
+                case SYNTAX_CHECKER:
+                    syntaxCheckerRegistry.register( ( SyntaxChecker ) schemaObject );
+                    break;
+            }
+        }
+        catch ( Exception e )
+        {
+            errors.add( e );
         }
     }
 



Mime
View raw message