directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889618 - 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/SchemaManagerAddTest.java
Date Fri, 11 Dec 2009 13:51:31 GMT
Author: elecharny
Date: Fri Dec 11 13:51:31 2009
New Revision: 889618

URL: http://svn.apache.org/viewvc?rev=889618&view=rev
Log:
o Added a test to check that we can add an AT with a name already attributed to an OC
o Fixed a nasty bugs : the copied SO was deleted when clearing the ClonedRegistries, removing
all the names and references into it... We need to copy the SO twice (not optimal, but who
cares ?)

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/SchemaManagerAddTest.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=889618&r1=889617&r2=889618&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
Fri Dec 11 13:51:31 2009
@@ -1415,20 +1415,10 @@
     }
 
 
-    //-----------------------------------------------------------------------------------
-    // SchemaObject operations
-    //-----------------------------------------------------------------------------------
-    /**
-     * {@inheritDoc}
-     */
-    public boolean add( SchemaObject schemaObject ) throws Exception
+    private SchemaObject copy( SchemaObject schemaObject )
     {
-        // First, clear the errors
-        errors.clear();
-
         SchemaObject copy = null;
 
-        // Clone the schemaObject
         if ( !( schemaObject instanceof LoadableSchemaObject ) )
         {
             copy = schemaObject.copy();
@@ -1446,11 +1436,32 @@
                 Throwable error = new LdapOperationNotSupportedException( "the SchemaObject
" + schemaObject.getOid()
                     + " canot be added, it's not a valid LoadableSchemaObject.", ResultCodeEnum.UNWILLING_TO_PERFORM
);
                 errors.add( error );
-
-                return false;
             }
         }
 
+        return copy;
+    }
+
+
+    //-----------------------------------------------------------------------------------
+    // SchemaObject operations
+    //-----------------------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public boolean add( SchemaObject schemaObject ) throws Exception
+    {
+        // First, clear the errors
+        errors.clear();
+
+        // Clone the schemaObject
+        SchemaObject copy = copy( schemaObject );
+
+        if ( copy == null )
+        {
+            return false;
+        }
+
         if ( registries.isRelaxed() )
         {
             // Apply the addition right away
@@ -1504,6 +1515,9 @@
                 // If we didn't get any error, apply the addition to the real retistries
                 if ( errors.isEmpty() )
                 {
+                    // Copy again as the clonedRegistries clear has removed the previous
copy
+                    copy = copy( schemaObject );
+
                     // Apply the addition to the real registries
                     registries.add( errors, copy );
 

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=889618&r1=889617&r2=889618&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 13:51:31 2009
@@ -469,7 +469,7 @@
 
 
     /**
-     * Try to inject an AttributeType whith a already attributed name
+     * Try to inject an AttributeType with an already attributed name
      */
     @Test
     public void testAddAttributeTypeNameAlreadyExist() throws Exception
@@ -502,6 +502,42 @@
     }
 
 
+    /**
+     * Try to inject an AttributeType with an ObjectClass name
+     */
+    @Test
+    public void testAddAttributeTypeNameOfAnObjectClass() 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", "referral" );
+
+        // It should be ok
+        assertTrue( schemaManager.add( attributeType ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+
+        // The AT must be present
+        assertTrue( isATPresent( schemaManager, "1.1.1.0" ) );
+
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+
+        AttributeType added = schemaManager.lookupAttributeTypeRegistry( "referral" );
+        assertNotNull( added );
+        assertEquals( "1.1.1.0", added.getOid() );
+        assertTrue( added.getNames().contains( "referral" ) );
+    }
+
+
     //-------------------------------------------------------------------------
     // Then, with a superior
     //-------------------------------------------------------------------------



Mime
View raw message