directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r887004 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Date Fri, 04 Dec 2009 00:02:44 GMT
Author: elecharny
Date: Fri Dec  4 00:02:43 2009
New Revision: 887004

URL: http://svn.apache.org/viewvc?rev=887004&view=rev
Log:
o Fixed the Registries clone() method, the schema content was not being cloned
o Added some tests

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.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/SchemaManagerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java?rev=887004&r1=887003&r2=887004&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerTest.java
Fri Dec  4 00:02:43 2009
@@ -22,13 +22,15 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
+import javax.naming.NamingException;
+import javax.naming.directory.NoSuchAttributeException;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.schema.loader.ldif.LdifSchemaLoaderTest;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
@@ -107,6 +109,25 @@
     }
 
 
+    private boolean isATPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid
);
+
+            return attributeType != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+
     //=========================================================================
     // AttributeType addition tests
     //-------------------------------------------------------------------------
@@ -133,6 +154,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -155,7 +178,7 @@
         // It should not fail
         assertTrue( schemaManager.add( attributeType ) );
 
-        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -183,6 +206,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -210,6 +235,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -232,7 +259,7 @@
         // It should not fail
         assertTrue( schemaManager.add( attributeType ) );
 
-        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -259,6 +286,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -285,6 +314,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -311,6 +342,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -332,7 +365,38 @@
         // It should not fail
         assertTrue( schemaManager.add( attributeType ) );
 
-        assertNotNull( schemaManager.lookupAttributeTypeRegistry( "1.1.0" ) );
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
+    }
+
+
+    /**
+     * Try to inject an AttributeType which already exist
+     */
+    @Test
+    public void testAddAttributeTypeAlreadyExist() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+
+        AttributeType attributeType = new AttributeType( "2.5.18.4" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( "2.5.13.1" );
+        attributeType.setSubstringOid( "2.5.13.1" );
+
+        // 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 be there
+        assertTrue( isATPresent( schemaManager, "2.5.18.4" ) );
+
+        // Check that it hasen't changed
+        AttributeType original = schemaManager.lookupAttributeTypeRegistry( "2.5.18.4" );
+        assertEquals( "distinguishedNameMatch", original.getEqualityOid() );
     }
 
 
@@ -388,6 +452,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -414,6 +480,8 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 
 
@@ -440,5 +508,7 @@
         Throwable error = errors.get( 0 );
 
         assertTrue( error instanceof LdapSchemaViolationException );
+
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
     }
 }

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=887004&r1=887003&r2=887004&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  4 00:02:43 2009
@@ -2325,6 +2325,16 @@
         // Now, check the registries. We don't care about errors
         clone.checkRefInteg();
 
+        clone.schemaObjects = new HashMap<String, Set<SchemaObjectWrapper>>();
+
+        // Last, not least, clone the SchemaObjects Map. It will be empty
+        for ( String schemaName : schemaObjects.keySet() )
+        {
+            Set<SchemaObjectWrapper> objects = new HashSet<SchemaObjectWrapper>();
+
+            clone.schemaObjects.put( schemaName, objects );
+        }
+
         return clone;
     }
 



Mime
View raw message