directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1209069 [2/8] - in /directory/apacheds/branches/apacheds-txns: core-api/ core-api/src/main/java/org/apache/directory/server/core/api/ core-api/src/main/java/org/apache/directory/server/core/api/interceptor/ core-api/src/main/java/org/apach...
Date Thu, 01 Dec 2011 13:25:35 GMT
Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java?rev=1209069&r1=1209068&r2=1209069&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java Thu Dec  1 13:25:26 2011
@@ -20,32 +20,32 @@
 package org.apache.directory.server.core.schema;
 
 
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import javax.naming.NameNotFoundException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.ldap.LdapContext;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.JndiUtils;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -68,6 +68,18 @@ public class MetaAttributeTypeHandlerIT 
     private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.2.100001";
     private static final String DEPENDEE_OID = "1.3.6.1.4.1.18060.0.4.0.2.100002";
 
+    private static LdapConnection connection;
+    private SchemaManager schemaManager;
+
+    
+    @Before
+    public void init() throws Exception
+    {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
+        schemaManager = getService().getSchemaManager();
+    }
+
     // ----------------------------------------------------------------------
     // Test all core methods with normal operational pathways
     // ----------------------------------------------------------------------
@@ -81,7 +93,9 @@ public class MetaAttributeTypeHandlerIT 
     @Test
     public void testAddAttributeTypeWithoutMatchingRule() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=2.5.4.58,ou=attributeTypes,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
@@ -91,19 +105,16 @@ public class MetaAttributeTypeHandlerIT 
             "m-description: attribute certificate use ;binary"
          );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=2.5.4.58" );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( "2.5.4.58" ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( "2.5.4.58" ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "2.5.4.58" ) );
-        assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "2.5.4.58" ), "apachemeta" );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "2.5.4.58" ) );
+        assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( "2.5.4.58" ), "apachemeta" );
         assertTrue( isOnDisk( dn ) );
     }
 
@@ -111,30 +122,29 @@ public class MetaAttributeTypeHandlerIT 
     @Test
     public void testAddAttributeTypeToEnabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
-            "m-oid:" + OID,
-            "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
-            "m-description:" + DESCRIPTION0,
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0,
             "m-equality: caseIgnoreMatch",
             "m-singleValue: FALSE",
             "m-usage: directoryOperation" );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
-        assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( OID ) );
+        assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
         assertTrue( isOnDisk( dn ) );
     }
 
@@ -142,32 +152,31 @@ public class MetaAttributeTypeHandlerIT 
     @Test
     public void testAddAttributeTypeToUnLoadedSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=notloaded,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
-            "m-oid:" + OID,
-            "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
-            "m-description:" + DESCRIPTION0,
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0,
             "m-equality: caseIgnoreMatch",
             "m-singleValue: FALSE",
             "m-usage: directoryOperation" );
 
-        Dn dn = getAttributeTypeContainer( "notloaded" );
-        dn = dn.add( "m-oid=" + OID );
-
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail( "Should not be there" );
         }
-        catch( NameNotFoundException nnfe )
+        catch( LdapException nnfe )
         {
             // Expected result.
         }
 
         assertFalse( "adding new attributeType to disabled schema should not register it into the registries",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // The added entry must not be present on disk
         assertFalse( isOnDisk( dn ) );
@@ -177,27 +186,26 @@ public class MetaAttributeTypeHandlerIT 
     @Test
     public void testAddAttributeTypeToDisabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
-            "m-oid:" + OID,
-            "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
-            "m-description:" + DESCRIPTION0,
+            "m-oid", OID,
+            "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+            "m-description", DESCRIPTION0,
             "m-equality: caseIgnoreMatch",
             "m-singleValue: FALSE",
             "m-usage: directoryOperation" );
 
-        Dn dn = getAttributeTypeContainer( "nis" );
-        dn = dn.add( "m-oid=" + OID );
-
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertFalse( "adding new attributeType to disabled schema should not register it into the registries",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // The GlobalOidRegistries must not contain the AT
-        assertFalse( getService().getSchemaManager().getGlobalOidRegistry().contains( OID ) );
+        assertFalse( schemaManager.getGlobalOidRegistry().contains( OID ) );
 
         // The added entry must be present on disk
         assertTrue( isOnDisk( dn ) );
@@ -211,7 +219,9 @@ public class MetaAttributeTypeHandlerIT 
     @Test
     public void testAddAttributeTypeDescWithEndingSpace() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=1.3.6.1.4.1.8104.1.1.37,ou=attributeTypes,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
@@ -225,19 +235,16 @@ public class MetaAttributeTypeHandlerIT 
             "m-singleValue: TRUE"
          );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=1.3.6.1.4.1.8104.1.1.37" );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
-        assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "1.3.6.1.4.1.8104.1.1.37" ), "apachemeta" );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
+        assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( "1.3.6.1.4.1.8104.1.1.37" ), "apachemeta" );
         assertTrue( isOnDisk( dn ) );
     }
 
@@ -250,21 +257,20 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
         // Check in Registries
         assertTrue( "attributeType should be removed from the registry after being deleted",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // Check on disk that the added SchemaObject exist
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         // Check in Registries
         assertFalse( "attributeType should be removed from the registry after being deleted",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // Check on disk that the deleted SchemaObject does not exist anymore
         assertFalse( isOnDisk( dn ) );
@@ -282,23 +288,22 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToDisabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "nis" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
 
         // Check in Registries
         assertFalse( "attributeType should be removed from the registry after being deleted",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // Check on disk that the added SchemaObject exists
         assertTrue( isOnDisk( dn ) );
 
         // Remove the AT
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         // Check in Registries
         assertFalse( "attributeType should be removed from the registry after being deleted",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
-        assertFalse( getService().getSchemaManager().getGlobalOidRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
+        assertFalse( schemaManager.getGlobalOidRegistry().contains( OID ) );
 
         // Check on disk that the deleted SchemaObject does not exist anymore
         assertFalse( isOnDisk( dn ) );
@@ -310,21 +315,20 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
         addDependeeAttributeType();
 
         try
         {
-            getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+            connection.delete( dn );
             fail( "should not be able to delete a attributeType in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
         assertTrue( "attributeType should still be in the registry after delete failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -337,27 +341,26 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        AttributeType at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( OID );
         assertEquals( at.getDescription(), DESCRIPTION0 );
         assertEquals( at.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        ModificationItem[] mods = new ModificationItem[2];
-        Attribute attr = new BasicAttribute( "m-description", DESCRIPTION1 );
-        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        attr = new BasicAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
-        mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+        Attribute attr = new DefaultAttribute( "m-description", DESCRIPTION1 );
+        Modification mod1 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+        attr = new DefaultAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
+        Modification mod2 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "attributeType OID should still be present",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         assertEquals( "attributeType schema should be set to apachemeta",
-            getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
 
-        at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+        at = schemaManager.lookupAttributeTypeRegistry( OID );
         assertEquals( at.getDescription(), DESCRIPTION1 );
         assertEquals( at.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
     }
@@ -369,25 +372,27 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        AttributeType at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( OID );
         assertEquals( at.getDescription(), DESCRIPTION0 );
         assertEquals( at.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+
+        Modification mod1 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
+            new DefaultAttribute( "m-description", DESCRIPTION1 ) );
+
+        Modification mod2 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
+            new DefaultAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX  ) );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-description", DESCRIPTION1 );
-        mods.put( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "attributeType OID should still be present",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         assertEquals( "attributeType schema should be set to apachemeta",
-            getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
 
-        at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+        at = schemaManager.lookupAttributeTypeRegistry( OID );
         assertEquals( at.getDescription(), DESCRIPTION1 );
         assertEquals( at.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
     }
@@ -402,21 +407,19 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getAttributeTypeContainer( "apachemeta" );
-        dn = newdn.add( "m-oid=" + NEW_OID );
-        schemaRoot.rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        Rdn rdn = new Rdn( "m-oid=" + NEW_OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+        
+        connection.rename( dn, rdn );
 
         assertFalse( "old attributeType OID should be removed from the registry after being renamed",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
-        getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+        schemaManager.lookupAttributeTypeRegistry( OID );
         fail( "attributeType lookup should fail after renaming the attributeType" );
 
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( NEW_OID ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( NEW_OID ) );
     }
 
 
@@ -426,16 +429,14 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
         addDependeeAttributeType();
 
-        Dn newdn = getAttributeTypeContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid=" + NEW_OID );
+        Rdn rdn = new Rdn( "m-oid=" + NEW_OID );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.rename( dn, rdn );
             fail( "should not be able to rename a attributeType in use" );
         }
         catch( LdapUnwillingToPerformException e )
@@ -444,7 +445,7 @@ public class MetaAttributeTypeHandlerIT 
         }
 
         assertTrue( "attributeType should still be in the registry after rename failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -457,19 +458,17 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getAttributeTypeContainer( "apache" );
-        newdn = newdn.add( "m-oid=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName(newdn) );
+        connection.move( dn, newDn );
 
         assertTrue( "attributeType OID should still be present",
-                getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+                schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         assertEquals( "attributeType schema should be set to apache not apachemeta",
-            getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
+            schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
     }
 
 
@@ -479,22 +478,20 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getAttributeTypeContainer( "apache" );
-        newdn = newdn.add( "m-oid=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "old attributeType OID should NOT be present",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         assertTrue( "new attributeType OID should be present",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( NEW_OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( NEW_OID ) );
 
         assertEquals( "attributeType with new oid should have schema set to apache NOT apachemeta",
-            getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
+            schemaManager.getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
     }
 
 
@@ -504,15 +501,14 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
         Dn top = new Dn();
         top = top.add( "m-oid=" + OID );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( top ) );
+            connection.move( dn, top );
             fail( "should not be able to move a attributeType up to ou=schema" );
         }
         catch( LdapInvalidDnException e )
@@ -521,7 +517,7 @@ public class MetaAttributeTypeHandlerIT 
         }
 
         assertTrue( "attributeType should still be in the registry after move failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -531,15 +527,13 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = new Dn( "ou=comparators,cn=apachemeta" );
-        newdn = newdn.add( "m-oid=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a attributeType into comparators container" );
         }
         catch( LdapInvalidDnException e )
@@ -548,7 +542,7 @@ public class MetaAttributeTypeHandlerIT 
         }
 
         assertTrue( "attributeType should still be in the registry after move failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -558,17 +552,15 @@ public class MetaAttributeTypeHandlerIT 
     {
         testAddAttributeTypeToEnabledSchema();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getAttributeTypeContainer( "nis" );
-        newdn = newdn.add( "m-oid=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "attributeType OID should no longer be present",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -579,15 +571,13 @@ public class MetaAttributeTypeHandlerIT 
         testAddAttributeTypeToEnabledSchema();
         addDependeeAttributeType();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getAttributeTypeContainer( "apache" );
-        newdn = newdn.add( "m-oid=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a attributeType in use" );
         }
         catch( LdapUnwillingToPerformException e )
@@ -596,7 +586,7 @@ public class MetaAttributeTypeHandlerIT 
         }
 
         assertTrue( "attributeType should still be in the registry after move failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -607,15 +597,13 @@ public class MetaAttributeTypeHandlerIT 
         testAddAttributeTypeToEnabledSchema();
         addDependeeAttributeType();
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getAttributeTypeContainer( "apache" );
-        newdn = newdn.add( "m-oid=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a attributeType in use" );
         }
         catch( LdapUnwillingToPerformException e )
@@ -624,7 +612,7 @@ public class MetaAttributeTypeHandlerIT 
         }
 
         assertTrue( "attributeType should still be in the registry after move failure",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
     }
 
 
@@ -633,7 +621,9 @@ public class MetaAttributeTypeHandlerIT 
     // ----------------------------------------------------------------------
     private void addDependeeAttributeType() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + DEPENDEE_OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaAttributeType",
@@ -645,12 +635,10 @@ public class MetaAttributeTypeHandlerIT 
             "m-usage: directoryOperation",
             "m-supAttributeType", OID );
 
-        Dn dn = getAttributeTypeContainer( "apachemeta" );
-        dn = dn.add( "m-oid=" + DEPENDEE_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( DEPENDEE_OID ) );
-        assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( DEPENDEE_OID ) );
+        assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
     }
 
 
@@ -669,18 +657,18 @@ public class MetaAttributeTypeHandlerIT 
         dn.add( "m-oid=" + OID );
 
         assertFalse( "attributeType OID should NOT be present when added to disabled nis schema",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         Dn newdn = getAttributeTypeContainer( "apachemeta" );
         newdn.add( "m-oid=" + OID );
 
-        getSchemaContext( getService() ).rename( dn, newdn );
+        connection.rename( dn, newdn );
 
         assertTrue( "attributeType OID should be present when moved to enabled schema",
-            getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+            schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         assertEquals( "attributeType should be in apachemeta schema after move",
-            getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+            schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
     }
     */
 }

Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java?rev=1209069&r1=1209068&r2=1209069&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java Thu Dec  1 13:25:26 2011
@@ -20,7 +20,6 @@
 package org.apache.directory.server.core.schema;
 
 
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -29,29 +28,25 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
-import javax.naming.NameNotFoundException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.comparators.BooleanComparator;
 import org.apache.directory.shared.ldap.model.schema.comparators.StringComparator;
-import org.apache.directory.shared.ldap.util.JndiUtils;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -71,7 +66,8 @@ public class MetaComparatorHandlerIT ext
     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 SchemaManager schemaManager;
+    private static SchemaManager schemaManager;
+    private static LdapConnection connection;
 
     class DummyMR extends MatchingRule
     {
@@ -83,9 +79,12 @@ public class MetaComparatorHandlerIT ext
     }
 
 
+    
     @Before
-    public void setup()
+    public void init() throws Exception
     {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
         schemaManager = getService().getSchemaManager();
     }
 
@@ -98,19 +97,23 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testAddComparatorToEnabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
-            "m-description: A test comparator" );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaComparator",
+            "m-fqcn", StringComparator.class.getName(),
+            "m-oid", OID,
+            "m-description: A test comparator" );
 
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
@@ -124,20 +127,23 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testAddComparatorToDisabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaComparator",
+            "m-fqcn", StringComparator.class.getName(),
+            "m-oid", OID,
             "m-description: A test comparator" );
 
         // nis is by default inactive
-        Dn dn = getComparatorContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertFalse( "adding new comparator to disabled schema should not register it into the registries",
@@ -149,25 +155,28 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testAddComparatorToUnloadedSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
-            "m-description: A test comparator" );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=notloaded,ou=schema" );
 
-        // nis is by default inactive
-        Dn dn = getComparatorContainer( "notloaded" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaComparator",
+            "m-fqcn", StringComparator.class.getName(),
+            "m-oid",  OID,
+            "m-description: A test comparator" );
 
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Addition
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail( "Should not be there" );
         }
-        catch ( NameNotFoundException nnfe )
+        catch ( LdapException nnfe )
         {
             // Expected result.
         }
@@ -190,20 +199,24 @@ public class MetaComparatorHandlerIT ext
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaComparator",
-            "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator", "m-bytecode", out
-                .toByteArray(), "m-oid", OID, "m-description: A test comparator" );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaComparator",
+            "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test comparator" );
 
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
@@ -225,21 +238,25 @@ public class MetaComparatorHandlerIT ext
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
             "objectClass: metaComparator",
-            "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator", "m-bytecode", out
-                .toByteArray(), "m-oid", OID, "m-description: A test comparator" );
+            "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test comparator" );
 
         // nis is by default inactive
-        Dn dn = getComparatorContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertFalse( "adding new comparator to disabled schema should not register it into the registries",
@@ -255,8 +272,7 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testDeleteComparatorFromEnabledSchema() throws Exception
     {
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
         testAddComparatorToEnabledSchema();
 
@@ -265,7 +281,7 @@ public class MetaComparatorHandlerIT ext
         assertTrue( isOnDisk( dn ) );
 
         // Deletion
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         // Post-checks
         assertFalse( "comparator should be removed from the registry after being deleted", schemaManager
@@ -287,8 +303,8 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testDeleteComparatorFromDisabledSchema() throws Exception
     {
-        Dn dn = getComparatorContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+
         testAddComparatorToDisabledSchema();
 
         // Pre-checks
@@ -297,7 +313,7 @@ public class MetaComparatorHandlerIT ext
         assertTrue( isOnDisk( dn ) );
 
         // Deletion
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         // Post-checks
         assertFalse( "comparator should be removed from the registry after being deleted", schemaManager
@@ -319,16 +335,17 @@ public class MetaComparatorHandlerIT ext
     @Test
     public void testDeleteComparatorWhenInUse() throws Exception
     {
-        Dn cDn = getComparatorContainer( "apachemeta" );
-        cDn = cDn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
         // Create a new Comparator
         testAddComparatorToEnabledSchema();
-        assertTrue( isOnDisk( cDn ) );
-        assertTrue( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertTrue( isOnDisk( dn ) );
+        assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
 
         // Create a MR using this comparator
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn mrDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            mrDn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaMatchingRule",
@@ -336,26 +353,23 @@ public class MetaComparatorHandlerIT ext
             "m-syntax", SchemaConstants.INTEGER_SYNTAX,
             "m-description: test" );
 
-        Dn mrDn = getMatchingRuleContainer( "apachemeta" );
-        mrDn = mrDn.add( "m-oid" + "=" + OID );
-
         // Pre-checks
         assertFalse( isOnDisk( mrDn ) );
-        assertFalse( getService().getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+        assertFalse( schemaManager.getMatchingRuleRegistry().contains( OID ) );
 
         // MatchingRule Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( mrDn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertTrue( isOnDisk( mrDn ) );
-        assertTrue( getService().getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+        assertTrue( schemaManager.getMatchingRuleRegistry().contains( OID ) );
 
         try
         {
-            getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( cDn ) );
+            connection.delete( dn );
             fail( "should not be able to delete a comparator in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -373,13 +387,10 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-fqcn", BooleanComparator.class.getName() );
-        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+        connection.modify( dn, new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BooleanComparator.class.getName() ) );
 
         assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
 
@@ -397,12 +408,10 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-fqcn", BooleanComparator.class.getName() );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName(dn), DirContext.REPLACE_ATTRIBUTE, mods );
+        connection.modify( dn, new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BooleanComparator.class.getName() ) );
 
         assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
 
@@ -421,13 +430,13 @@ public class MetaComparatorHandlerIT ext
     @Ignore
     public void testRenameComparator() throws Exception
     {
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
+
         testAddComparatorToEnabledSchema();
 
-        Dn newdn = getComparatorContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        Rdn rdn = new Rdn( "m-oid=" + NEW_OID );
+
+        connection.rename( dn, rdn );
 
         assertFalse( "old comparator OID should be removed from the registry after being renamed", schemaManager
             .getComparatorRegistry().contains( OID ) );
@@ -451,17 +460,16 @@ public class MetaComparatorHandlerIT ext
     @Ignore
     public void testRenameComparatorWhenInUse() throws Exception
     {
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
+
         testAddComparatorToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn newdn = getComparatorContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Rdn rdn = new Rdn( "m-oid" + "=" + NEW_OID );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.rename( dn, rdn );
             fail( "should not be able to rename a comparator in use" );
         }
         catch ( LdapUnwillingToPerformException e )
@@ -472,7 +480,7 @@ public class MetaComparatorHandlerIT ext
         assertTrue( "comparator should still be in the registry after rename failure", schemaManager
             .getComparatorRegistry().contains( OID ) );
         schemaManager.getMatchingRuleRegistry().unregister( OID );
-        getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
 
@@ -485,13 +493,11 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getComparatorContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
 
@@ -509,13 +515,11 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getComparatorContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=comparators,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.moveAndRename( dn, newDn );
 
         assertFalse( "old comparator OID should NOT be present", schemaManager.getComparatorRegistry().contains( OID ) );
 
@@ -539,15 +543,13 @@ public class MetaComparatorHandlerIT ext
         testAddComparatorToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getComparatorContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apache,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a comparator in use" );
         }
         catch ( LdapUnwillingToPerformException e )
@@ -558,7 +560,7 @@ public class MetaComparatorHandlerIT ext
         assertTrue( "comparator should still be in the registry after move failure", schemaManager
             .getComparatorRegistry().contains( OID ) );
         schemaManager.getMatchingRuleRegistry().unregister( OID );
-        getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
 
@@ -569,15 +571,13 @@ public class MetaComparatorHandlerIT ext
         testAddComparatorToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getComparatorContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=comparators,cn=apache,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.moveAndRename( dn, newDn );
             fail( "should not be able to move a comparator in use" );
         }
         catch ( LdapUnwillingToPerformException e )
@@ -588,7 +588,7 @@ public class MetaComparatorHandlerIT ext
         assertTrue( "comparator should still be in the registry after move failure", schemaManager
             .getComparatorRegistry().contains( OID ) );
         schemaManager.getMatchingRuleRegistry().unregister( OID );
-        getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+        schemaManager.getGlobalOidRegistry().unregister( OID );
     }
 
 
@@ -602,15 +602,14 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
         Dn top = new Dn();
         top = top.add( "m-oid" + "=" + OID );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( top ) );
+            connection.move( dn, top );
             fail( "should not be able to move a comparator up to ou=schema" );
         }
         catch ( LdapInvalidDnException e )
@@ -629,15 +628,13 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        Dn newdn = new Dn( "ou=normalizers,cn=apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + "ou=normalizers,cn=apachemeta,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a comparator up to normalizers container" );
         }
         catch ( LdapInvalidDnException e )
@@ -656,14 +653,12 @@ public class MetaComparatorHandlerIT ext
     {
         testAddComparatorToEnabledSchema();
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getComparatorContainer( "nis" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn);
 
         assertFalse( "comparator OID should no longer be present", schemaManager.getComparatorRegistry().contains( OID ) );
     }
@@ -676,16 +671,14 @@ public class MetaComparatorHandlerIT ext
         testAddComparatorToDisabledSchema();
 
         // nis is inactive by default
-        Dn dn = getComparatorContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
 
         assertFalse( "comparator OID should NOT be present when added to disabled nis schema", schemaManager
             .getComparatorRegistry().contains( OID ) );
 
-        Dn newdn = getComparatorContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "comparator OID should be present when moved to enabled schema", schemaManager
             .getComparatorRegistry().contains( OID ) );

Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java?rev=1209069&r1=1209068&r2=1209069&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java Thu Dec  1 13:25:26 2011
@@ -20,32 +20,29 @@
 package org.apache.directory.server.core.schema;
 
 
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import javax.naming.NameNotFoundException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
 import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.MatchingRule;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.comparators.StringComparator;
-import org.apache.directory.shared.ldap.util.JndiUtils;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -68,20 +65,25 @@ public class MetaMatchingRuleHandlerIT e
     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 SchemaManager schemaManager;
+    private static LdapConnection connection;
 
 
     @Before
-    public void setup()
+    public void setup() throws Exception
     {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
         schemaManager = getService().getSchemaManager();
     }
 
 
     private void createComparator() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaComparator",
@@ -89,14 +91,11 @@ public class MetaMatchingRuleHandlerIT e
             "m-oid: " + OID,
             "m-description: A test comparator" );
 
-        Dn dn = getComparatorContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertTrue( isOnDisk( dn ) );
-        assertTrue( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+        assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
     }
 
 
@@ -110,7 +109,9 @@ public class MetaMatchingRuleHandlerIT e
     {
         createComparator();
 
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaMatchingRule",
@@ -118,19 +119,16 @@ public class MetaMatchingRuleHandlerIT e
             "m-syntax", SchemaConstants.INTEGER_SYNTAX,
             "m-description", DESCRIPTION0 );
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
         // Pre-checks
         assertFalse( isOnDisk( dn ) );
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( OID ) );
 
         // Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         // Post-checks
-        assertTrue( getService().getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
-        assertEquals( getService().getSchemaManager().getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+        assertTrue( schemaManager.getMatchingRuleRegistry().contains( OID ) );
+        assertEquals( schemaManager.getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
         assertTrue( isOnDisk( dn ) );
     }
 
@@ -140,7 +138,9 @@ public class MetaMatchingRuleHandlerIT e
     {
         createComparator();
 
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=nis,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaMatchingRule",
@@ -148,9 +148,7 @@ public class MetaMatchingRuleHandlerIT e
             "m-syntax", SchemaConstants.INTEGER_SYNTAX,
             "m-description", DESCRIPTION0 );
 
-        Dn dn = getMatchingRuleContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertFalse( "adding new matchingRule to disabled schema should not register it into the registries",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -163,7 +161,9 @@ public class MetaMatchingRuleHandlerIT e
     {
         createComparator();
 
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=notloaded,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
                 "objectClass: top",
                 "objectClass: metaTop",
                 "objectClass: metaMatchingRule",
@@ -171,15 +171,12 @@ public class MetaMatchingRuleHandlerIT e
                 "m-syntax", SchemaConstants.INTEGER_SYNTAX,
                 "m-description", DESCRIPTION0);
 
-        Dn dn = getMatchingRuleContainer( "notloaded" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail( "Should not be there" );
         }
-        catch( NameNotFoundException nnfe )
+        catch( LdapException le )
         {
             // Expected result
         }
@@ -196,15 +193,15 @@ public class MetaMatchingRuleHandlerIT e
     @Test
     public void testDeleteMatchingRuleFromEnabledSchema() throws Exception
     {
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+        
         testAddMatchingRuleToEnabledSchema();
 
         assertTrue( "matchingRule should be removed from the registry after being deleted",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "matchingRule should be removed from the registry after being deleted",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -225,15 +222,15 @@ public class MetaMatchingRuleHandlerIT e
     @Test
     public void testDeleteMatchingRuleFromDisabledSchema() throws Exception
     {
-        Dn dn = getMatchingRuleContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=nis,ou=schema" );
+
         testAddMatchingRuleToDisabledSchema();
 
         assertFalse( "matchingRule should be removed from the registry after being deleted",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "matchingRule should be removed from the registry after being deleted",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -254,15 +251,14 @@ public class MetaMatchingRuleHandlerIT e
         assertEquals( mr.getDescription(), DESCRIPTION0 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+
+        Modification mod1 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-description", DESCRIPTION1 );
+        Modification mod2 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
 
-        ModificationItem[] mods = new ModificationItem[2];
-        Attribute attr = new BasicAttribute( "m-description", DESCRIPTION1 );
-        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        attr = new BasicAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
-        mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "matchingRule OID should still be present",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -286,13 +282,14 @@ public class MetaMatchingRuleHandlerIT e
         assertEquals( mr.getDescription(), DESCRIPTION0 );
         assertEquals( mr.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+
+        Modification mod1 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-description", DESCRIPTION1 );
+        Modification mod2 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-description", DESCRIPTION1 );
-        mods.put( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "matchingRule OID should still be present",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -313,13 +310,12 @@ public class MetaMatchingRuleHandlerIT e
     @Ignore
     public void testRenameMatchingRule() throws Exception
     {
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+
         testAddMatchingRuleToEnabledSchema();
 
-        Dn newdn = getMatchingRuleContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        Rdn rdn  = new Rdn( "m-oid=" + NEW_OID );
+        connection.rename( dn, rdn );
 
         assertFalse( "old matchingRule OID should be removed from the registry after being renamed",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -346,13 +342,11 @@ public class MetaMatchingRuleHandlerIT e
     {
         testAddMatchingRuleToEnabledSchema();
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getMatchingRuleContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "matchingRule OID should still be present",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -368,13 +362,11 @@ public class MetaMatchingRuleHandlerIT e
     {
         testAddMatchingRuleToEnabledSchema();
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getMatchingRuleContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=matchingRules,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.moveAndRename( dn, newDn );
 
         assertFalse( "old matchingRule OID should NOT be present",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -390,44 +382,40 @@ public class MetaMatchingRuleHandlerIT e
     // ----------------------------------------------------------------------
     // Test move, rename, and delete when a MR exists and uses the Normalizer
     // ----------------------------------------------------------------------
-
-
-//    public void testDeleteSyntaxWhenInUse() throws NamingException
+//    @Test
+//    public void testDeleteSyntaxWhenInUse() throws Exception
 //    {
-//        Dn dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( "m-oid" + "=" + OID );
+//        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+//
 //        testAddSyntax();
 //        addDependeeMatchingRule();
 //
 //        try
 //        {
-//            super.schemaRoot.destroySubcontext( JndiUtils.toName( dn ) );
+//            connection.delete( dn );
 //            fail( "should not be able to delete a syntax in use" );
 //        }
-//        catch( LdapUnwillingToPerformException e )
+//        catch( LdapException e )
 //        {
-//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//            //assertEquals( e.@getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
 //        }
 //
 //        assertTrue( "syntax should still be in the registry after delete failure",
 //            getLdapSyntaxRegistry().hasSyntax( OID ) );
 //    }
-//
-//
+
+
 //    public void testMoveSyntaxWhenInUse() throws NamingException
 //    {
 //        testAddSyntax();
 //        addDependeeMatchingRule();
 //
-//        Dn dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( "m-oid" + "=" + OID );
-//
-//        Dn newdn = getSyntaxContainer( "apache" );
-//        newdn = newdn.add( "m-oid" + "=" + OID );
+//        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+//        Dn newDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apache,ou=schema" );
 //
 //        try
 //        {
-//            super.schemaRoot.rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+//            super.schemaRoot.rename( dn, newDn );
 //            fail( "should not be able to move a syntax in use" );
 //        }
 //        catch( LdapUnwillingToPerformException e )
@@ -445,15 +433,13 @@ public class MetaMatchingRuleHandlerIT e
 //        testAddSyntax();
 //        addDependeeMatchingRule()
 //
-//        Dn dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( "m-oid" + "=" + OID );s
-//
-//        Dn newdn = getSyntaxContainer( "apache" );
-//        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+//        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 //
+//        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=matchingRules,cn=apache,ou=schema" );
+
 //        try
 //        {
-//            super.schemaRoot.rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+//            super.schemaRoot.moveAndRename( dn, JndiUtils.toName( newdn ) );
 //            fail( "should not be able to move a syntax in use" );
 //        }
 //        catch( LdapUnwillingToPerformException e )
@@ -477,17 +463,16 @@ public class MetaMatchingRuleHandlerIT e
 //
 //    public void testRenameNormalizerWhenInUse() throws NamingException
 //    {
-//        Dn dn = getSyntaxContainer( "apachemeta" );
-//        dn.add( "m-oid" + "=" + OID );
+//        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+//
 //        testAddSyntax();
 //        addDependeeMatchingRule();
 //
-//        Dn newdn = getSyntaxContainer( "apachemeta" );
-//        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+//        Rdn rdn = new Rdn( "m-oid=" + NEW_OID );
 //
 //        try
 //        {
-//            super.schemaRoot.rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+//            super.schemaRoot.rename( dn, rdn );
 //            fail( "should not be able to rename a syntax in use" );
 //        }
 //        catch( LdapUnwillingToPerformException e )
@@ -511,15 +496,13 @@ public class MetaMatchingRuleHandlerIT e
     {
         testAddMatchingRuleToEnabledSchema();
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
-        Dn top = new Dn();
-        top = top.add( "m-oid" + "=" + OID );
+        Dn top = new Dn( "m-oid=" + OID );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( top ) );
+            connection.move( dn, top );
             fail( "should not be able to move a matchingRule up to ou=schema" );
         }
         catch( LdapInvalidDnException e )
@@ -538,15 +521,13 @@ public class MetaMatchingRuleHandlerIT e
     {
         testAddMatchingRuleToEnabledSchema();
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
-        Dn newdn = new Dn( "ou=comparators,cn=apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparatos,cn=apachemeta,ou=schema" );
 
         try
         {
-            getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+            connection.move( dn, newDn );
             fail( "should not be able to move a matchingRule into comparators container" );
         }
         catch( LdapInvalidDnException e )
@@ -565,14 +546,12 @@ public class MetaMatchingRuleHandlerIT e
     {
         testAddMatchingRuleToEnabledSchema();
 
-        Dn dn = getMatchingRuleContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getMatchingRuleContainer( "nis" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "matchingRule OID should no longer be present",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
@@ -586,16 +565,14 @@ public class MetaMatchingRuleHandlerIT e
         testAddMatchingRuleToDisabledSchema();
 
         // nis is inactive by default
-        Dn dn = getMatchingRuleContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=nis,ou=schema" );
 
         assertFalse( "matchingRule OID should NOT be present when added to disabled nis schema",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );
 
-        Dn newdn = getMatchingRuleContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName(newdn) );
+        connection.move( dn, newDn );
 
         assertTrue( "matchingRule OID should be present when moved to enabled schema",
             schemaManager.getMatchingRuleRegistry().contains( OID ) );



Mime
View raw message