directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889950 - 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 17:07:50 GMT
Author: elecharny
Date: Sat Dec 12 17:07:49 2009
New Revision: 889950

URL: http://svn.apache.org/viewvc?rev=889950&view=rev
Log:
o Added the missing tests for OC (except one)
o Reorganized the way OC are checked by creatig private methods for clarity
o Added controls for ObjectClassType

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=889950&r1=889949&r2=889950&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 17:07:49 2009
@@ -28,7 +28,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.NamingException;
 import javax.naming.directory.NoSuchAttributeException;
@@ -42,6 +44,7 @@
 import org.apache.directory.shared.ldap.schema.MatchingRule;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
@@ -1415,7 +1418,7 @@
     // Then, with superiors
     //-------------------------------------------------------------------------
     /**
-     * Addition of a valid OC
+     * Addition of a valid OC with some superiors
      */
     @Test
     public void testAddObjectClassSuperiorsValid() throws Exception
@@ -1423,6 +1426,36 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "alias", "referral", "top" );
+
+        assertTrue( schemaManager.add( objectClass ) );
+
+        assertEquals( 0, schemaManager.getErrors().size() );
+
+        ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );
+
+        assertNotNull( added );
+        assertTrue( added.getNames().contains( "Test" ) );
+        assertNotNull( added.getSuperiors() );
+        assertEquals( 3, added.getSuperiors().size() );
+
+        Set<String> expectedSups = new HashSet<String>();
+        expectedSups.add( "alias" );
+        expectedSups.add( "referral" );
+        expectedSups.add( "top" );
+
+        for ( ObjectClass addedOC : added.getSuperiors() )
+        {
+            assertTrue( expectedSups.contains( addedOC.getName() ) );
+            expectedSups.remove( addedOC.getName() );
+        }
+
+        assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1435,6 +1468,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "alias", "Test", "referral" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1447,6 +1494,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "alias", "referral", "2.5.6.1" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1459,6 +1520,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "alias", "refessal" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1471,6 +1546,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.ABSTRACT );
+        objectClass.addSuperiorOids( "extensibleObject" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1483,6 +1572,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.ABSTRACT );
+        objectClass.addSuperiorOids( "referral" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1495,6 +1598,20 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.AUXILIARY );
+        objectClass.addSuperiorOids( "referral" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
@@ -1507,11 +1624,25 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "extensibleObject" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
 
     /**
-     * Addition of an OC with a some AT present in one of its superiors' MAY or MUST 
+     * Addition of an OC with some AT present in one of its superiors' MAY or MUST 
      */
     @Test
     public void testAddObjectClassSuperiorsATPresentInSuperiors() throws Exception
@@ -1519,6 +1650,8 @@
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
+
+        // TODO
     }
 
 

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=889950&r1=889949&r2=889950&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 17:07:49 2009
@@ -122,36 +122,98 @@
     }
 
 
-    /**
-     * Inject the ObjectClass into the registries, updating the references to
-     * other SchemaObject
-     *
-     * @param registries The Registries
-     * @throws Exception on failure
-     *
-     */
-    public void addToRegistries( List<Throwable> errors, Registries registries ) throws
NamingException
+    private void buildSuperiors( List<Throwable> errors, Registries registries )
     {
-        if ( registries != null )
+        ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+
+        if ( superiorOids != null )
         {
-            AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
-            ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
+            superiors = new ArrayList<ObjectClass>( superiorOids.size() );
 
-            if ( superiorOids != null )
+            for ( String superiorName : superiorOids )
             {
-                superiors = new ArrayList<ObjectClass>( superiorOids.size() );
+                try
+                {
+                    ObjectClass superior = ocRegistry.lookup( ocRegistry.getOidByName( superiorName
) );
+
+                    // Before adding the superior, check that the ObjectClass type is consistent
+                    switch ( objectClassType )
+                    {
+                        case ABSTRACT:
+                            if ( superior.objectClassType != ObjectClassTypeEnum.ABSTRACT
)
+                            {
+                                // An ABSTRACT OC can only inherit from ABSTRACT OCs
+                                String msg = "Cannot register the SchemaOject " + oid + ",
an ABSTRACT ObjectClass "
+                                    + "cannot inherit from an " + superior.getObjectType()
+ " ObjectClass :/n "
+                                    + superior;
+
+                                Throwable error = new LdapSchemaViolationException( msg,
+                                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                                errors.add( error );
+                                return;
+                            }
+
+                            break;
+
+                        case AUXILIARY:
+                            if ( superior.objectClassType == ObjectClassTypeEnum.STRUCTURAL
)
+                            {
+                                // An AUXILIARY OC can only inherit from STRUCTURAL OCs
+                                String msg = "Cannot register the SchemaOject " + oid + ",
an AUXILIARY ObjectClass "
+                                    + "cannot inherit from a STRUCTURAL ObjectClass :/n "
+ superior;
+
+                                Throwable error = new LdapSchemaViolationException( msg,
+                                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                                errors.add( error );
+                                return;
+                            }
+
+                            break;
+
+                        case STRUCTURAL:
+                            if ( superior.objectClassType == ObjectClassTypeEnum.AUXILIARY
)
+                            {
+                                // A STRUCTURAL OC can only inherit from AUXILIARY OCs
+                                String msg = "Cannot register the SchemaOject " + oid + ",
a STRUCTURAL ObjectClass "
+                                    + "cannot inherit from an AUXILIARY ObjectClass :/n "
+ superior;
+
+                                Throwable error = new LdapSchemaViolationException( msg,
+                                    ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                                errors.add( error );
+                                return;
+                            }
 
-                for ( String superiorName : superiorOids )
+                            break;
+                    }
+
+                    superiors.add( superior );
+                }
+                catch ( NamingException ne )
                 {
-                    superiors.add( ocRegistry.lookup( ocRegistry.getOidByName( superiorName
) ) );
+                    // Cannot find the OC
+                    String msg = "Cannot register the SchemaOject " + oid + ", the given
SUPERIOR does not exist : "
+                        + superiorName;
+
+                    Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX
);
+                    errors.add( error );
+                    return;
                 }
             }
+        }
+    }
 
-            if ( mayAttributeTypeOids != null )
-            {
-                mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size()
);
 
-                for ( String mayAttributeTypeName : mayAttributeTypeOids )
+    private void buildMay( List<Throwable> errors, Registries registries )
+    {
+        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+        if ( mayAttributeTypeOids != null )
+        {
+            mayAttributeTypes = new ArrayList<AttributeType>( mayAttributeTypeOids.size()
);
+
+            for ( String mayAttributeTypeName : mayAttributeTypeOids )
+            {
+                try
                 {
                     AttributeType attributeType = atRegistry.lookup( mayAttributeTypeName
);
 
@@ -169,13 +231,32 @@
 
                     mayAttributeTypes.add( attributeType );
                 }
+                catch ( NamingException ne )
+                {
+                    // Cannot find the AT
+                    String msg = "Cannot register the SchemaOject " + oid
+                        + ", the AT we want to add to MAY does not exist : " + mayAttributeTypeName;
+
+                    Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX
);
+                    errors.add( error );
+                    break;
+                }
             }
+        }
+    }
 
-            if ( mustAttributeTypeOids != null )
-            {
-                mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size()
);
 
-                for ( String mustAttributeTypeName : mustAttributeTypeOids )
+    private void buildMust( List<Throwable> errors, Registries registries )
+    {
+        AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
+
+        if ( mustAttributeTypeOids != null )
+        {
+            mustAttributeTypes = new ArrayList<AttributeType>( mustAttributeTypeOids.size()
);
+
+            for ( String mustAttributeTypeName : mustAttributeTypeOids )
+            {
+                try
                 {
                     AttributeType attributeType = atRegistry.lookup( mustAttributeTypeName
);
 
@@ -206,7 +287,41 @@
 
                     mustAttributeTypes.add( attributeType );
                 }
+                catch ( NamingException ne )
+                {
+                    // Cannot find the AT
+                    String msg = "Cannot register the SchemaOject " + oid
+                        + ", the AT we want to add to MUST does not exist : " + mustAttributeTypeName;
+
+                    Throwable error = new LdapSchemaViolationException( msg, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX
);
+                    errors.add( error );
+                    break;
+                }
             }
+        }
+    }
+
+
+    /**
+     * Inject the ObjectClass into the registries, updating the references to
+     * other SchemaObject
+     *
+     * @param registries The Registries
+     * @throws Exception on failure
+     *
+     */
+    public void addToRegistries( List<Throwable> errors, Registries registries ) throws
NamingException
+    {
+        if ( registries != null )
+        {
+            // The superiors
+            buildSuperiors( errors, registries );
+
+            // The MAY AttributeTypes
+            buildMay( errors, registries );
+
+            // The MUST AttributeTypes
+            buildMust( errors, registries );
 
             /**
              * Add the OC references (using and usedBy) : 



Mime
View raw message