directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889873 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
Date Sat, 12 Dec 2009 01:12:49 GMT
Author: elecharny
Date: Sat Dec 12 01:12:48 2009
New Revision: 889873

URL: http://svn.apache.org/viewvc?rev=889873&view=rev
Log:
We don't allow the same AT to be present twice in MAY and MUST for an OC

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/ObjectClass.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=889873&r1=889872&r2=889873&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
Sat Dec 12 01:12:48 2009
@@ -1349,32 +1349,15 @@
         ObjectClass objectClass = new ObjectClass( "1.1.1" );
         objectClass.addMayAttributeTypeOids( "cn", "ref", "commonName" );
 
-        assertTrue( schemaManager.add( objectClass ) );
-
-        assertEquals( 0, schemaManager.getErrors().size() );
-
-        assertTrue( isOCPresent( schemaManager, "1.1.1" ) );
-
-        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+        assertFalse( schemaManager.add( objectClass ) );
 
-        assertNotNull( added );
+        assertEquals( 1, schemaManager.getErrors().size() );
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
 
-        assertNotNull( added.getMayAttributeTypes() );
-        assertEquals( 2, added.getMayAttributeTypes().size() );
-        Set<String> expectedAT = new HashSet<String>();
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
 
-        expectedAT.add( "cn" );
-        expectedAT.add( "ref" );
-
-        for ( AttributeType attributeType : added.getMayAttributeTypes() )
-        {
-            assertTrue( expectedAT.contains( attributeType.getName() ) );
-
-            expectedAT.remove( attributeType.getName() );
-        }
-
-        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
-        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1391,32 +1374,15 @@
         ObjectClass objectClass = new ObjectClass( "1.1.1" );
         objectClass.addMustAttributeTypeOids( "cn", "ref", "2.5.4.3" );
 
-        assertTrue( schemaManager.add( objectClass ) );
-
-        assertEquals( 0, schemaManager.getErrors().size() );
-
-        assertTrue( isOCPresent( schemaManager, "1.1.1" ) );
-
-        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+        assertFalse( schemaManager.add( objectClass ) );
 
-        assertNotNull( added );
+        assertEquals( 1, schemaManager.getErrors().size() );
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
 
-        assertNotNull( added.getMustAttributeTypes() );
-        assertEquals( 2, added.getMustAttributeTypes().size() );
-        Set<String> expectedAT = new HashSet<String>();
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
 
-        expectedAT.add( "cn" );
-        expectedAT.add( "ref" );
-
-        for ( AttributeType attributeType : added.getMustAttributeTypes() )
-        {
-            assertTrue( expectedAT.contains( attributeType.getName() ) );
-
-            expectedAT.remove( attributeType.getName() );
-        }
-
-        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
-        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java?rev=889873&r1=889872&r2=889873&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/ObjectClass.java
Sat Dec 12 01:12:48 2009
@@ -25,6 +25,8 @@
 
 import javax.naming.NamingException;
 
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.schema.registries.ObjectClassRegistry;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
@@ -149,52 +151,48 @@
             {
                 mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size()
);
 
-                List<String> toRemove = new ArrayList<String>();
-
                 for ( String mayAttributeTypeName : mayAttributeTypeOids )
                 {
                     AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName
);
 
                     if ( mayAttributeTypes.contains( attributeType ) )
                     {
-                        // Already registrred : skip it and remove it from the OIDs list
-                        toRemove.add( mayAttributeTypeName );
-                        continue;
+                        // Already registered : this is an error
+                        String msg = "Cannot register the SchemaOject " + oid
+                            + ", there are some duplicate AT in the MAY : " + mayAttributeTypeName;
+
+                        Throwable error = new LdapSchemaViolationException( msg,
+                            ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                        errors.add( error );
+                        break;
                     }
 
                     mayAttributeTypes.add( attributeType );
                 }
-
-                for ( String oid : toRemove )
-                {
-                    mayAttributeTypeOids.remove( oid );
-                }
             }
 
             if ( mustAttributeTypeOids != null )
             {
                 mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size()
);
 
-                List<String> toRemove = new ArrayList<String>();
-
                 for ( String mustAttributeTypeName : mustAttributeTypeOids )
                 {
                     AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName
);
 
                     if ( mustAttributeTypes.contains( attributeType ) )
                     {
-                        // Already registrred : skip it and remove it from the OIDs list
-                        toRemove.add( mustAttributeTypeName );
-                        continue;
+                        // Already registered : this is an error
+                        String msg = "Cannot register the SchemaOject " + oid
+                            + ", there are some duplicate AT in the MUST : " + mustAttributeTypeName;
+
+                        Throwable error = new LdapSchemaViolationException( msg,
+                            ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                        errors.add( error );
+                        break;
                     }
 
                     mustAttributeTypes.add( attributeType );
                 }
-
-                for ( String oid : toRemove )
-                {
-                    mustAttributeTypeOids.remove( oid );
-                }
             }
 
             /**



Mime
View raw message