You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/12/01 14:25:35 UTC

svn commit: r1209069 [4/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...

Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.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/MetaSchemaHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java Thu Dec  1 13:25:26 2011
@@ -6,44 +6,40 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ * 
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ * 
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
- *  under the License. 
- *  
+ *  under the License.
+ * 
  */
 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.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-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.MetaSchemaConstants;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+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.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -104,19 +100,24 @@ public class MetaSchemaHandlerIT extends
     /** Another test attribute : krb5principalName taken from the Krb5Kdc schema */
     private static final String KRB5_PRINCIPAL_NAME_ATTR = "krb5PrincipalName";
     
+    public static SchemaManager schemaManager;
+    private static LdapConnection connection;
+
 
     @Before
-    public void checkSambaSchema() throws Exception
+    public void setup() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
+        schemaManager = getService().getSchemaManager();
 
         // check that there is a samba schema installed and that is is disabled
-        Attributes attributes = schemaRoot.getAttributes( "cn=samba" );
-        assertNotNull( attributes );
-        assertTrue( attributes.get( MetaSchemaConstants.M_DISABLED_AT ).contains( "TRUE" ) );
-        attributes = schemaRoot.getAttributes( "ou=attributeTypes,cn=samba" );
-        assertNotNull( attributes );
-        assertTrue( attributes.get( SchemaConstants.OU_AT ).contains( "attributetypes" ) );
+        Entry entry = connection.lookup( "cn=samba,ou=schema" );
+        assertNotNull( entry );
+        assertTrue( entry.get( MetaSchemaConstants.M_DISABLED_AT ).contains( "TRUE" ) );
+        entry = connection.lookup( "ou=attributeTypes,cn=samba,ou=schema" );
+        assertNotNull( entry );
+        assertTrue( entry.get( SchemaConstants.OU_AT ).contains( "attributetypes" ) );
         
         // Disable the NIS schema
         IntegrationUtils.disableSchema( getService(), "nis" );
@@ -125,30 +126,32 @@ public class MetaSchemaHandlerIT extends
     
     private void createDisabledBrokenSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-
+        Dn dn = new Dn( "cn=broken,ou=schema" );
+    
         // Create the schema
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: broken",
             MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
         
-        schemaRoot.createSubcontext( "cn=broken", dummySchema );
+        connection.add( dummySchema );
     }
 
     
     private void createEnabledValidSchema( String schemaName ) throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
+        Dn dn = new Dn( "cn=" + schemaName + ",ou=schema" );
 
         // Create the schema
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn", schemaName );
         
-        schemaRoot.createSubcontext( "cn=" + schemaName, dummySchema );
+        connection.add( entry );
     }
 
     // -----------------------------------------------------------------------
@@ -170,19 +173,19 @@ public class MetaSchemaHandlerIT extends
         // check that the nis schema is not enabled
         assertTrue( IntegrationUtils.isDisabled( getService(), "nis" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // not in the AttributeTypeRegistry
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
         
         // now enable the test schema
         IntegrationUtils.enableSchema( getService(), "nis" );
         
-        // now test that the schema is loaded 
+        // now test that the schema is loaded
         assertTrue( IntegrationUtils.isEnabled( getService(), "nis" ) );
         
-        // double check and make sure the test attribute from the 
+        // double check and make sure the test attribute from the
         // test schema is now loaded and present within the attr registry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
     }
 
 
@@ -203,13 +206,13 @@ public class MetaSchemaHandlerIT extends
             IntegrationUtils.enableSchema( getService(), "wrong" );
             fail();
         }
-        catch ( NameNotFoundException lnnfe )
+        catch ( LdapException lnnfe )
         {
             // Expected
             assertTrue( true );
         }
         
-        // Test again that the schema is not loaded 
+        // Test again that the schema is not loaded
         assertFalse( IntegrationUtils.isLoaded( getService(), "wrong" ) );
     }
 
@@ -229,9 +232,9 @@ public class MetaSchemaHandlerIT extends
         // Ceck that it's not enabled
         assertTrue( IntegrationUtils.isDisabled( getService(), "nis" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // not in the AttributeTypeRegistry
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
         
         // now enable the test schema
         IntegrationUtils.enableSchema( getService(), "nis" );
@@ -239,18 +242,18 @@ public class MetaSchemaHandlerIT extends
         // and enable it again (it should not do anything)
         IntegrationUtils.enableSchema( getService(), "nis" );
         
-        // now test that the schema is loaded 
+        // now test that the schema is loaded
         assertTrue( IntegrationUtils.isEnabled( getService(), "nis" ) );
         
-        // double check and make sure the test attribute from the 
+        // double check and make sure the test attribute from the
         // test schema is now loaded and present within the attr registry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
     }
 
     
     /**
-     * Checks that if we enable a schema which will break the registries, we get 
-     * an error. 
+     * Checks that if we enable a schema which will break the registries, we get
+     * an error.
      *
      * @throws Exception on error
      */
@@ -280,19 +283,19 @@ public class MetaSchemaHandlerIT extends
         // check that the krb5kdc schema is enabled
         assertTrue( IntegrationUtils.isEnabled( getService(), "krb5kdc" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // in the AttributeTypeRegistry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR ) );
         
         // now disable the krb5kdc schema
         IntegrationUtils.disableSchema( getService(), "krb5kdc" );
         
-        // now test that the schema is not enabled 
+        // now test that the schema is not enabled
         assertTrue( IntegrationUtils.isDisabled( getService(), "krb5kdc" ) );
         
-        // double check and make sure the test attribute from the 
+        // double check and make sure the test attribute from the
         // test schema is now loaded and present within the attr registry
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( KRB5_PRINCIPAL_NAME_ATTR ) );
     }
 
 
@@ -313,13 +316,13 @@ public class MetaSchemaHandlerIT extends
             IntegrationUtils.disableSchema( getService(), "wrong" );
             fail();
         }
-        catch ( NameNotFoundException lnnfe )
+        catch ( LdapException lnnfe )
         {
             // Expected
             assertTrue( true );
         }
         
-        // Test again that the schema is not loaded 
+        // Test again that the schema is not loaded
         assertFalse( IntegrationUtils.isLoaded( getService(), "wrong" ) );
     }
 
@@ -334,30 +337,30 @@ public class MetaSchemaHandlerIT extends
     public void testDisableSchemaAlreadyDisabled() throws Exception
     {
         // check that the nis schema is loaded
-        assertTrue( IntegrationUtils.isLoaded(  getService(), "nis" ) );
+        assertTrue( IntegrationUtils.isLoaded( getService(), "nis" ) );
         
         // Check that it's not enabled
         assertTrue( IntegrationUtils.isDisabled( getService(), "nis" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // not in the AttributeTypeRegistry
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
         
         // now disable the test schema again
         IntegrationUtils.disableSchema( getService(), "nis" );
 
-        // now test that the schema is not loaded 
+        // now test that the schema is not loaded
         assertTrue( IntegrationUtils.isDisabled( getService(), "nis" ) );
         
-        // double check and make sure the test attribute from the 
+        // double check and make sure the test attribute from the
         // test schema is not loaded and present within the attr registry
-        assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertFalse( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
     }
 
     
     /**
-     * Checks that if we disable a schema which will break the registries, we get 
-     * an error. 
+     * Checks that if we disable a schema which will break the registries, we get
+     * an error.
      *
      * @throws Exception on error
      */
@@ -370,19 +373,19 @@ public class MetaSchemaHandlerIT extends
         // Check that it's enabled
         assertTrue( IntegrationUtils.isEnabled( getService(), "system" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // in the AttributeTypeRegistry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "cn" ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "cn" ) );
         
         // now disable the system schema : it should break the registries, thus being rejected
         IntegrationUtils.disableSchema( getService(), "system" );
 
-        // now test that the schema is not loaded 
+        // now test that the schema is not loaded
         assertTrue( IntegrationUtils.isEnabled( getService(), "system" ) );
         
-        // double check and make sure the test attribute from the 
+        // double check and make sure the test attribute from the
         // test schema is loaded and present within the attr registry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "cn" ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "cn" ) );
     }
 
     // -----------------------------------------------------------------------
@@ -394,16 +397,14 @@ public class MetaSchemaHandlerIT extends
     @Test
     public void testAddEnabledValidSchema() throws Exception
     {
-        Dn dn = getSchemaContainer( "dummy" );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
         assertFalse( isOnDisk( dn ) );
 
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        
         createEnabledValidSchema( "dummy" );
         
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
-        assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
+        assertNotNull( connection.lookup( "cn=dummy,ou=schema" ) );
         
         assertTrue( isOnDisk( dn ) );
     }
@@ -415,23 +416,23 @@ public class MetaSchemaHandlerIT extends
     @Test
     public void testAddEnabledSchemaWithExistingEnabledDeps() throws Exception
     {
-        Dn dn = getSchemaContainer( "dummy" );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
         assertFalse( isOnDisk( dn ) );
 
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes(
-                "objectClass: top",
-                "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
-                "cn: dummy",
-                "m-dependencies: core",
-                "m-dependencies: system",
-                MetaSchemaConstants.M_DISABLED_AT, "FALSE");
+        Entry dummySchema = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
+            "cn: dummy",
+            "m-dependencies: core",
+            "m-dependencies: system",
+            MetaSchemaConstants.M_DISABLED_AT, "FALSE");
         
-        schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+        connection.add( dummySchema );
         
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
-        assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
+        assertNotNull( connection.lookup( "cn=dummy, ou=schema" ) );
         
         assertTrue( isOnDisk( dn ) );
     }
@@ -443,12 +444,12 @@ public class MetaSchemaHandlerIT extends
     @Test
     public void testAddEnabledSchemaWithExistingDisabledDeps() throws Exception
     {
-        Dn dn = getSchemaContainer( "dummy" );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
         assertFalse( isOnDisk( dn ) );
 
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -458,12 +459,12 @@ public class MetaSchemaHandlerIT extends
         
         try
         {
-            schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+            connection.add( dummySchema );
             fail();
         }
-        catch ( OperationNotSupportedException lonse )
+        catch ( LdapException lonse )
         {
-            // expected        
+            // expected
         }
         
         assertFalse( IntegrationUtils.isLoaded( getService(), "dummy" ) );
@@ -477,12 +478,12 @@ public class MetaSchemaHandlerIT extends
     @Test
     public void testAddEnabledSchemaWithNotExistingDeps() throws Exception
     {
-        Dn dn = getSchemaContainer( "dummy" );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
         assertFalse( isOnDisk( dn ) );
 
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -492,12 +493,12 @@ public class MetaSchemaHandlerIT extends
         
         try
         {
-            schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+            connection.add( dummySchema );
             fail();
         }
-        catch ( OperationNotSupportedException lonse )
+        catch ( LdapException lonse )
         {
-            // expected       
+            // expected
         }
         
         assertFalse( IntegrationUtils.isLoaded( getService(), "dummy" ) );
@@ -514,8 +515,7 @@ public class MetaSchemaHandlerIT extends
     @Test
     public void testDeleteEnabledValidSchema() throws Exception
     {
-        Dn dn = getSchemaContainer( "dummy" );
-        LdapContext schemaRoot = getSchemaContext( getService() );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
         
         // Create a schema we will delete
         createEnabledValidSchema( "dummy" );
@@ -523,18 +523,15 @@ public class MetaSchemaHandlerIT extends
         assertTrue( IntegrationUtils.isLoaded( getService(), "dummy" ) );
 
         // Delete the schema
-        schemaRoot.destroySubcontext( "cn=dummy" );
+        connection.delete( dn );
 
         assertFalse( isOnDisk( dn ) );
         assertFalse( IntegrationUtils.isLoaded( getService(), "dummy" ) );
     }
-
-    
-    
     
     
     /**
-     * Tests the addition of a new metaSchema object that is disabled 
+     * Tests the addition of a new metaSchema object that is disabled
      * on addition and has no dependencies.
      *
      * @throws Exception on error
@@ -543,22 +540,24 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testAddDisabledSchemaNoDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
+
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
             MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
         
-        schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+        connection.add( dummySchema );
         
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
-        assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
+        assertNotNull( connection.lookup( "cn=dummy,ou=schema" ) );
     }
     
     
     /**
-     * Tests the addition of a new metaSchema object that is disabled 
+     * Tests the addition of a new metaSchema object that is disabled
      * on addition and has dependencies.
      *
      * @throws Exception on error
@@ -567,8 +566,10 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testAddDisabledSchemaWithDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
+
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -576,15 +577,15 @@ public class MetaSchemaHandlerIT extends
             "m-dependencies: nis",
             "m-dependencies: core" );
         
-        schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+        connection.add( dummySchema );
         
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
-        assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
+        assertNotNull( connection.lookup( "cn=dummy,ou=schema" ) );
     }
     
     
     /**
-     * Tests the rejection of a new metaSchema object that is disabled 
+     * Tests the rejection of a new metaSchema object that is disabled
      * on addition and has missing dependencies.
      *
      * @throws Exception on error
@@ -593,8 +594,10 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectDisabledSchemaAddWithMissingDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
+
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -604,11 +607,11 @@ public class MetaSchemaHandlerIT extends
         
         try
         {
-            schemaRoot.createSubcontext( "cn=dummy", dummySchema );
-        } 
-        catch( OperationNotSupportedException e )
+            connection.add( dummySchema );
+        }
+        catch( LdapException e )
         {
-            // expected        
+            // expected
         }
         
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
@@ -616,16 +619,17 @@ public class MetaSchemaHandlerIT extends
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=dummy" );
+            connection.lookup( "cn=dummy,ou=schema" );
             fail( "schema should not be added to schema partition" );
         }
-        catch( NamingException e )
+        catch( LdapException e )
         {
         }
     }
     
+    
     /**
-     * Tests the addition of a new metaSchema object that is enabled 
+     * Tests the addition of a new metaSchema object that is enabled
      * on addition and has no dependencies.
      *
      * @throws Exception on error
@@ -634,22 +638,24 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testAddEnabledSchemaNoDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
+
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaSchema",
             "cn: dummy"
             );
 
-        schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+        connection.add( dummySchema );
         
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
-        assertNotNull( schemaRoot.lookup( "cn=dummy" ) );
+        assertNotNull( connection.lookup( "cn=dummy,ou=schema" ) );
     }
     
     
     /**
-     * Tests the rejection of a metaSchema object add that is enabled 
+     * Tests the rejection of a metaSchema object add that is enabled
      * on addition yet has disabled dependencies.
      *
      * @throws Exception on error
@@ -658,8 +664,10 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectEnabledSchemaAddWithDisabledDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
+
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -667,12 +675,12 @@ public class MetaSchemaHandlerIT extends
         
         try
         {
-            schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+            connection.add( dummySchema );
             fail( "should not be able to add enabled schema with deps on disabled schemas" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
-            // expected        
+            // expected
         }
         
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
@@ -680,10 +688,10 @@ public class MetaSchemaHandlerIT extends
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=dummy" );
+            connection.lookup( "cn=dummy,ou=schema" );
             fail( "schema should not be added to schema partition" );
         }
-        catch( NamingException e )
+        catch( LdapException e )
         {
         }
     }
@@ -703,14 +711,14 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testDeleteSchemaNoDependents() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
-        // add the dummy schema enabled 
+        // add the dummy schema enabled
         testAddEnabledSchemaNoDeps();
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
         
         // delete it now
-        schemaRoot.destroySubcontext( "cn=dummy" );
+        connection.delete( dn );
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
     }
     
@@ -724,27 +732,23 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectSchemaDeleteWithDependents() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-
         // add the dummy schema enabled
         testAddEnabledSchemaNoDeps();
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
         
         // make the nis schema depend on the dummy schema
-        ModificationItem[] mods = new ModificationItem[1];
-        mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE,
-                new BasicAttribute( "m-dependencies", "dummy" ) );
-        schemaRoot.modifyAttributes( "cn=nis", mods );
+        connection.modify( "cn=nis,ou=schema",
+            new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "m-dependencies", "dummy" ) );
         
         // attempt to delete it now & it should fail
         try
         {
-            schemaRoot.destroySubcontext( "cn=dummy" );
+            connection.delete( "cn=dummy,ou=schema" );
             fail( "should not be able to delete a schema with dependents" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
-            // expected        
+            // expected
         }
 
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
@@ -752,7 +756,7 @@ public class MetaSchemaHandlerIT extends
     
     
     /**
-     * Tests the rejection of a new metaSchema object that is enabled 
+     * Tests the rejection of a new metaSchema object that is enabled
      * on addition and missing dependencies.
      *
      * @throws Exception on error
@@ -761,9 +765,10 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectEnabledSchemaAddWithMisingDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
+        Dn dn = new Dn( "cn=dummy,ou=schema" );
 
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
+        Entry dummySchema = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
@@ -771,12 +776,12 @@ public class MetaSchemaHandlerIT extends
         
         try
         {
-            schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+            connection.add( dummySchema );
             fail( "should not be able to add enabled schema with deps on missing schemas" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
-            // expected        
+            // expected
         }
         
         assertFalse( IntegrationUtils.isEnabled( getService(), "dummy" ) );
@@ -784,10 +789,10 @@ public class MetaSchemaHandlerIT extends
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=dummy" );
+            connection.lookup( "cn=dummy,ou=schema" );
             fail( "schema should not be added to schema partition" );
         }
-        catch( NamingException e )
+        catch( LdapException e )
         {
         }
     }
@@ -804,54 +809,52 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testDisableSchemaWithEnabledDependents() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-
         // let's enable the test schema and add the dummy schema
         // as enabled by default and dependends on the test schema
         
         // enables the test schema and samba
-        testEnableExistingSchema(); 
+        testEnableExistingSchema();
         
-        // adds enabled dummy schema that depends on the test schema  
-        Attributes dummySchema = LdifUtils.createJndiAttributes( 
-            "objectClass: top", 
+        // adds enabled dummy schema that depends on the test schema
+        Dn dn = new Dn( "cn=dummy, ou=schema" );
+        
+        Entry dummySchema = new DefaultEntry(
+            dn,
+            "objectClass: top",
             "objectClass", MetaSchemaConstants.META_SCHEMA_OC,
             "cn: dummy",
             "m-dependencies: nis" );
         
-        schemaRoot.createSubcontext( "cn=dummy", dummySchema );
+        connection.add( dummySchema );
         
         // check that the nis schema is loaded and the dummy schema is loaded
         assertTrue( IntegrationUtils.isEnabled( getService(), "nis" ) );
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
         
-        // double check and make sure an attribute from that schema is 
+        // double check and make sure an attribute from that schema is
         // in the AttributeTypeRegistry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
         
-        // now try to disable the test schema which should fail 
+        // now try to disable the test schema which should fail
         // since it's dependent, the dummy schema, is enabled
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-disabled", "TRUE" );
-        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        
         try
         {
-            schemaRoot.modifyAttributes( "cn=nis", mods );
+            connection.modify( "cn=nis,ou=schema",
+                new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "TRUE" ) );
             fail( "attempt to disable schema with enabled dependents should fail" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
-            // expected        
+            // expected
         }
         
-        // now test that both schema are still loaded 
+        // now test that both schema are still loaded
         assertTrue( IntegrationUtils.isEnabled( getService(), "nis" ) );
         assertTrue( IntegrationUtils.isEnabled( getService(), "dummy" ) );
         
-        // double check and make sure the test attribute from the test  
+        // double check and make sure the test attribute from the test
         // schema is still loaded and present within the attr registry
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( UID_NUMBER_ATTR ) );
     }
     
     
@@ -860,7 +863,7 @@ public class MetaSchemaHandlerIT extends
     // -----------------------------------------------------------------------
     /**
      * Makes sure we can change the name of a schema with entities in it.
-     * Will use the samba schema which comes out of the box and nothing 
+     * Will use the samba schema which comes out of the box and nothing
      * depends on.
      *
      * @throws Exception on error
@@ -869,25 +872,24 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testSchemaRenameDisabledSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        schemaRoot.rename( "cn=samba", "cn=foo" );
-        assertNotNull( schemaRoot.lookup( "cn=foo" ) );
+        connection.rename( "cn=samba,ou=schema", "cn=foo" );
+        assertNotNull( connection.lookup( "cn=foo,ou=schema" ) );
 
         // check that there is a samba schema installed and that is is disabled
-        Attributes attributes = schemaRoot.getAttributes( "cn=foo" );
-        assertNotNull( attributes );
-        assertTrue( attributes.get( MetaSchemaConstants.M_DISABLED_AT ).contains( "TRUE" ) );
-        attributes = schemaRoot.getAttributes( "ou=attributeTypes,cn=foo" );
-        assertNotNull( attributes );
-        assertTrue( attributes.get( SchemaConstants.OU_AT ).contains( "attributetypes" ) );
+        Entry entry = connection.lookup( "cn=foo,ou=schema" );
+        assertNotNull( entry );
+        assertTrue( entry.get( MetaSchemaConstants.M_DISABLED_AT ).contains( "TRUE" ) );
+        entry = connection.lookup( "ou=attributeTypes,cn=foo,ou=schema" );
+        assertNotNull( entry );
+        assertTrue( entry.get( SchemaConstants.OU_AT ).contains( "attributetypes" ) );
 
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=samba" );
+            connection.lookup( "cn=samba,ou=schema" );
             fail( "the samba schema should not be present after a rename to foo" );
         }
-        catch( NameNotFoundException e )
+        catch( LdapException e )
         {
         }
     }
@@ -904,26 +906,25 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectSchemaRenameWithDeps() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
         try
         {
-            schemaRoot.rename( "cn=nis", "cn=foo" );
+            connection.rename( "cn=nis,ou=schema", "cn=foo" );
             fail( "should not be able to rename nis which has samba as it's dependent" );
         }
-        catch ( OperationNotSupportedException onse )
+        catch ( LdapException onse )
         {
-            // expected        
+            // expected
         }
         
-        assertNotNull( schemaRoot.lookup( "cn=nis" ) );
+        assertNotNull( connection.lookup( "cn=nis,ou=schema" ) );
 
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=foo" );
+            connection.lookup( "cn=foo,ou=schema" );
             fail( "the foo schema should not be present after rejecting the rename" );
         }
-        catch( NameNotFoundException e )
+        catch( LdapException e )
         {
         }
     }
@@ -931,7 +932,7 @@ public class MetaSchemaHandlerIT extends
 
     /**
      * Makes sure we can change the name of a schema with entities in it.
-     * Will use the samba schema which comes out of the box and nothing 
+     * Will use the samba schema which comes out of the box and nothing
      * depends on.
      *
      * @throws Exception on error
@@ -940,24 +941,22 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testSchemaRenameEnabledSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-
         IntegrationUtils.enableSchema( getService(), "samba" );
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "sambaNTPassword" ) );
-        assertEquals( "samba", getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "sambaNTPassword" ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "sambaNTPassword" ) );
+        assertEquals( "samba", schemaManager.getAttributeTypeRegistry().getSchemaName( "sambaNTPassword" ) );
         
-        schemaRoot.rename( "cn=samba", "cn=foo" );
-        assertNotNull( schemaRoot.lookup( "cn=foo" ) );
-        assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "sambaNTPassword" ) );
-        assertEquals( "foo", getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "sambaNTPassword" ) );
+        connection.rename( "cn=samba,ou=schema", "cn=foo" );
+        assertNotNull( connection.lookup( "cn=foo, ou=schema" ) );
+        assertTrue( schemaManager.getAttributeTypeRegistry().contains( "sambaNTPassword" ) );
+        assertEquals( "foo", schemaManager.getAttributeTypeRegistry().getSchemaName( "sambaNTPassword" ) );
 
         //noinspection EmptyCatchBlock
         try
         {
-            schemaRoot.lookup( "cn=samba" );
+            connection.lookup( "cn=samba, ou=schema" );
             fail( "the samba schema should not be present after a rename to foo" );
         }
-        catch( NameNotFoundException e )
+        catch( LdapException e )
         {
         }
     }
@@ -967,7 +966,7 @@ public class MetaSchemaHandlerIT extends
     // Dependency Modify Tests
     // -----------------------------------------------------------------------
     /**
-     * Checks to make sure the addition of an undefined schema to the dependencies 
+     * Checks to make sure the addition of an undefined schema to the dependencies
      * of an existing schema fail with an UNWILLING_TO_PERFORM result code.
      *
      * @throws Exception on error
@@ -976,28 +975,23 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectAddBogusDependency() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-dependencies", "bogus" );
-        mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
-        
         try
         {
-            schemaRoot.modifyAttributes( "cn=nis", mods );
+            connection.modify( "cn=nis,ou=schema",
+                new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "m-dependencies", "bogus" ));
             fail( "Should not be able to add bogus dependency to schema" );
         }
-        catch ( OperationNotSupportedException onse )
+        catch ( LdapException onse )
         {
-            // expected        
+            // expected
         }
     }
 
 
     /**
-     * Checks to make sure the addition of an defined yet disabled schema to the 
-     * dependencies of an existing enabled schema fails with an UNWILLING_TO_PERFORM 
-     * result code.  You must enable the dependency to add it or disable the schema 
+     * Checks to make sure the addition of an defined yet disabled schema to the
+     * dependencies of an existing enabled schema fails with an UNWILLING_TO_PERFORM
+     * result code.  You must enable the dependency to add it or disable the schema
      * depending on it to add it.
      *
      * @throws Exception on error
@@ -1006,27 +1000,24 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testRejectAddOfDisabledDependencyToEnabledSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
         IntegrationUtils.enableSchema( getService(), "nis" );
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-dependencies", "mozilla" );
-        mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
         
         try
         {
-            schemaRoot.modifyAttributes( "cn=nis", mods );
+            connection.modify( "cn=nis,ou=schema",
+                new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "m-dependencies", "mozilla" ) );
             fail( "Should not be able to add disabled dependency to schema" );
         }
-        catch ( OperationNotSupportedException onse )
+        catch ( LdapException onse )
         {
-            // expected        
+            // expected
         }
     }
 
 
     /**
-     * Checks to make sure the addition of an defined yet disabled schema to the 
-     * dependencies of an existing disabled schema succeeds. 
+     * Checks to make sure the addition of an defined yet disabled schema to the
+     * dependencies of an existing disabled schema succeeds.
      *
      * @throws Exception on error
      */
@@ -1034,19 +1025,17 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testAddOfDisabledDependencyToDisabledSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-dependencies", "mozilla" );
-        mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
-        schemaRoot.modifyAttributes( "cn=nis", mods );
-        Attributes attrs = schemaRoot.getAttributes( "cn=nis" );
-        Attribute dependencies = attrs.get( "m-dependencies" );
+        connection.modify( "cn=nis,ou=schema",
+            new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "m-dependencies", "mozilla" ) );
+
+        Entry entry = connection.lookup( "cn=nis,ou=schema" );
+        Attribute dependencies = entry.get( "m-dependencies" );
         assertTrue( dependencies.contains( "mozilla" ) );
     }
 
 
     /**
-     * Checks to make sure the addition of an defined yet enabled schema to the 
+     * Checks to make sure the addition of an defined yet enabled schema to the
      * dependencies of an existing disabled schema succeeds.
      *
      * @throws Exception on error
@@ -1055,13 +1044,10 @@ public class MetaSchemaHandlerIT extends
     @Ignore
     public void testAddOfEnabledDependencyToDisabledSchema() throws Exception
     {
-        LdapContext schemaRoot = getSchemaContext( getService() );
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-dependencies", "java" );
-        mods[0] = new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
-        schemaRoot.modifyAttributes( "cn=nis", mods );
-        Attributes attrs = schemaRoot.getAttributes( "cn=nis" );
-        Attribute dependencies = attrs.get( "m-dependencies" );
+        connection.modify( "cn=nis,ou=schema",
+            new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "m-dependencies", "java" ) );
+        Entry entry = connection.lookup( "cn=nis,ou=schema" );
+        Attribute dependencies = entry.get( "m-dependencies" );
         assertTrue( dependencies.contains( "java" ) );
     }
 }

Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.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/MetaSyntaxCheckerHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.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,26 +28,22 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
-import javax.naming.InvalidNameException;
-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.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.ldif.LdifUtils;
 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.LdapSyntax;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker;
-import org.apache.directory.shared.ldap.util.JndiUtils;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -68,12 +63,14 @@ public class MetaSyntaxCheckerHandlerIT 
     private static final String OID = "1.3.6.1.4.1.18060.0.4.0.0.100000";
     private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.0.100001";
 
-    public static SchemaManager schemaManager;
-
+    private static LdapConnection connection;
+    private static SchemaManager schemaManager;
 
     @Before
-    public void setup()
+    public void setup() throws Exception
     {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
         schemaManager = getService().getSchemaManager();
     }
 
@@ -84,13 +81,18 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testAddSyntaxCheckerToEnabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID,
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntaxChecker",
+            "m-fqcn", OctetStringSyntaxChecker.class.getName(),
+            "m-oid", OID,
             "m-description: A test syntaxChecker" );
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertTrue( schemaManager.getSyntaxCheckerRegistry().contains( OID ) );
         assertEquals( schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" );
@@ -103,14 +105,19 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testAddSyntaxCheckerToDisabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID,
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntaxChecker",
+            "m-fqcn", OctetStringSyntaxChecker.class.getName(),
+            "m-oid", OID,
             "m-description: A test syntaxChecker" );
 
         // nis is by default inactive
-        Dn dn = getSyntaxCheckerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertFalse( "adding new syntaxChecker to disabled schema should not register it into the registries",
             schemaManager.getSyntaxCheckerRegistry().contains( OID ) );
@@ -121,20 +128,23 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testAddSyntaxCheckerToUnloadedSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaSyntaxChecker", "m-fqcn", OctetStringSyntaxChecker.class.getName(), "m-oid", OID,
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=notloaded,ou=schema" );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntaxChecker",
+            "m-fqcn", OctetStringSyntaxChecker.class.getName(),
+            "m-oid", OID,
             "m-description: A test syntaxChecker" );
 
         // nis is by default inactive
-        Dn dn = getSyntaxCheckerContainer( "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.
         }
@@ -156,14 +166,19 @@ public class MetaSyntaxCheckerHandlerIT 
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaSyntaxChecker", "m-fqcn",
-            "org.apache.directory.shared.ldap.model.schema.syntaxCheckers.DummySyntaxChecker", "m-bytecode", out
-                .toByteArray(), "m-oid", OID, "m-description: A test syntaxChecker" );
-
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+        
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntaxChecker",
+            "m-fqcn", "org.apache.directory.shared.ldap.model.schema.syntaxCheckers.DummySyntaxChecker",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test syntaxChecker" );
+
+        connection.add( entry );
 
         assertTrue( schemaManager.getSyntaxCheckerRegistry().contains( OID ) );
         assertEquals( schemaManager.getSyntaxCheckerRegistry().getSchemaName( OID ), "apachemeta" );
@@ -184,14 +199,19 @@ public class MetaSyntaxCheckerHandlerIT 
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes("objectClass: top", "objectClass: metaTop",
-                "objectClass: metaSyntaxChecker", "m-fqcn",
-                "org.apache.directory.shared.ldap.model.schema.syntaxCheckers.DummySyntaxChecker", "m-bytecode", out
-                .toByteArray(), "m-oid", OID, "m-description: A test syntaxChecker");
-
-        Dn dn = getSyntaxCheckerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntaxChecker",
+            "m-fqcn", "org.apache.directory.shared.ldap.model.schema.syntaxCheckers.DummySyntaxChecker",
+            "m-bytecode", out.toByteArray(),
+            "m-oid", OID,
+            "m-description: A test syntaxChecker");
+
+        connection.add( entry );
 
         assertFalse( schemaManager.getSyntaxCheckerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
@@ -201,15 +221,15 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testDeleteSyntaxCheckerFromEnabledSchema() throws Exception
     {
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+
         testAddSyntaxCheckerToEnabledSchema();
 
         assertTrue( "syntaxChecker should be removed from the registry after being deleted", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "syntaxChecker should be removed from the registry after being deleted", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
@@ -230,15 +250,15 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testDeleteSyntaxCheckerFromDisabledSchema() throws Exception
     {
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+
         testAddSyntaxCheckerToEnabledSchema();
 
         assertTrue( "syntaxChecker should be removed from the registry after being deleted", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "syntaxChecker should be removed from the registry after being deleted", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
@@ -260,13 +280,12 @@ public class MetaSyntaxCheckerHandlerIT 
     @Ignore
     public void testRenameSyntaxChecker() throws Exception
     {
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn newdn = getSyntaxCheckerContainer( "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 syntaxChecker OID should be removed from the registry after being renamed", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
@@ -293,13 +312,11 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getSyntaxCheckerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName(dn), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry()
             .contains( OID ) );
@@ -318,13 +335,11 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        Dn newdn = getSyntaxCheckerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=syntaxCheckers,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.moveAndRename( dn, newDn );
 
         assertFalse( "old syntaxChecker OID should NOT be present", schemaManager.getSyntaxCheckerRegistry().contains(
             OID ) );
@@ -346,13 +361,11 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-fqcn", BogusSyntaxChecker.class.getName() );
-        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+        Modification mod = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BogusSyntaxChecker.class.getName() );
+        connection.modify( dn, mod );
 
         assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry()
             .contains( OID ) );
@@ -371,12 +384,11 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-fqcn", BogusSyntaxChecker.class.getName() );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+        Modification mod = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BogusSyntaxChecker.class.getName() );
+        connection.modify( dn, mod );
 
         assertTrue( "syntaxChecker OID should still be present", schemaManager.getSyntaxCheckerRegistry()
             .contains( OID ) );
@@ -395,38 +407,41 @@ public class MetaSyntaxCheckerHandlerIT 
     @Test
     public void testDeleteSyntaxCheckerWhenInUse() throws Exception
     {
-        Dn scDn = getSyntaxCheckerContainer( "apachemeta" );
-        scDn = scDn.add( "m-oid" + "=" + OID );
+        Dn scDn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
         // Create a new SyntaxChecker
         testAddSyntaxCheckerToEnabledSchema();
         assertTrue( isOnDisk( scDn ) );
-        assertTrue( getService().getSchemaManager().getSyntaxCheckerRegistry().contains( OID ) );
+        assertTrue( schemaManager.getSyntaxCheckerRegistry().contains( OID ) );
 
         // Create a Syntax using this comparator
-        Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
-            "objectClass: metaSyntax", "m-oid", OID, "m-description: test" );
+        Dn sDn = new Dn( "m-oid=" + OID + ",ou=syntaxes,cn=apachemeta,ou=schema" );
 
-        Dn sDn = getSyntaxContainer( "apachemeta" );
-        sDn = sDn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            sDn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaSyntax",
+            "m-oid", OID,
+            "m-description: test" );
 
         // Pre-checks
         assertFalse( isOnDisk( sDn ) );
-        assertFalse( getService().getSchemaManager().getLdapSyntaxRegistry().contains( OID ) );
+        assertFalse( schemaManager.getLdapSyntaxRegistry().contains( OID ) );
 
         // Syntax Addition
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( sDn ), attrs );
+        connection.add( entry );
 
         // Post-checks
         assertTrue( isOnDisk( sDn ) );
-        assertTrue( getService().getSchemaManager().getLdapSyntaxRegistry().contains( OID ) );
+        assertTrue( schemaManager.getLdapSyntaxRegistry().contains( OID ) );
 
         try
         {
-            getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( scDn ) );
+            connection.delete( scDn );
             fail( "should not be able to delete a syntaxChecker in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -442,18 +457,15 @@ public class MetaSyntaxCheckerHandlerIT 
         testAddSyntaxCheckerToEnabledSchema();
         schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() );
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
-        Dn newdn = getSyntaxCheckerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,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 syntaxChecker in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -471,18 +483,15 @@ public class MetaSyntaxCheckerHandlerIT 
         testAddSyntaxCheckerToEnabledSchema();
         schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() );
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
-        Dn newdn = getSyntaxCheckerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=syntaxCheckers,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 syntaxChecker in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -497,20 +506,19 @@ public class MetaSyntaxCheckerHandlerIT 
     @Ignore
     public void testRenameSyntaxCheckerWhenInUse() throws Exception
     {
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
+
         testAddSyntaxCheckerToEnabledSchema();
         schemaManager.getLdapSyntaxRegistry().register( new DummySyntax() );
 
-        Dn newdn = getSyntaxCheckerContainer( "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 syntaxChecker in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -531,18 +539,16 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        Dn top = new Dn();
-        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 syntaxChecker up to ou=schema" );
         }
-        catch ( InvalidNameException e )
+        catch ( LdapException e )
         {
         }
 
@@ -557,18 +563,16 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,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 syntaxChecker into comparators container" );
         }
-        catch ( InvalidNameException e )
+        catch ( LdapException e )
         {
         }
 
@@ -583,14 +587,12 @@ public class MetaSyntaxCheckerHandlerIT 
     {
         testAddSyntaxCheckerToEnabledSchema();
 
-        Dn dn = getSyntaxCheckerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getSyntaxCheckerContainer( "nis" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "syntaxChecker OID should no longer be present", schemaManager.getSyntaxCheckerRegistry()
             .contains( OID ) );
@@ -604,16 +606,14 @@ public class MetaSyntaxCheckerHandlerIT 
         testAddSyntaxCheckerToDisabledSchema();
 
         // nis is inactive by default
-        Dn dn = getSyntaxCheckerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=nis,ou=schema" );
 
         assertFalse( "syntaxChecker OID should NOT be present when added to disabled nis schema", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );
 
-        Dn newdn = getSyntaxCheckerContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=syntaxCheckers,cn=apachemeta,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "syntaxChecker OID should be present when moved to enabled schema", schemaManager
             .getSyntaxCheckerRegistry().contains( OID ) );