directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r896599 [9/30] - in /directory/apacheds/trunk: ./ avl-partition/ avl-partition/src/ avl-partition/src/main/ avl-partition/src/main/java/ avl-partition/src/main/java/org/ avl-partition/src/main/java/org/apache/ avl-partition/src/main/java/or...
Date Wed, 06 Jan 2010 18:27:19 GMT
Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java Wed Jan  6 18:26:43 2010
@@ -20,23 +20,13 @@
 package org.apache.directory.server.core.schema;
 
 
-import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
-import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.runner.RunWith;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -45,6 +35,20 @@
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.StringComparator;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 
 /**
  * A test case which tests the addition of various schema elements
@@ -53,8 +57,8 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith ( CiRunner.class )
-public class MetaMatchingRuleHandlerIT
+@RunWith(FrameworkRunner.class)
+public class MetaMatchingRuleHandlerIT extends AbstractMetaSchemaObjectHandler
 {
     private static final String DESCRIPTION0 = "A test matchingRule";
     private static final String DESCRIPTION1 = "An alternate description";
@@ -63,208 +67,323 @@
     private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
 
 
-    public static DirectoryService service;
+    public static SchemaManager schemaManager;
 
 
-    private static MatchingRuleRegistry getMatchingRuleRegistry()
+    @Before
+    public void setup()
     {
-        return service.getRegistries().getMatchingRuleRegistry();
+        schemaManager = service.getSchemaManager();
     }
-    
-    
-    /**
-     * Gets relative DN to ou=schema.
-     * 
-     * @param schemaName the name of the schema
-     * @return  the dn of the container of matchingRules for a schema
-     * @throws Exception on error
-     */
-    private LdapDN getMatchingRuleContainer( String schemaName ) throws Exception
+
+
+    private void createComparator() throws Exception
     {
-        return new LdapDN( "ou=matchingRules,cn=" + schemaName );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaComparator",
+            "m-fqcn: " + StringComparator.class.getName(),
+            "m-oid: " + OID,
+            "m-description: A test comparator" );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+        
+        // Addition
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( isOnDisk( dn ) );
+        assertTrue( service.getSchemaManager().getComparatorRegistry().contains( OID ) );
     }
     
     
     // ----------------------------------------------------------------------
     // Test all core methods with normal operational pathways
     // ----------------------------------------------------------------------
+    // Test Add operation
+    // ----------------------------------------------------------------------
+    @Test
+    public void testAddMatchingRuleToEnabledSchema() throws Exception
+    {
+        createComparator();
+        
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaMatchingRule",
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0 );
 
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+        
+        // Pre-checks
+        assertFalse( isOnDisk( dn ) );
+        assertFalse( service.getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
 
+        // Addition
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        // Post-checks
+        assertTrue( service.getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+        assertEquals( service.getSchemaManager().getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+        assertTrue( isOnDisk( dn ) );
+    }
+    
+    
     @Test
-    public void testAddMatchingRule() throws Exception
+    public void testAddMatchingRuleToDisabledSchema() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT, "top" );
-        oc.add( MetaSchemaConstants.META_TOP_OC );
-        oc.add( MetaSchemaConstants.META_MATCHING_RULE_OC );
-        attrs.put( oc );
-        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
-        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, SchemaConstants.INTEGER_SYNTAX );
-        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        createComparator();
         
-        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaMatchingRule",
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0 );
+        
+        LdapDN dn = getMatchingRuleContainer( "nis" );
+        dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getMatchingRuleRegistry().hasMatchingRule( OID ) );
-        assertEquals( getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+        assertFalse( "adding new matchingRule to disabled schema should not register it into the registries", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
     }
     
-
+    
     @Test
-    public void testDeleteMatchingRule() throws Exception
+    public void testAddMatchingRuleToUnloadedSchema() throws Exception
     {
-        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddMatchingRule();
+        createComparator();
         
-        getSchemaContext( service ).destroySubcontext( dn );
-
-        assertFalse( "matchingRule should be removed from the registry after being deleted", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaMatchingRule",
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0 );
+        
+        LdapDN dn = getMatchingRuleContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
         
         try
         {
-            getMatchingRuleRegistry().lookup( OID );
-            fail( "matchingRule lookup should fail after deleting it" );
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
         }
-        catch( NamingException e )
+        catch( NameNotFoundException nnfe )
         {
+            // Expected result
         }
+        
+        assertFalse( "adding new matchingRule to disabled schema should not register it into the registries", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
     }
-
-
+    
+    
+    // ----------------------------------------------------------------------
+    // Test Delete operation
+    // ----------------------------------------------------------------------
     @Test
-    public void testRenameMatchingRule() throws Exception
+    public void testDeleteMatchingRuleFromEnabledSchema() throws Exception
     {
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddMatchingRule();
+        dn.add( "m-oid" + "=" + OID );
+        testAddMatchingRuleToEnabledSchema();
         
-        LdapDN newdn = getMatchingRuleContainer( "apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
-        getSchemaContext( service ).rename( dn, newdn );
+        assertTrue( "matchingRule should be removed from the registry after being deleted", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+        
+        getSchemaContext( service ).destroySubcontext( dn );
 
-        assertFalse( "old matchingRule OID should be removed from the registry after being renamed", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        assertFalse( "matchingRule should be removed from the registry after being deleted", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
         
         try
         {
-            getMatchingRuleRegistry().lookup( OID );
-            fail( "matchingRule lookup should fail after renaming the matchingRule" );
+            schemaManager.getMatchingRuleRegistry().lookup( OID );
+            fail( "matchingRule lookup should fail after deleting it" );
         }
         catch( NamingException e )
         {
         }
 
-        assertTrue( getMatchingRuleRegistry().hasMatchingRule( NEW_OID ) );
+        assertFalse( isOnDisk( dn ) );
     }
 
 
     @Test
-    public void testMoveMatchingRule() throws Exception
+    public void testDeleteMatchingRuleFromDisabledSchema() throws Exception
     {
-        testAddMatchingRule();
-        
-        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-
-        LdapDN newdn = getMatchingRuleContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        
-        getSchemaContext( service ).rename( dn, newdn );
-
-        assertTrue( "matchingRule OID should still be present", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
-        
-        assertEquals( "matchingRule schema should be set to apache not apachemeta", 
-            getMatchingRuleRegistry().getSchemaName( OID ), "apache" );
-    }
-
-
-    @Test
-    public void testMoveMatchingRuleAndChangeRdn() throws Exception
-    {
-        testAddMatchingRule();
+        LdapDN dn = getMatchingRuleContainer( "nis" );
+        dn.add( "m-oid" + "=" + OID );
+        testAddMatchingRuleToDisabledSchema();
         
-        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-
-        LdapDN newdn = getMatchingRuleContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        assertFalse( "matchingRule should be removed from the registry after being deleted", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
         
-        getSchemaContext( service ).rename( dn, newdn );
+        getSchemaContext( service ).destroySubcontext( dn );
 
-        assertFalse( "old matchingRule OID should NOT be present", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
-        
-        assertTrue( "new matchingRule OID should be present", 
-            getMatchingRuleRegistry().hasMatchingRule( NEW_OID ) );
-        
-        assertEquals( "matchingRule with new oid should have schema set to apache NOT apachemeta", 
-            getMatchingRuleRegistry().getSchemaName( NEW_OID ), "apache" );
+        assertFalse( "matchingRule should be removed from the registry after being deleted", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
     }
 
 
+    // ----------------------------------------------------------------------
+    // Test Modify operation
+    // ----------------------------------------------------------------------
     @Test
+    @Ignore
     public void testModifyMatchingRuleWithModificationItems() throws Exception
     {
-        testAddMatchingRule();
+        testAddMatchingRuleToEnabledSchema();
         
-        MatchingRule mr = getMatchingRuleRegistry().lookup( OID );
+        MatchingRule mr = schemaManager.getMatchingRuleRegistry().lookup( OID );
         assertEquals( mr.getDescription(), DESCRIPTION0 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
         
         ModificationItem[] mods = new ModificationItem[2];
-        Attribute attr = new BasicAttribute( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        Attribute attr = new BasicAttribute( "m-description", DESCRIPTION1 );
         mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        attr = new BasicAttribute( MetaSchemaConstants.M_SYNTAX_AT, SchemaConstants.DIRECTORY_STRING_SYNTAX );
+        attr = new BasicAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
         mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
         getSchemaContext( service ).modifyAttributes( dn, mods );
 
         assertTrue( "matchingRule OID should still be present", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
         
         assertEquals( "matchingRule schema should be set to apachemeta", 
-            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
         
-        mr = getMatchingRuleRegistry().lookup( OID );
+        mr = schemaManager.getMatchingRuleRegistry().lookup( OID );
         assertEquals( mr.getDescription(), DESCRIPTION1 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
     }
 
     
     @Test
+    @Ignore
     public void testModifyMatchingRuleWithAttributes() throws Exception
     {
-        testAddMatchingRule();
+        testAddMatchingRuleToEnabledSchema();
         
-        MatchingRule mr = getMatchingRuleRegistry().lookup( OID );
+        MatchingRule mr = schemaManager.getMatchingRuleRegistry().lookup( OID );
         assertEquals( mr.getDescription(), DESCRIPTION0 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
         
         Attributes mods = new BasicAttributes( true );
-        mods.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
-        mods.put( MetaSchemaConstants.M_SYNTAX_AT, SchemaConstants.DIRECTORY_STRING_SYNTAX );
+        mods.put( "m-description", DESCRIPTION1 );
+        mods.put( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
         getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
 
         assertTrue( "matchingRule OID should still be present", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
         
         assertEquals( "matchingRule schema should be set to apachemeta", 
-            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
 
-        mr = getMatchingRuleRegistry().lookup( OID );
+        mr = schemaManager.getMatchingRuleRegistry().lookup( OID );
         assertEquals( mr.getDescription(), DESCRIPTION1 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
     }
+
+
+    // ----------------------------------------------------------------------
+    // Test Rename operation
+    // ----------------------------------------------------------------------
+    @Test
+    @Ignore
+    public void testRenameMatchingRule() throws Exception
+    {
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+        testAddMatchingRuleToEnabledSchema();
+        
+        LdapDN newdn = getMatchingRuleContainer( "apachemeta" );
+        newdn.add( "m-oid" + "=" + NEW_OID );
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old matchingRule OID should be removed from the registry after being renamed", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        
+        try
+        {
+            schemaManager.getMatchingRuleRegistry().lookup( OID );
+            fail( "matchingRule lookup should fail after renaming the matchingRule" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( schemaManager.getMatchingRuleRegistry().contains( NEW_OID ) );
+    }
+
     
+    // ----------------------------------------------------------------------
+    // Test Move operation
+    // ----------------------------------------------------------------------
+    @Test
+    @Ignore
+    public void testMoveMatchingRule() throws Exception
+    {
+        testAddMatchingRuleToEnabledSchema();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+
+        LdapDN newdn = getMatchingRuleContainer( "apache" );
+        newdn.add( "m-oid" + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "matchingRule OID should still be present", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        
+        assertEquals( "matchingRule schema should be set to apache not apachemeta", 
+            schemaManager.getMatchingRuleRegistry().getSchemaName( OID ), "apache" );
+    }
+
+
+    @Test
+    @Ignore
+    public void testMoveMatchingRuleAndChangeRdn() throws Exception
+    {
+        testAddMatchingRuleToEnabledSchema();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+
+        LdapDN newdn = getMatchingRuleContainer( "apache" );
+        newdn.add( "m-oid" + "=" + NEW_OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old matchingRule OID should NOT be present", 
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        
+        assertTrue( "new matchingRule OID should be present", 
+            schemaManager.getMatchingRuleRegistry().contains( NEW_OID ) );
+        
+        assertEquals( "matchingRule with new oid should have schema set to apache NOT apachemeta", 
+            schemaManager.getMatchingRuleRegistry().getSchemaName( NEW_OID ), "apache" );
+    }
+
 
     // ----------------------------------------------------------------------
     // Test move, rename, and delete when a MR exists and uses the Normalizer
@@ -274,7 +393,7 @@
 //    public void testDeleteSyntaxWhenInUse() throws NamingException
 //    {
 //        LdapDN dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        dn.add( "m-oid" + "=" + OID );
 //        testAddSyntax();
 //        addDependeeMatchingRule();
 //        
@@ -289,7 +408,7 @@
 //        }
 //
 //        assertTrue( "syntax should still be in the registry after delete failure", 
-//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//            getLdapSyntaxRegistry().hasSyntax( OID ) );
 //    }
 //    
 //    
@@ -299,10 +418,10 @@
 //        addDependeeMatchingRule();
 //        
 //        LdapDN dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        dn.add( "m-oid" + "=" + OID );
 //
 //        LdapDN newdn = getSyntaxContainer( "apache" );
-//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        newdn.add( "m-oid" + "=" + OID );
 //        
 //        try
 //        {
@@ -315,7 +434,7 @@
 //        }
 //
 //        assertTrue( "syntax should still be in the registry after move failure", 
-//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//            registries.getLdapSyntaxRegistry().hasSyntax( OID ) );
 //    }
 //
 //
@@ -325,10 +444,10 @@
 //        addDependeeMatchingRule()
 //        
 //        LdapDN dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );s
+//        dn.add( "m-oid" + "=" + OID );s
 //
 //        LdapDN newdn = getSyntaxContainer( "apache" );
-//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        newdn.add( "m-oid" + "=" + NEW_OID );
 //        
 //        try
 //        {
@@ -357,12 +476,12 @@
 //    public void testRenameNormalizerWhenInUse() throws NamingException
 //    {
 //        LdapDN dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        dn.add( "m-oid" + "=" + OID );
 //        testAddSyntax();
 //        addDependeeMatchingRule();
 //        
 //        LdapDN newdn = getSyntaxContainer( "apachemeta" );
-//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        newdn.add( "m-oid" + "=" + NEW_OID );
 //        
 //        try
 //        {
@@ -385,15 +504,16 @@
 
 
     @Test
+    @Ignore
     public void testMoveMatchingRuleToTop() throws Exception
     {
-        testAddMatchingRule();
+        testAddMatchingRuleToEnabledSchema();
         
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN top = new LdapDN();
-        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        top.add( "m-oid" + "=" + OID );
         
         try
         {
@@ -406,20 +526,21 @@
         }
 
         assertTrue( "matchingRule should still be in the registry after move failure", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveMatchingRuleToComparatorContainer() throws Exception
     {
-        testAddMatchingRule();
+        testAddMatchingRuleToEnabledSchema();
         
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = new LdapDN( "ou=comparators,cn=apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         try
         {
@@ -432,71 +553,52 @@
         }
 
         assertTrue( "matchingRule should still be in the registry after move failure", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
     }
     
     
     @Test
-    public void testAddMatchingRuleToDisabledSchema() throws Exception
-    {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT, "top" );
-        oc.add( MetaSchemaConstants.META_TOP_OC );
-        oc.add( MetaSchemaConstants.META_MATCHING_RULE_OC );
-        attrs.put( oc );
-        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
-        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, SchemaConstants.INTEGER_SYNTAX );
-        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
-        
-        LdapDN dn = getMatchingRuleContainer( "nis" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        getSchemaContext( service ).createSubcontext( dn, attrs );
-        
-        assertFalse( "adding new matchingRule to disabled schema should not register it into the registries", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
-    }
-
-
-    @Test
+    @Ignore
     public void testMoveMatchingRuleToDisabledSchema() throws Exception
     {
-        testAddMatchingRule();
+        testAddMatchingRuleToEnabledSchema();
         
         LdapDN dn = getMatchingRuleContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         // nis is inactive by default
         LdapDN newdn = getMatchingRuleContainer( "nis" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "matchingRule OID should no longer be present", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveMatchingRuleToEnabledSchema() throws Exception
     {
         testAddMatchingRuleToDisabledSchema();
         
         // nis is inactive by default
         LdapDN dn = getMatchingRuleContainer( "nis" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         assertFalse( "matchingRule OID should NOT be present when added to disabled nis schema", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
 
         LdapDN newdn = getMatchingRuleContainer( "apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertTrue( "matchingRule OID should be present when moved to enabled schema", 
-            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+            schemaManager.getMatchingRuleRegistry().contains( OID ) );
         
         assertEquals( "matchingRule should be in apachemeta schema after move", 
-            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
     }
 }

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java Wed Jan  6 18:26:43 2010
@@ -20,31 +20,16 @@
 package org.apache.directory.server.core.schema;
 
 
-import org.apache.directory.server.constants.MetaSchemaConstants;
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
-import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
-import org.apache.directory.server.schema.registries.NormalizerRegistry;
-import org.apache.directory.server.schema.registries.OidRegistry;
-import org.apache.directory.shared.ldap.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
-import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.MatchingRule;
-import org.apache.directory.shared.ldap.schema.Normalizer;
-import org.apache.directory.shared.ldap.schema.Syntax;
-import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimNormalizer;
-import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
-
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.runner.RunWith;
 
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -53,9 +38,21 @@
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.util.Comparator;
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimNormalizer;
+import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 
 /**
@@ -65,254 +62,349 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith ( CiRunner.class )
-public class MetaNormalizerHandlerIT
+@RunWith(FrameworkRunner.class)
+public class MetaNormalizerHandlerIT extends AbstractMetaSchemaObjectHandler
 {
     private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
     private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
 
-
-    public static DirectoryService service;
-
-
-    /**
-     * Gets relative DN to ou=schema.
-     *
-     * @param schemaName the name of the schema
-     * @return  the name of the container with normalizer entries in it
-     * @throws Exception on error
-     */
-    private LdapDN getNormalizerContainer( String schemaName ) throws Exception
-    {
-        return new LdapDN( "ou=normalizers,cn=" + schemaName );
-    }
-    
-
-    private static NormalizerRegistry getNormalizerRegistry()
-    {
-        return service.getRegistries().getNormalizerRegistry();
-    }
-
-
-    private static MatchingRuleRegistry getMatchingRuleRegistry()
-    {
-        return service.getRegistries().getMatchingRuleRegistry();
-    }
+    public static SchemaManager schemaManager;
 
 
-    private static OidRegistry getOidRegistry()
+    @Before
+    public void setup()
     {
-        return service.getRegistries().getOidRegistry();
+        schemaManager = service.getSchemaManager();
     }
 
 
     // ----------------------------------------------------------------------
     // Test all core methods with normal operational pathways
     // ----------------------------------------------------------------------
-
-
     @Test
-    public void testAddNormalizer() throws Exception
+    public void testAddNormalizerToEnabledSchema() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT, "top" );
-        oc.add( MetaSchemaConstants.META_TOP_OC );
-        oc.add( MetaSchemaConstants.META_NORMALIZER_OC );
-        attrs.put( oc );
-        attrs.put( MetaSchemaConstants.M_FQCN_AT, NoOpNormalizer.class.getName() );
-        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
-        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", NoOpNormalizer.class.getName(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getNormalizerRegistry().hasNormalizer( OID ) );
-        assertEquals( getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
-        Class<?> clazz = getNormalizerRegistry().lookup( OID ).getClass();
+        assertTrue( schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertEquals( schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( OID ).getClass();
         assertEquals( clazz, NoOpNormalizer.class );
+        assertTrue( isOnDisk( dn ) );
+    }
+    
+    
+    @Test
+    public void testAddNormalizerToDisabledSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", NoOpNormalizer.class.getName(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
+        
+        // nis is by default inactive
+        LdapDN dn = getNormalizerContainer( "nis" );
+        dn.add( "m-oid" + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new normalizer to disabled schema should not register it into the registries", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+    }
+    
+    
+    @Test
+    public void testAddNormalizerToUnloadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", NoOpNormalizer.class.getName(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
+        
+        // nis is by default inactive
+        LdapDN dn = getNormalizerContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
+
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Expected result.
+        }
+        
+        assertFalse( "adding new normalizer to disabled schema should not register it into the registries", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
     }
     
     
     @Test
-    public void testAddNormalizerWithByteCode() throws Exception
+    public void testAddNormalizerWithByteCodeToEnabledSchema() throws Exception
     {
         InputStream in = getClass().getResourceAsStream( "DummyNormalizer.bytecode" );
         ByteArrayOutputStream out = new ByteArrayOutputStream();
+        
         while ( in.available() > 0 )
         {
             out.write( in.read() );
         }
         
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT, "top" );
-        oc.add( MetaSchemaConstants.META_TOP_OC );
-        oc.add( MetaSchemaConstants.META_NORMALIZER_OC );
-        attrs.put( oc );
-        attrs.put( MetaSchemaConstants.M_FQCN_AT, "DummyNormalizer" );
-        attrs.put( MetaSchemaConstants.M_BYTECODE_AT, out.toByteArray() );
-        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
-        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", "org.apache.directory.shared.ldap.schema.normalizers.DummyNormalizer",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertEquals( schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( OID ).getClass();
+        assertEquals( clazz.getName(), "org.apache.directory.shared.ldap.schema.normalizers.DummyNormalizer" );
+        assertTrue( isOnDisk( dn ) );
+    }
+    
+    
+    @Test
+    public void testAddNormalizerWithByteCodeToDisabledSchema() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "DummyNormalizer.bytecode" );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        
+        while ( in.available() > 0 )
+        {
+            out.write( in.read() );
+        }
+        
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaNormalizer",
+            "m-fqcn", "org.apache.directory.shared.ldap.schema.normalizers.DummyNormalizer",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test normalizer" );
+        
+        LdapDN dn = getNormalizerContainer( "nis" );
+        dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getNormalizerRegistry().hasNormalizer( OID ) );
-        assertEquals( getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
-        Class<?> clazz = getNormalizerRegistry().lookup( OID ).getClass();
-        assertEquals( clazz.getName(), "DummyNormalizer" );
+        assertFalse( schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
     }
     
     
     @Test
-    public void testDeleteNormalizer() throws Exception
+    public void testDeleteNormalizerFromEnabledSchema() throws Exception
     {
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddNormalizer();
+        dn.add( "m-oid" + "=" + OID );
+        testAddNormalizerToEnabledSchema();
+        
+        assertTrue( "normalizer should be removed from the registry after being deleted", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
         
         getSchemaContext( service ).destroySubcontext( dn );
 
         assertFalse( "normalizer should be removed from the registry after being deleted", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
 
-        //noinspection EmptyCatchBlock
         try
         {
-            getNormalizerRegistry().lookup( OID );
+            schemaManager.getNormalizerRegistry().lookup( OID );
             fail( "normalizer lookup should fail after deleting the normalizer" );
         }
         catch( NamingException e )
         {
         }
+
+        assertFalse( isOnDisk( dn ) );
     }
 
 
     @Test
+    public void testDeleteNormalizerFromDisabledSchema() throws Exception
+    {
+        LdapDN dn = getNormalizerContainer( "apachemeta" );
+        dn.add( "m-oid" + "=" + OID );
+        testAddNormalizerToEnabledSchema();
+
+        assertTrue( "normalizer should be removed from the registry after being deleted", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+        
+        getSchemaContext( service ).destroySubcontext( dn );
+
+        assertFalse( "normalizer should be removed from the registry after being deleted", 
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+
+        try
+        {
+            schemaManager.getNormalizerRegistry().lookup( OID );
+            fail( "normalizer lookup should fail after deleting the normalizer" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertFalse( isOnDisk( dn ) );
+    }
+
+
+    @Test
+    @Ignore
     public void testRenameNormalizer() throws Exception
     {
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddNormalizer();
+        dn.add( "m-oid" + "=" + OID );
+        testAddNormalizerToEnabledSchema();
         
         LdapDN newdn = getNormalizerContainer( "apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        newdn.add( "m-oid" + "=" + NEW_OID );
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "old normalizer OID should be removed from the registry after being renamed", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
 
         //noinspection EmptyCatchBlock
         try
         {
-            getNormalizerRegistry().lookup( OID );
+            schemaManager.getNormalizerRegistry().lookup( OID );
             fail( "normalizer lookup should fail after deleting the normalizer" );
         }
         catch( NamingException e )
         {
         }
 
-        assertTrue( getNormalizerRegistry().hasNormalizer( NEW_OID ) );
-        Class<?> clazz = getNormalizerRegistry().lookup( NEW_OID ).getClass();
+        assertTrue( schemaManager.getNormalizerRegistry().contains( NEW_OID ) );
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( NEW_OID ).getClass();
         assertEquals( clazz, NoOpNormalizer.class );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizer() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = getNormalizerContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertTrue( "normalizer OID should still be present", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
         
         assertEquals( "normalizer schema should be set to apache not apachemeta", 
-            getNormalizerRegistry().getSchemaName( OID ), "apache" );
+            schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apache" );
 
-        Class<?> clazz = getNormalizerRegistry().lookup( OID ).getClass();
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( OID ).getClass();
         assertEquals( clazz, NoOpNormalizer.class );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerAndChangeRdn() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = getNormalizerContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        newdn.add( "m-oid" + "=" + NEW_OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "old normalizer OID should NOT be present", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
         
         assertTrue( "new normalizer OID should be present", 
-            getNormalizerRegistry().hasNormalizer( NEW_OID ) );
+            schemaManager.getNormalizerRegistry().contains( NEW_OID ) );
         
         assertEquals( "normalizer with new oid should have schema set to apache NOT apachemeta", 
-            getNormalizerRegistry().getSchemaName( NEW_OID ), "apache" );
+            schemaManager.getNormalizerRegistry().getSchemaName( NEW_OID ), "apache" );
 
-        Class<?> clazz = getNormalizerRegistry().lookup( NEW_OID ).getClass();
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( NEW_OID ).getClass();
         assertEquals( clazz, NoOpNormalizer.class );
     }
 
     
     @Test
+    @Ignore
     public void testModifyNormalizerWithModificationItems() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
         
         ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( MetaSchemaConstants.M_FQCN_AT, DeepTrimNormalizer.class.getName() );
+        Attribute attr = new BasicAttribute( "m-fqcn", DeepTrimNormalizer.class.getName() );
         mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
         getSchemaContext( service ).modifyAttributes( dn, mods );
 
         assertTrue( "normalizer OID should still be present", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
         
         assertEquals( "normalizer schema should be set to apachemeta", 
-            getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
 
-        Class<?> clazz = getNormalizerRegistry().lookup( OID ).getClass();
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( OID ).getClass();
         assertEquals( clazz, DeepTrimNormalizer.class );
     }
 
     
     @Test
+    @Ignore
     public void testModifyNormalizerWithAttributes() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
         
         Attributes mods = new BasicAttributes( true );
-        mods.put( MetaSchemaConstants.M_FQCN_AT, DeepTrimNormalizer.class.getName() );
+        mods.put( "m-fqcn", DeepTrimNormalizer.class.getName() );
         getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
 
         assertTrue( "normalizer OID should still be present", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
         
         assertEquals( "normalizer schema should be set to apachemeta", 
-            getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
 
-        Class<?> clazz = getNormalizerRegistry().lookup( OID ).getClass();
+        Class<?> clazz = schemaManager.getNormalizerRegistry().lookup( OID ).getClass();
         assertEquals( clazz, DeepTrimNormalizer.class );
     }
     
@@ -320,44 +412,67 @@
     // ----------------------------------------------------------------------
     // Test move, rename, and delete when a MR exists and uses the Normalizer
     // ----------------------------------------------------------------------
-
-    
     @Test
     public void testDeleteNormalizerWhenInUse() throws Exception
     {
-        LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddNormalizer();
-        getMatchingRuleRegistry().register( new DummyMR() );
-        
+        LdapDN nDn = getNormalizerContainer( "apachemeta" );
+        nDn.add( "m-oid" + "=" + OID );
+
+        // Create a new Normalizer
+        testAddNormalizerToEnabledSchema();
+        assertTrue( isOnDisk( nDn ) );
+        assertTrue( service.getSchemaManager().getNormalizerRegistry().contains( OID ) );
+        
+        // Create a MR using this Normalizer
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaMatchingRule",
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description: test" );
+
+        LdapDN mrDn = getMatchingRuleContainer( "apachemeta" );
+        mrDn.add( "m-oid" + "=" + OID );
+
+        // Pre-checks
+        assertFalse( isOnDisk( mrDn ) );
+        assertFalse( service.getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+
+        // MatchingRule Addition
+        getSchemaContext( service ).createSubcontext( mrDn, attrs );
+
+        // Post-checks
+        assertTrue( isOnDisk( mrDn ) );
+        assertTrue( service.getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+
         try
         {
-            getSchemaContext( service ).destroySubcontext( dn );
-            fail( "should not be able to delete a normalizer in use" );
+            getSchemaContext( service ).destroySubcontext( nDn );
+            fail( "should not be able to delete a Normalizer in use" );
         }
-        catch( LdapOperationNotSupportedException e ) 
+        catch ( LdapOperationNotSupportedException e )
         {
             assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
         }
 
-        assertTrue( "normalizer should still be in the registry after delete failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
-        getMatchingRuleRegistry().unregister( OID );
-        getOidRegistry().unregister( OID );
+        assertTrue( "Normalizer should still be in the registry after delete failure", schemaManager
+            .getNormalizerRegistry().contains( OID ) );
     }
     
     
     @Test
+    @Ignore
     public void testMoveNormalizerWhenInUse() throws Exception
     {
-        testAddNormalizer();
-        getMatchingRuleRegistry().register( new DummyMR() );
+        testAddNormalizerToEnabledSchema();
+        schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = getNormalizerContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         try
         {
@@ -370,23 +485,24 @@
         }
 
         assertTrue( "normalizer should still be in the registry after move failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
-        getMatchingRuleRegistry().unregister( OID );
-        getOidRegistry().unregister( OID );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        schemaManager.getMatchingRuleRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerAndChangeRdnWhenInUse() throws Exception
     {
-        testAddNormalizer();
-        getMatchingRuleRegistry().register( new DummyMR() );
+        testAddNormalizerToEnabledSchema();
+        schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = getNormalizerContainer( "apache" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        newdn.add( "m-oid" + "=" + NEW_OID );
         
         try
         {
@@ -399,22 +515,23 @@
         }
 
         assertTrue( "normalizer should still be in the registry after move failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
-        getMatchingRuleRegistry().unregister( OID );
-        getOidRegistry().unregister( OID );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        schemaManager.getMatchingRuleRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
     
     @Test
+    @Ignore
     public void testRenameNormalizerWhenInUse() throws Exception
     {
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        testAddNormalizer();
-        getMatchingRuleRegistry().register( new DummyMR() );
+        dn.add( "m-oid" + "=" + OID );
+        testAddNormalizerToEnabledSchema();
+        schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
         
         LdapDN newdn = getNormalizerContainer( "apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        newdn.add( "m-oid" + "=" + NEW_OID );
         
         try
         {
@@ -427,9 +544,9 @@
         }
 
         assertTrue( "normalizer should still be in the registry after rename failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
-        getMatchingRuleRegistry().unregister( OID );
-        getOidRegistry().unregister( OID );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
+        schemaManager.getMatchingRuleRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
 
@@ -439,15 +556,16 @@
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerToTop() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN top = new LdapDN();
-        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        top.add( "m-oid" + "=" + OID );
         
         try
         {
@@ -460,20 +578,21 @@
         }
 
         assertTrue( "normalizer should still be in the registry after move failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerToComparatorContainer() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         LdapDN newdn = new LdapDN( "ou=comparators,cn=apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         try
         {
@@ -486,132 +605,64 @@
         }
 
         assertTrue( "normalizer should still be in the registry after move failure", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
-    }
-    
-    
-    @Test
-    public void testAddNormalizerToDisabledSchema() throws Exception
-    {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( SchemaConstants.OBJECT_CLASS_AT, "top" );
-        oc.add( MetaSchemaConstants.META_TOP_OC );
-        oc.add( MetaSchemaConstants.META_NORMALIZER_OC );
-        attrs.put( oc );
-        attrs.put( MetaSchemaConstants.M_FQCN_AT, NoOpNormalizer.class.getName() );
-        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
-        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test normalizer" );
-        
-        // nis is by default inactive
-        LdapDN dn = getNormalizerContainer( "nis" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
-        getSchemaContext( service ).createSubcontext( dn, attrs );
-        
-        assertFalse( "adding new normalizer to disabled schema should not register it into the registries", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerToDisabledSchema() throws Exception
     {
-        testAddNormalizer();
+        testAddNormalizerToEnabledSchema();
         
         LdapDN dn = getNormalizerContainer( "apachemeta" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         // nis is inactive by default
         LdapDN newdn = getNormalizerContainer( "nis" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "normalizer OID should no longer be present", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveNormalizerToEnabledSchema() throws Exception
     {
         testAddNormalizerToDisabledSchema();
         
         // nis is inactive by default
         LdapDN dn = getNormalizerContainer( "nis" );
-        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        dn.add( "m-oid" + "=" + OID );
 
         assertFalse( "normalizer OID should NOT be present when added to disabled nis schema", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
 
         LdapDN newdn = getNormalizerContainer( "apachemeta" );
-        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        newdn.add( "m-oid" + "=" + OID );
         
         getSchemaContext( service ).rename( dn, newdn );
 
         assertTrue( "normalizer OID should be present when moved to enabled schema", 
-            getNormalizerRegistry().hasNormalizer( OID ) );
+            schemaManager.getNormalizerRegistry().contains( OID ) );
         
         assertEquals( "normalizer should be in apachemeta schema after move", 
-            getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
     }
 
 
-    class DummyMR implements MatchingRule
+    class DummyMR extends MatchingRule
     {
-        private static final long serialVersionUID = 1L;
-
-        public Comparator getComparator() throws NamingException
-        {
-            return null;
-        }
-
-        public Normalizer getNormalizer() throws NamingException
-        {
-            return null;
-        }
-
-        public Syntax getSyntax() throws NamingException
-        {
-            return null;
-        }
-
-        public String getDescription()
-        {
-            return null;
-        }
-
-        public String getName()
-        {
-            return "dummy";
-        }
-
-        public String[] getNames()
-        {
-            return new String[] { "dummy" };
-        }
-
-        public String getOid()
-        {
-            return OID;
-        }
-
-        public boolean isObsolete()
-        {
-            return false;
-        }
-
-        public String getSchema()
-        {
-            return null;
-        }
-
-        public void setSchema( String schemaName )
+        public DummyMR()
         {
+            super( OID );
+            addName( "dummy" );
         }
 
-        public String[] getNamesRef()
-        {
-            return new String[] { "dummy" };
-        }
+        private static final long serialVersionUID = 1L;
     }
 }

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java?rev=896599&r1=896598&r2=896599&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java Wed Jan  6 18:26:43 2010
@@ -20,22 +20,13 @@
 package org.apache.directory.server.core.schema;
 
 
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
-import org.apache.directory.server.schema.registries.ObjectClassRegistry;
-import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
-import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.ObjectClass;
-import org.junit.Test;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import org.junit.runner.RunWith;
 
+import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -44,6 +35,18 @@
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 
+import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
+import org.apache.directory.shared.ldap.schema.registries.ObjectClassRegistry;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
 
 /**
  * A test case which tests the addition of various schema elements
@@ -52,8 +55,8 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith ( CiRunner.class )
-public class MetaObjectClassHandlerIT
+@RunWith(FrameworkRunner.class)
+public class MetaObjectClassHandlerIT extends AbstractMetaSchemaObjectHandler
 {
     private static final String NAME = "testObjectClass";
     private static final String NEW_NAME = "alternateName";
@@ -67,76 +70,107 @@
     private static final String DEPENDEE_OID = "1.3.6.1.4.1.18060.0.4.0.3.100002";
 
 
-    public static DirectoryService service;
-
-    
-    /**
-     * Gets relative DN to ou=schema.
-     *
-     * @param schemaName the name of the schema
-     * @return the dn of the container which contains objectClasses
-     * @throws Exception on error
-     */
-    private LdapDN getObjectClassContainer( String schemaName ) throws Exception
-    {
-        return new LdapDN( "ou=objectClasses,cn=" + schemaName );
-    }
-
-
     private static ObjectClassRegistry getObjectClassRegistry()
     {
-        return service.getRegistries().getObjectClassRegistry();
+        return service.getSchemaManager().getObjectClassRegistry();
     }
     
     
-    private void addObjectClass() throws Exception
+    private LdapDN addObjectClass() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", NAME);
-        attrs.put( "m-description", DESCRIPTION0 );
-        attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid: " + OID,
+            "m-name: " + NAME,
+            "m-description: " + DESCRIPTION0,
+            "m-typeObjectClass: AUXILIARY",
+            "m-must: cn",
+            "m-may: ou" );
         
         LdapDN dn = getObjectClassContainer( "apachemeta" );
         dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        return dn;
     }
 
     
     // ----------------------------------------------------------------------
     // Test all core methods with normal operational pathways
     // ----------------------------------------------------------------------
-
-
     @Test
-    public void testAddObjectClass() throws Exception
+    public void testAddObjectClassToEnabledSchema() throws Exception
     {
-        addObjectClass();
+        LdapDN dn = addObjectClass();
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( OID ) );
+        assertTrue( getObjectClassRegistry().contains( OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
+        assertTrue( isOnDisk( dn ) );
     }
     
     
     @Test
-    public void testDeleteAttributeType() throws Exception
+    public void testAddObjectClassToDisabledSchema() throws Exception
+    {
+        LdapDN dn = addObjectClassToDisabledSchema();
+        
+        assertFalse( "adding new objectClass to disabled schema should not register it into the registries", 
+            getObjectClassRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+    }
+
+
+    @Test
+    public void testAddObjectClassToUnloadedSchema() throws Exception
+    {
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid: " + OID,
+            "m-name: " + NAME,
+            "m-description: " + DESCRIPTION0,
+            "m-typeObjectClass: AUXILIARY",
+            "m-must: cn",
+            "m-may: ou" );
+
+        LdapDN dn = getObjectClassContainer( "notloaded" );
+        dn.add( "m-oid" + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail( "Should not be there" );
+        }
+        catch( NameNotFoundException nnfe )
+        {
+            // Excpected result
+        }
+        
+        assertFalse( "adding new objectClass to disabled schema should not register it into the registries", 
+            getObjectClassRegistry().contains( OID ) );
+        assertFalse( isOnDisk( dn ) );
+    }
+
+
+    @Test
+    public void testDeleteObjectClassFromEnabledSchema() throws Exception
     {
         LdapDN dn = getObjectClassContainer( "apachemeta" );
         dn.add( "m-oid" + "=" + OID );
         addObjectClass();
-        
+
+        assertTrue( "objectClass should be removed from the registry after being deleted", 
+            getObjectClassRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+
         getSchemaContext( service ).destroySubcontext( dn );
 
         assertFalse( "objectClass should be removed from the registry after being deleted", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
 
-        //noinspection EmptyCatchBlock
         try
         {
             getObjectClassRegistry().lookup( OID );
@@ -145,11 +179,43 @@
         catch( NamingException e )
         {
         }
+
+        assertFalse( isOnDisk( dn ) );
     }
 
+    
+    @Test
+    public void testDeleteObjectClassFromDisabledSchema() throws Exception
+    {
+        LdapDN dn = getObjectClassContainer( "nis" );
+        dn.add( "m-oid" + "=" + OID );
+        addObjectClassToDisabledSchema();
+        
+        assertFalse( "objectClass should be removed from the registry after being deleted", 
+            getObjectClassRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+        
+        getSchemaContext( service ).destroySubcontext( dn );
+
+        assertFalse( "objectClass should be removed from the registry after being deleted", 
+            getObjectClassRegistry().contains( OID ) );
+
+        try
+        {
+            getObjectClassRegistry().lookup( OID );
+            fail( "objectClass lookup should fail after deleting it" );
+        }
+        catch( NamingException e )
+        {
+        }
+        
+        assertFalse( isOnDisk( dn ) );
+    }
+    
 
     @Test
-    public void testRenameAttributeType() throws Exception
+    @Ignore
+    public void testRenameObjectClassType() throws Exception
     {
         LdapDN dn = getObjectClassContainer( "apachemeta" );
         dn.add( "m-oid" + "=" + OID );
@@ -160,7 +226,7 @@
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "old objectClass OID should be removed from the registry after being renamed", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
 
         //noinspection EmptyCatchBlock
         try
@@ -172,12 +238,13 @@
         {
         }
 
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+        assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
     }
 
 
     @Test
-    public void testMoveAttributeType() throws Exception
+    @Ignore
+    public void testMoveObjectClass() throws Exception
     {
         addObjectClass();
         
@@ -190,7 +257,7 @@
         getSchemaContext( service ).rename( dn, newdn );
 
         assertTrue( "objectClass OID should still be present", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
         
         assertEquals( "objectClass schema should be set to apache not apachemeta", 
             getObjectClassRegistry().getSchemaName( OID ), "apache" );
@@ -198,6 +265,7 @@
 
 
     @Test
+    @Ignore
     public void testMoveObjectClassAndChangeRdn() throws Exception
     {
         addObjectClass();
@@ -211,10 +279,10 @@
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "old objectClass OID should NOT be present", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
         
         assertTrue( "new objectClass OID should be present", 
-            getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+            getObjectClassRegistry().contains( NEW_OID ) );
         
         assertEquals( "objectClass with new oid should have schema set to apache NOT apachemeta", 
             getObjectClassRegistry().getSchemaName( NEW_OID ), "apache" );
@@ -222,7 +290,8 @@
 
     
     @Test
-    public void testModifyAttributeTypeWithModificationItems() throws Exception
+    @Ignore
+    public void testModifyObjectClassWithModificationItems() throws Exception
     {
         addObjectClass();
         
@@ -241,7 +310,7 @@
         getSchemaContext( service ).modifyAttributes( dn, mods );
 
         assertTrue( "objectClass OID should still be present", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
         
         assertEquals( "objectClass schema should be set to apachemeta", 
             getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
@@ -253,7 +322,8 @@
 
     
     @Test
-    public void testModifyAttributeTypeWithAttributes() throws Exception
+    @Ignore
+    public void testModifyObjectClassWithAttributes() throws Exception
     {
         addObjectClass();
         
@@ -270,7 +340,7 @@
         getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
 
         assertTrue( "objectClass OID should still be present", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
         
         assertEquals( "objectClass schema should be set to apachemeta", 
             getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
@@ -303,7 +373,7 @@
         dn.add( "m-oid" + "=" + DEPENDEE_OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( DEPENDEE_OID ) );
+        assertTrue( getObjectClassRegistry().contains( DEPENDEE_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
     }
 
@@ -327,11 +397,12 @@
         }
 
         assertTrue( "objectClass should still be in the registry after delete failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
     
     
     @Test
+    @Ignore
     public void testMoveObjectClassWhenInUse() throws Exception
     {
         addObjectClass();
@@ -354,11 +425,12 @@
         }
 
         assertTrue( "objectClass should still be in the registry after move failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveObjectClassAndChangeRdnWhenInUse() throws Exception
     {
         addObjectClass();
@@ -381,11 +453,12 @@
         }
 
         assertTrue( "ObjectClass should still be in the registry after move failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
     
     @Test
+    @Ignore
     public void testRenameObjectClassWhenInUse() throws Exception
     {
         LdapDN dn = getObjectClassContainer( "apachemeta" );
@@ -407,7 +480,7 @@
         }
 
         assertTrue( "objectClass should still be in the registry after rename failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
 
@@ -415,6 +488,7 @@
     // Let's try some freaky stuff
     // ----------------------------------------------------------------------
     @Test
+    @Ignore
     public void testMoveObjectClassToTop() throws Exception
     {
         addObjectClass();
@@ -436,11 +510,12 @@
         }
 
         assertTrue( "objectClass should still be in the registry after move failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveObjectClassToComparatorContainer() throws Exception
     {
         addObjectClass();
@@ -462,40 +537,33 @@
         }
 
         assertTrue( "objectClass should still be in the registry after move failure", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
     
-    private void addObjectClassToDisabledSchema() throws Exception
+    private LdapDN addObjectClassToDisabledSchema() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", NAME);
-        attrs.put( "m-description", DESCRIPTION0 );
-        attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-        
+        Attributes attrs = AttributeUtils.createAttributes( 
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid: " + OID,
+            "m-name: " + NAME,
+            "m-description: " + DESCRIPTION0,
+            "m-typeObjectClass: AUXILIARY",
+            "m-must: cn",
+            "m-may: ou" );
+
         LdapDN dn = getObjectClassContainer( "nis" );
         dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
-    }
-    
-    @Test
-    public void testAddObjectClassToDisabledSchema1() throws Exception
-    {
-        addObjectClassToDisabledSchema();
         
-        assertFalse( "adding new objectClass to disabled schema should not register it into the registries", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+        return dn;
     }
-
-
+    
+    
     @Test
+    @Ignore
     public void testMoveObjectClassToDisabledSchema() throws Exception
     {
         addObjectClass();
@@ -510,11 +578,12 @@
         getSchemaContext( service ).rename( dn, newdn );
 
         assertFalse( "objectClass OID should no longer be present", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
     }
 
 
     @Test
+    @Ignore
     public void testMoveObjectClassToEnabledSchema() throws Exception
     {
         addObjectClassToDisabledSchema();
@@ -524,7 +593,7 @@
         dn.add( "m-oid" + "=" + OID );
 
         assertFalse( "objectClass OID should NOT be present when added to disabled nis schema", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
 
         LdapDN newdn = getObjectClassContainer( "apachemeta" );
         newdn.add( "m-oid" + "=" + OID );
@@ -532,7 +601,7 @@
         getSchemaContext( service ).rename( dn, newdn );
 
         assertTrue( "objectClass OID should be present when moved to enabled schema", 
-            getObjectClassRegistry().hasObjectClass( OID ) );
+            getObjectClassRegistry().contains( OID ) );
         
         assertEquals( "objectClass should be in apachemeta schema after move", 
             getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
@@ -565,7 +634,7 @@
         dn.add( "m-oid" + "=" + OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( OID ) );
+        assertTrue( getObjectClassRegistry().contains( OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
     }
 
@@ -672,7 +741,7 @@
         dn.add( "m-oid" + "=" + NEW_OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+        assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
     }
 
@@ -693,7 +762,6 @@
         attrs.put( "m-name", "abstractOCtest");
         attrs.put( "m-description", "An abstract oC inheriting from top" );
         attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-supObjectClass", "javaNamingReference" );
         attrs.put( "m-must", "cn" );
         attrs.put( "m-may", "ou" );
         
@@ -706,7 +774,7 @@
         dn.add( "m-oid" + "=" + NEW_OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+        assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
     }
 
@@ -774,7 +842,7 @@
         dn.add( "m-oid" + "=" + NEW_OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+        assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
     }
 
@@ -805,10 +873,16 @@
 
         LdapDN dn = getObjectClassContainer( "apachemeta" );
         dn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
-        assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
+        try
+        {
+            getSchemaContext( service ).createSubcontext( dn, attrs );
+            fail();
+        }
+        catch ( NamingException ne )
+        {
+            assertTrue( true );
+        }
     }
 
     
@@ -840,7 +914,7 @@
         dn.add( "m-oid" + "=" + NEW_OID );
         getSchemaContext( service ).createSubcontext( dn, attrs );
         
-        assertTrue( getObjectClassRegistry().hasObjectClass( NEW_OID ) );
+        assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
     }
 }



Mime
View raw message