directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r890020 - 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/registries/Registries.java
Date Sun, 13 Dec 2009 02:26:52 GMT
Author: elecharny
Date: Sun Dec 13 02:26:51 2009
New Revision: 890020

URL: http://svn.apache.org/viewvc?rev=890020&view=rev
Log:
o Implemented the last test for OC addition
o Fixed the check for AT in MAY and in one of the OC's MUST

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/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=890020&r1=890019&r2=890020&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
Sun Dec 13 02:26:51 2009
@@ -1642,16 +1642,75 @@
 
 
     /**
-     * Addition of an OC with some AT present in one of its superiors' MAY or MUST 
+     * Addition of an OC with some AT present in MUST and in MAY in one of its
+     * superior
      */
     @Test
-    public void testAddObjectClassSuperiorsATPresentInSuperiors() throws Exception
+    public void testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay() throws Exception
     {
         SchemaManager schemaManager = loadSystem();
         int ocrSize = schemaManager.getObjectClassRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        // TODO
+        ObjectClass objectClass = new ObjectClass( "1.1.1" );
+        objectClass.setNames( "Test" );
+        objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
+        objectClass.addSuperiorOids( "alias", "OpenLDAProotDSE" );
+        objectClass.addMustAttributeTypeOids( "aliasedObjectName", "cn" );
+
+        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( 2, added.getSuperiors().size() );
+
+        Set<String> expectedSups = new HashSet<String>();
+        expectedSups.add( "alias" );
+        expectedSups.add( "OpenLDAProotDSE" );
+
+        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() );
+    }
+
+
+    /**
+     * Addition of an OC with some AT present in MAY and in MUST in one of its
+     * superior : not allowed
+     */
+    @Test
+    public void testAddObjectClassSuperiorsATInMayPresentInSuperiorsMust() throws Exception
+    {
+        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", "OpenLDAProotDSE" );
+        objectClass.addMayAttributeTypeOids( "aliasedObjectName", "cn" );
+
+        assertFalse( schemaManager.add( objectClass ) );
+
+        assertEquals( 1, schemaManager.getErrors().size() );
+
+        assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaViolationException
);
+
+        assertFalse( isOCPresent( schemaManager, "1.1.1" ) );
+
+        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/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=890020&r1=890019&r2=890020&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
Sun Dec 13 02:26:51 2009
@@ -1183,6 +1183,35 @@
     }
 
 
+    private List<AttributeType> getMustRecursive( List<AttributeType> musts,
Set<ObjectClass> processed,
+        ObjectClass objectClass )
+    {
+        if ( objectClass != null )
+        {
+            if ( processed.contains( objectClass ) )
+            {
+                // We have found a cycle. It has already been reported, 
+                // don't add a new error, just exit.
+                return null;
+            }
+
+            processed.add( objectClass );
+
+            for ( AttributeType must : objectClass.getMustAttributeTypes() )
+            {
+                musts.add( must );
+            }
+
+            for ( ObjectClass superior : objectClass.getSuperiors() )
+            {
+                getMustRecursive( musts, processed, superior );
+            }
+        }
+
+        return musts;
+    }
+
+
     private void resolve( ObjectClass objectClass, List<Throwable> errors )
     {
         // This set is used to avoid having more than one error
@@ -1195,6 +1224,27 @@
 
         // Call the recursive method, as we may have superiors to deal with
         resolveRecursive( objectClass, processed, errors );
+
+        // Check that the MAY and MUST AT are consistent (no AT in MAY and in MUST
+        // in one of its superior
+        List<AttributeType> musts = getMustRecursive( new ArrayList<AttributeType>(),
new HashSet<ObjectClass>(),
+            objectClass );
+
+        if ( musts != null )
+        {
+            for ( AttributeType may : objectClass.getMayAttributeTypes() )
+            {
+                if ( musts.contains( may ) )
+                {
+                    // This is not allowed.
+                    Throwable error = new LdapSchemaViolationException( "The ObjectClass
" + objectClass.getOid()
+                        + " has some AttribteType in MAY which is already declared" + " in
one of its superior MUST",
+                        ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+                    errors.add( error );
+                    return;
+                }
+            }
+        }
     }
 
 



Mime
View raw message