directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1209069 [3/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/MetaNormalizerHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.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/MetaNormalizerHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.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,28 +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.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.normalizers.DeepTrimNormalizer;
 import org.apache.directory.shared.ldap.model.schema.normalizers.NoOpNormalizer;
-import org.apache.directory.shared.ldap.util.JndiUtils;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -71,11 +67,14 @@ public class MetaNormalizerHandlerIT ext
     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 init() throws Exception
     {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
         schemaManager = getService().getSchemaManager();
     }
 
@@ -86,7 +85,10 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testAddNormalizerToEnabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaNormalizer",
@@ -94,9 +96,7 @@ public class MetaNormalizerHandlerIT ext
             "m-oid", OID,
             "m-description: A test normalizer" );
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertTrue( schemaManager.getNormalizerRegistry().contains( OID ) );
         assertEquals( schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
@@ -109,7 +109,11 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testAddNormalizerToDisabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        // nis is by default inactive
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaNormalizer",
@@ -117,10 +121,8 @@ public class MetaNormalizerHandlerIT ext
             "m-oid", OID,
             "m-description: A test normalizer" );
 
-        // nis is by default inactive
-        Dn dn = getNormalizerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+
+        connection.add( entry );
 
         assertFalse( "adding new normalizer to disabled schema should not register it into the registries",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -131,7 +133,11 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testAddNormalizerToUnloadedSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        // nis is by default inactive
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=notloaded,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaNormalizer",
@@ -139,16 +145,12 @@ public class MetaNormalizerHandlerIT ext
             "m-oid", OID,
             "m-description: A test normalizer" );
 
-        // nis is by default inactive
-        Dn dn = getNormalizerContainer( "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.
         }
@@ -170,7 +172,10 @@ public class MetaNormalizerHandlerIT ext
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaNormalizer",
@@ -179,9 +184,7 @@ public class MetaNormalizerHandlerIT ext
             "m-oid", OID,
             "m-description: A test normalizer" );
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         assertTrue( schemaManager.getNormalizerRegistry().contains( OID ) );
         assertEquals( schemaManager.getNormalizerRegistry().getSchemaName( OID ), "apachemeta" );
@@ -202,7 +205,10 @@ public class MetaNormalizerHandlerIT ext
             out.write( in.read() );
         }
 
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaNormalizer",
@@ -210,10 +216,8 @@ public class MetaNormalizerHandlerIT ext
             "m-bytecode", out.toByteArray(),
             "m-oid", OID,
             "m-description: A test normalizer" );
-
-        Dn dn = getNormalizerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        
+        connection.add( entry );
 
         assertFalse( schemaManager.getNormalizerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
@@ -223,15 +227,15 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testDeleteNormalizerFromEnabledSchema() throws Exception
     {
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+
         testAddNormalizerToEnabledSchema();
 
         assertTrue( "normalizer should be removed from the registry after being deleted",
             schemaManager.getNormalizerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "normalizer should be removed from the registry after being deleted",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -252,15 +256,15 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testDeleteNormalizerFromDisabledSchema() throws Exception
     {
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+
         testAddNormalizerToEnabledSchema();
 
         assertTrue( "normalizer should be removed from the registry after being deleted",
             schemaManager.getNormalizerRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "normalizer should be removed from the registry after being deleted",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -282,13 +286,12 @@ public class MetaNormalizerHandlerIT ext
     @Ignore
     public void testRenameNormalizer() throws Exception
     {
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
         testAddNormalizerToEnabledSchema();
 
-        Dn newdn = getNormalizerContainer( "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 normalizer OID should be removed from the registry after being renamed",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -315,13 +318,11 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
 
-        Dn newdn = getNormalizerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "normalizer OID should still be present",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -340,13 +341,10 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
-        Dn newdn = getNormalizerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=normalizers,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.moveAndRename( dn, newDn );
 
         assertFalse( "old normalizer OID should NOT be present",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -368,13 +366,12 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
 
-        ModificationItem[] mods = new ModificationItem[1];
-        Attribute attr = new BasicAttribute( "m-fqcn", DeepTrimNormalizer.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", DeepTrimNormalizer.class.getName() );
+        
+        connection.modify( dn, mod );
 
         assertTrue( "normalizer OID should still be present",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -393,12 +390,11 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-fqcn", DeepTrimNormalizer.class.getName() );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+        Modification mod = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", DeepTrimNormalizer.class.getName() );
+        connection.modify( dn, mod );
 
         assertTrue( "normalizer OID should still be present",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -417,16 +413,18 @@ public class MetaNormalizerHandlerIT ext
     @Test
     public void testDeleteNormalizerWhenInUse() throws Exception
     {
-        Dn nDn = getNormalizerContainer( "apachemeta" );
-        nDn = nDn.add( "m-oid" + "=" + OID );
+        Dn nDn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apachemeta,ou=schema" );
 
         // Create a new Normalizer
         testAddNormalizerToEnabledSchema();
         assertTrue( isOnDisk( nDn ) );
-        assertTrue( getService().getSchemaManager().getNormalizerRegistry().contains( OID ) );
+        assertTrue( schemaManager.getNormalizerRegistry().contains( OID ) );
 
         // Create a MR using this Normalizer
-        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",
@@ -434,26 +432,23 @@ public class MetaNormalizerHandlerIT 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( nDn ) );
+            connection.delete( nDn );
             fail( "should not be able to delete a Normalizer in use" );
         }
-        catch ( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -469,18 +464,15 @@ public class MetaNormalizerHandlerIT ext
         testAddNormalizerToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
-        Dn newdn = getNormalizerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=normalizers,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 normalizer in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -498,18 +490,15 @@ public class MetaNormalizerHandlerIT ext
         testAddNormalizerToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-
-        Dn newdn = getNormalizerContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=normalizers,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 normalizer in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -524,20 +513,19 @@ public class MetaNormalizerHandlerIT ext
     @Ignore
     public void testRenameNormalizerWhenInUse() throws Exception
     {
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
+
         testAddNormalizerToEnabledSchema();
         schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
 
-        Dn newdn = getNormalizerContainer( "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 normalizer in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -559,15 +547,13 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,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 normalizer up to ou=schema" );
         }
         catch( LdapInvalidDnException e )
@@ -586,15 +572,13 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,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 normalizer into comparators container" );
         }
         catch( LdapInvalidDnException e )
@@ -613,14 +597,12 @@ public class MetaNormalizerHandlerIT ext
     {
         testAddNormalizerToEnabledSchema();
 
-        Dn dn = getNormalizerContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getNormalizerContainer( "nis" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "normalizer OID should no longer be present",
             schemaManager.getNormalizerRegistry().contains( OID ) );
@@ -634,16 +616,14 @@ public class MetaNormalizerHandlerIT ext
         testAddNormalizerToDisabledSchema();
 
         // nis is inactive by default
-        Dn dn = getNormalizerContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=nis,ou=schema" );
 
         assertFalse( "normalizer OID should NOT be present when added to disabled nis schema",
             schemaManager.getNormalizerRegistry().contains( OID ) );
 
-        Dn newdn = getNormalizerContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=normalizers,cn=apacheMeta,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "normalizer OID should be present when moved to enabled schema",
             schemaManager.getNormalizerRegistry().contains( OID ) );

Modified: directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.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/MetaObjectClassHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java Thu Dec  1 13:25:26 2011
@@ -20,31 +20,27 @@
 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.InvalidNameException;
-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.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.ObjectClass;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.model.schema.registries.ObjectClassRegistry;
-import org.apache.directory.shared.ldap.util.JndiUtils;
+import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -72,15 +68,31 @@ public class MetaObjectClassHandlerIT ex
     private static final String DEPENDEE_OID = "1.3.6.1.4.1.18060.0.4.0.3.100002";
 
 
+
+    public static SchemaManager schemaManager;
+    private static LdapConnection connection;
+
+
+    @Before
+    public void setup() throws Exception
+    {
+        super.init();
+        connection = IntegrationUtils.getAdminConnection( getService() );
+        schemaManager = getService().getSchemaManager();
+    }
+
     private static ObjectClassRegistry getObjectClassRegistry()
     {
-        return getService().getSchemaManager().getObjectClassRegistry();
+        return schemaManager.getObjectClassRegistry();
     }
 
 
     private Dn addObjectClass() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaObjectClass",
@@ -91,9 +103,7 @@ public class MetaObjectClassHandlerIT ex
             "m-must: cn",
             "m-may: ou" );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         return dn;
     }
@@ -127,7 +137,10 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddObjectClassToUnloadedSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=notloaded,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaObjectClass",
@@ -138,15 +151,12 @@ public class MetaObjectClassHandlerIT ex
             "m-must: cn",
             "m-may: ou" );
 
-        Dn dn = getObjectClassContainer( "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 )
         {
             // Excpected result
         }
@@ -160,15 +170,15 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testDeleteObjectClassFromEnabledSchema() throws Exception
     {
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
         addObjectClass();
 
         assertTrue( "objectClass should be removed from the registry after being deleted",
             getObjectClassRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "objectClass should be removed from the registry after being deleted",
             getObjectClassRegistry().contains( OID ) );
@@ -189,15 +199,15 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testDeleteObjectClassFromDisabledSchema() throws Exception
     {
-        Dn dn = getObjectClassContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=nis,ou=schema" );
+
         addObjectClassToDisabledSchema();
 
         assertFalse( "objectClass should be removed from the registry after being deleted",
             getObjectClassRegistry().contains( OID ) );
         assertTrue( isOnDisk( dn ) );
 
-        getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+        connection.delete( dn );
 
         assertFalse( "objectClass should be removed from the registry after being deleted",
             getObjectClassRegistry().contains( OID ) );
@@ -219,13 +229,13 @@ public class MetaObjectClassHandlerIT ex
     @Ignore
     public void testRenameObjectClassType() throws Exception
     {
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=nis,ou=schema" );
+
         addObjectClass();
 
-        Dn newdn = getObjectClassContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apachemeta,ou=schema" );
+
+        connection.move( dn, newDn );
 
         assertFalse( "old objectClass OID should be removed from the registry after being renamed",
             getObjectClassRegistry().contains( OID ) );
@@ -250,13 +260,11 @@ public class MetaObjectClassHandlerIT ex
     {
         addObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn newdn = getObjectClassContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "objectClass OID should still be present",
             getObjectClassRegistry().contains( OID ) );
@@ -272,13 +280,11 @@ public class MetaObjectClassHandlerIT ex
     {
         addObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn newdn = getObjectClassContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apache,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "old objectClass OID should NOT be present",
             getObjectClassRegistry().contains( OID ) );
@@ -301,15 +307,14 @@ public class MetaObjectClassHandlerIT ex
         assertEquals( oc.getDescription(), DESCRIPTION0 );
         assertEquals( oc.getName(), NAME );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,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-name", NEW_NAME );
-        mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+        Modification mod1 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-description", DESCRIPTION1 );
+        Modification mod2 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-name", NEW_NAME );
+        
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "objectClass OID should still be present",
             getObjectClassRegistry().contains( OID ) );
@@ -333,13 +338,14 @@ public class MetaObjectClassHandlerIT ex
         assertEquals( oc.getDescription(), DESCRIPTION0 );
         assertEquals( oc.getName(), NAME );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Attributes mods = new BasicAttributes( true );
-        mods.put( "m-description", DESCRIPTION1 );
-        mods.put( "m-name", NEW_NAME );
-        getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+        Modification mod1 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-description", DESCRIPTION1 );
+        Modification mod2 = new DefaultModification(
+            ModificationOperation.REPLACE_ATTRIBUTE, "m-name", NEW_NAME );
+
+        connection.modify( dn, mod1, mod2 );
 
         assertTrue( "objectClass OID should still be present",
             getObjectClassRegistry().contains( OID ) );
@@ -358,22 +364,22 @@ public class MetaObjectClassHandlerIT ex
     // ----------------------------------------------------------------------
     private void addDependeeObjectClass() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-        attrs.put( "m-oid", DEPENDEE_OID );
-        attrs.put( "m-name", DEPENDEE_NAME );
-        attrs.put( "m-description", DESCRIPTION0 );
-        attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-        attrs.put( "m-supObjectClass", OID );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + DEPENDEE_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + DEPENDEE_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+        
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", DEPENDEE_OID,
+            "m-name", DEPENDEE_NAME,
+            "m-description", DESCRIPTION0,
+            "m-typeObjectClass", "AUXILIARY",
+            "m-must: cn",
+            "m-may: ou",
+            "m-supObjectClass", OID );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( DEPENDEE_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
@@ -383,17 +389,17 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testDeleteObjectClassWhenInUse() throws Exception
     {
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
         addObjectClass();
         addDependeeObjectClass();
 
         try
         {
-            getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+            connection.delete( dn );
             fail( "should not be able to delete a objectClass in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -409,18 +415,16 @@ public class MetaObjectClassHandlerIT ex
         addObjectClass();
         addDependeeObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn newdn = getObjectClassContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=objectClasses,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 objectClass in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -436,18 +440,16 @@ public class MetaObjectClassHandlerIT ex
         addObjectClass();
         addDependeeObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn newdn = getObjectClassContainer( "apache" );
-        newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+        Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,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 an objectClass in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch( LdapException e )
         {
         }
 
@@ -460,20 +462,19 @@ public class MetaObjectClassHandlerIT ex
     @Ignore
     public void testRenameObjectClassWhenInUse() throws Exception
     {
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
         addObjectClass();
         addDependeeObjectClass();
 
-        Dn newdn = getObjectClassContainer( "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 an objectClass in use" );
         }
-        catch( OperationNotSupportedException e )
+        catch ( LdapException e )
         {
         }
 
@@ -491,18 +492,16 @@ public class MetaObjectClassHandlerIT ex
     {
         addObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,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 objectClass up to ou=schema" );
         }
-        catch( InvalidNameException e )
+        catch ( LdapException e )
         {
         }
 
@@ -517,18 +516,16 @@ public class MetaObjectClassHandlerIT ex
     {
         addObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,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 objectClass into comparators container" );
         }
-        catch( InvalidNameException e )
+        catch( LdapException e )
         {
         }
 
@@ -539,7 +536,10 @@ public class MetaObjectClassHandlerIT ex
 
     private Dn addObjectClassToDisabledSchema() throws Exception
     {
-        Attributes attrs = LdifUtils.createJndiAttributes(
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=nis,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
             "objectClass: top",
             "objectClass: metaTop",
             "objectClass: metaObjectClass",
@@ -550,9 +550,7 @@ public class MetaObjectClassHandlerIT ex
             "m-must: cn",
             "m-may: ou" );
 
-        Dn dn = getObjectClassContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        connection.add( entry );
 
         return dn;
     }
@@ -564,14 +562,12 @@ public class MetaObjectClassHandlerIT ex
     {
         addObjectClass();
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
         // nis is inactive by default
-        Dn newdn = getObjectClassContainer( "nis" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=nis,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertFalse( "objectClass OID should no longer be present",
             getObjectClassRegistry().contains( OID ) );
@@ -585,16 +581,14 @@ public class MetaObjectClassHandlerIT ex
         addObjectClassToDisabledSchema();
 
         // nis is inactive by default
-        Dn dn = getObjectClassContainer( "nis" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=nis,ou=schema" );
 
         assertFalse( "objectClass OID should NOT be present when added to disabled nis schema",
             getObjectClassRegistry().contains( OID ) );
 
-        Dn newdn = getObjectClassContainer( "apachemeta" );
-        newdn = newdn.add( "m-oid" + "=" + OID );
+        Dn newDn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apachemeta,ou=schema" );
 
-        getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+        connection.move( dn, newDn );
 
         assertTrue( "objectClass OID should be present when moved to enabled schema",
             getObjectClassRegistry().contains( OID ) );
@@ -602,6 +596,7 @@ public class MetaObjectClassHandlerIT ex
         assertEquals( "objectClass should be in apachemeta schema after move",
             getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
     }
+    
 
     // ----------------------------------------------------------------------
     // Let's test the Abstract, Auiliary and Structural inheritence enforcement
@@ -612,23 +607,22 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAbstractOCinheritingFromAbstractOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "ABSTRACT" );
-        attrs.put( "m-supObjectClass", "top" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: ABSTRACT",
+            "m-supObjectClass: top",
+            "m-must: cn",
+            "m-may: ou" );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
@@ -641,33 +635,28 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAbstractOCinheritingFromAuxiliaryOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "ABSTRACT" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "javaSerializedObject");
-        attrs.put( sup );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: ABSTRACT",
+            "m-supObjectClass: top",
+            "m-supObjectClass: javaSerializedObject",
+            "m-must: cn",
+            "m-may: ou" );
 
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail();
         }
-        catch ( NamingException ne )
+        catch ( LdapException ne )
         {
             assertTrue( true );
         }
@@ -680,33 +669,28 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAbstractOCinheritingFromStructuralOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "ABSTRACT" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "person");
-        attrs.put( sup );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: ABSTRACT",
+            "m-supObjectClass: top",
+            "m-supObjectClass: person",
+            "m-must: cn",
+            "m-may: ou" );
 
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail();
         }
-        catch ( NamingException ne )
+        catch ( LdapException ne )
         {
             assertTrue( true );
         }
@@ -719,23 +703,22 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAuxiliaryOCinheritingFromAbstractOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", NEW_OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-supObjectClass", "top" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", NEW_OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: AUXILIARY",
+            "m-supObjectClass: top",
+            "m-must: cn",
+            "m-may: ou" );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
@@ -748,27 +731,23 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAuxiliaryOCinheritingFromAuxiliaryOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", NEW_OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "AUXILIARY" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "javaNamingReference");
-        attrs.put( sup );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", NEW_OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: AUXILIARY",
+            "m-supObjectClass: top",
+            "m-supObjectClass: javaNamingReference",
+            "m-must: cn",
+            "m-may: ou" );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
@@ -781,33 +760,28 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddAuxiliaryOCinheritingFromStructuralOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "ABSTRACT" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "person");
-        attrs.put( sup );
+        Dn dn = new Dn( "m-oid=" + OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
 
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + OID );
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: ABSTRACT",
+            "m-supObjectClass: top",
+            "m-supObjectClass: person",
+            "m-must: cn",
+            "m-may: ou" );
 
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail();
         }
-        catch ( NamingException ne )
+        catch ( LdapException ne )
         {
             assertTrue( true );
         }
@@ -820,23 +794,22 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddStructuralOCinheritingFromAbstractOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", NEW_OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "STRUCTURAL" );
-        attrs.put( "m-supObjectClass", "top" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+        
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", NEW_OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: STRUCTURAL",
+            "m-supObjectClass: top",
+            "m-must: cn",
+            "m-may: ou" );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );
@@ -849,33 +822,28 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddStructuralOCinheritingFromAuxiliaryOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", NEW_OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "STRUCTURAL" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "javaNamingReference");
-        attrs.put( sup );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + NEW_OID );
+        Dn dn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+        
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", NEW_OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: STRUCTURAL",
+            "m-supObjectClass: top",
+            "m-supObjectClass: javaNamingReference",
+            "m-must: cn",
+            "m-may: ou" );
 
         try
         {
-            getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+            connection.add( entry );
             fail();
         }
-        catch ( NamingException ne )
+        catch ( LdapException ne )
         {
             assertTrue( true );
         }
@@ -888,27 +856,23 @@ public class MetaObjectClassHandlerIT ex
     @Test
     public void testAddStructuralOCinheritingFromStructuralOC() throws Exception
     {
-        Attributes attrs = new BasicAttributes( true );
-        Attribute oc = new BasicAttribute( "objectClass", "top" );
-        oc.add( "metaTop" );
-        oc.add( "metaObjectClass" );
-        attrs.put( oc );
-
-        attrs.put( "m-oid", NEW_OID );
-        attrs.put( "m-name", "abstractOCtest");
-        attrs.put( "m-description", "An abstract oC inheriting from top" );
-        attrs.put( "m-typeObjectClass", "STRUCTURAL" );
-        attrs.put( "m-must", "cn" );
-        attrs.put( "m-may", "ou" );
-
-        Attribute sup = new BasicAttribute( "m-supObjectClass" );
-        sup.add( "top" );
-        sup.add( "person");
-        attrs.put( sup );
-
-        Dn dn = getObjectClassContainer( "apachemeta" );
-        dn = dn.add( "m-oid" + "=" + NEW_OID );
-        getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+        Dn dn = new Dn( "m-oid=" + NEW_OID + ",ou=objectClasses,cn=apacheMeta,ou=schema" );
+        
+        Entry entry = new DefaultEntry(
+            dn,
+            "objectClass: top",
+            "objectClass: metaTop",
+            "objectClass: metaObjectClass",
+            "m-oid", NEW_OID,
+            "m-name: abstractOCtest",
+            "m-description: An abstract oC inheriting from top",
+            "m-typeObjectClass: STRUCTURAL",
+            "m-supObjectClass: top",
+            "m-supObjectClass: person",
+            "m-must: cn",
+            "m-may: ou" );
+
+        connection.add( entry );
 
         assertTrue( getObjectClassRegistry().contains( NEW_OID ) );
         assertEquals( getObjectClassRegistry().getSchemaName( NEW_OID ), "apachemeta" );



Mime
View raw message