You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2011/11/18 12:21:59 UTC
svn commit: r1203604 [2/8] - in /directory/apacheds/branches/apacheds-osgi:
./ all/ apache-felix/ component-hub/ component-hub/src/
component-hub/src/main/ component-hub/src/main/java/
component-hub/src/main/java/org/ component-hub/src/main/java/org/ap...
Modified: directory/apacheds/branches/apacheds-osgi/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=1203604&r1=1203603&r2=1203604&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/branches/apacheds-osgi/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Fri Nov 18 11:21:55 2011
@@ -25,9 +25,6 @@ import java.util.ArrayList;
import java.util.List;
import javax.naming.NamingException;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
@@ -48,6 +45,9 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.entry.Attribute;
import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.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.ChangeType;
import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
@@ -301,25 +301,24 @@ public class IntegrationUtils
public static void enableSchema( DirectoryService service, String schemaName ) throws Exception
{
- LdapContext schemaRoot = getSchemaContext( service );
+ LdapConnection connection = getAdminConnection( service );
// now enable the test schema
- ModificationItem[] mods = new ModificationItem[1];
- javax.naming.directory.Attribute attr = new BasicAttribute( "m-disabled", "FALSE" );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
+ connection.modify( "cn=" + schemaName + ",ou=schema",
+ new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE" ) );
}
public static void disableSchema( DirectoryService service, String schemaName ) throws Exception
{
- LdapContext schemaRoot = getSchemaContext( service );
+ LdapConnection connection = getAdminConnection( service );
// now enable the test schema
- ModificationItem[] mods = new ModificationItem[1];
- javax.naming.directory.Attribute attr = new BasicAttribute( "m-disabled", "TRUE" );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- schemaRoot.modifyAttributes( "cn=" + schemaName, mods );
+ Modification mod = new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "TRUE" );
+
+ connection.modify( "cn=" + schemaName + ",ou=schema", mod );
}
Propchange: directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Nov 18 11:21:55 2011
@@ -9,5 +9,5 @@
/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:599654-600228
/directory/apacheds/branches/milestones/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:1072812-1075328
/directory/apacheds/branches/xdbm-refactoring/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:945827-946347
-/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:1066126-1067785,1068026-1072718,1072800-1075329,1185681-1201345
+/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:1066126-1067785,1068026-1072718,1072800-1075329,1185681-1201345,1201371-1203550
/directory/studio/trunk/core-integ/src/test/java/org/apache/directory/server/core/collective/CollectiveAttributeServiceIT.java:1067786-1067997
Modified: directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/AbstractMetaSchemaObjectHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/AbstractMetaSchemaObjectHandler.java?rev=1203604&r1=1203603&r2=1203604&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/AbstractMetaSchemaObjectHandler.java (original)
+++ directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/AbstractMetaSchemaObjectHandler.java Fri Nov 18 11:21:55 2011
@@ -37,7 +37,7 @@ public abstract class AbstractMetaSchema
protected static String workingDir;
@Before
- public final void init()
+ public void init() throws Exception
{
workingDir = getService().getInstanceLayout().getPartitionsDirectory().getAbsolutePath();
}
@@ -52,7 +52,7 @@ public abstract class AbstractMetaSchema
{
StringBuilder sb = new StringBuilder();
- sb.append( workingDir ).append( '/' ).append( getService().getSchemaPartition().getId() ).append( '/' ).append( "ou=schema" );
+ sb.append( workingDir ).append( '/' ).append( getService().getSchemaPartition().getId() );
for ( Rdn rdn : dn )
{
@@ -74,7 +74,7 @@ public abstract class AbstractMetaSchema
*/
protected boolean isOnDisk( Dn dn )
{
- // donot change the value of getSchemaPath to lowercase
+ // do not change the value of getSchemaPath to lowercase
// on Linux this gives a wrong path
String schemaObjectFileName = getSchemaPath( dn );
@@ -95,96 +95,4 @@ public abstract class AbstractMetaSchema
{
return new Dn( "cn=" + schemaName );
}
-
-
- /**
- * Gets relative Dn to ou=schema.
- *
- * @param schemaName the name of the schema
- * @return the dn of the a schema's attributeType entity container
- * @throws Exception on failure
- */
- protected Dn getAttributeTypeContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=attributeTypes,cn=" + schemaName );
- }
-
-
- /**
- * Get relative Dn to ou=schema for Comparators
- *
- * @param schemaName the name of the schema
- * @return the dn to the ou under which comparators are found for a schema
- * @throws Exception if there are dn construction issues
- */
- protected Dn getComparatorContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=comparators,cn=" + schemaName );
- }
-
-
- /**
- * Get relative Dn to ou=schema for MatchingRules
- *
- * @param schemaName the name of the schema
- * @return the dn to the ou under which MatchingRules are found for a schema
- * @throws Exception if there are dn construction issues
- */
- protected Dn getMatchingRuleContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=matchingRules,cn=" + schemaName );
- }
-
-
- /**
- * Gets relative Dn to ou=schema.
- *
- * @param schemaName the name of the schema
- * @return the dn of the container which contains objectClasses
- * @throws Exception on error
- */
- protected Dn getObjectClassContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=objectClasses,cn=" + schemaName );
- }
-
-
-
- /**
- * Gets relative Dn to ou=schema.
- *
- * @param schemaName the name of the schema
- * @return the name of the container with normalizer entries in it
- * @throws Exception on error
- */
- protected Dn getNormalizerContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=normalizers,cn=" + schemaName );
- }
-
-
- /**
- * Get relative Dn to ou=schema for Syntaxes
- *
- * @param schemaName the name of the schema
- * @return the dn of the container holding syntaxes for the schema
- * @throws Exception on dn parse errors
- */
- protected Dn getSyntaxContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=syntaxes,cn=" + schemaName );
- }
-
-
- /**
- * Get relative Dn to ou=schema for SyntaxCheckers
- *
- * @param schemaName the name of the schema
- * @return the dn of the container holding syntax checkers for the schema
- * @throws Exception on dn parse errors
- */
- protected Dn getSyntaxCheckerContainer( String schemaName ) throws Exception
- {
- return new Dn( "ou=syntaxCheckers,cn=" + schemaName );
- }
}
Modified: directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java?rev=1203604&r1=1203603&r2=1203604&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java Fri Nov 18 11:21:55 2011
@@ -20,32 +20,32 @@
package org.apache.directory.server.core.schema;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import javax.naming.NameNotFoundException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.ldap.LdapContext;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
import org.apache.directory.shared.ldap.model.schema.AttributeType;
-import org.apache.directory.shared.ldap.util.JndiUtils;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -68,6 +68,18 @@ public class MetaAttributeTypeHandlerIT
private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.2.100001";
private static final String DEPENDEE_OID = "1.3.6.1.4.1.18060.0.4.0.2.100002";
+ private static LdapConnection connection;
+ private SchemaManager schemaManager;
+
+
+ @Before
+ public void init() throws Exception
+ {
+ super.init();
+ connection = IntegrationUtils.getAdminConnection( getService() );
+ schemaManager = getService().getSchemaManager();
+ }
+
// ----------------------------------------------------------------------
// Test all core methods with normal operational pathways
// ----------------------------------------------------------------------
@@ -81,7 +93,9 @@ public class MetaAttributeTypeHandlerIT
@Test
public void testAddAttributeTypeWithoutMatchingRule() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=2.5.4.58,ou=attributeTypes,cn=apachemeta,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
@@ -91,19 +105,16 @@ public class MetaAttributeTypeHandlerIT
"m-description: attribute certificate use ;binary"
);
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=2.5.4.58" );
-
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( "2.5.4.58" ) );
+ assertFalse( schemaManager.getAttributeTypeRegistry().contains( "2.5.4.58" ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
- assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "2.5.4.58" ) );
- assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "2.5.4.58" ), "apachemeta" );
+ assertTrue( schemaManager.getAttributeTypeRegistry().contains( "2.5.4.58" ) );
+ assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( "2.5.4.58" ), "apachemeta" );
assertTrue( isOnDisk( dn ) );
}
@@ -111,30 +122,29 @@ public class MetaAttributeTypeHandlerIT
@Test
public void testAddAttributeTypeToEnabledSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
- "m-oid:" + OID,
- "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
- "m-description:" + DESCRIPTION0,
+ "m-oid", OID,
+ "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+ "m-description", DESCRIPTION0,
"m-equality: caseIgnoreMatch",
"m-singleValue: FALSE",
"m-usage: directoryOperation" );
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
-
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ assertFalse( schemaManager.getAttributeTypeRegistry().contains( OID ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
- assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
- assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+ assertTrue( schemaManager.getAttributeTypeRegistry().contains( OID ) );
+ assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
assertTrue( isOnDisk( dn ) );
}
@@ -142,32 +152,31 @@ public class MetaAttributeTypeHandlerIT
@Test
public void testAddAttributeTypeToUnLoadedSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=notloaded,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
- "m-oid:" + OID,
- "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
- "m-description:" + DESCRIPTION0,
+ "m-oid", OID,
+ "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+ "m-description", DESCRIPTION0,
"m-equality: caseIgnoreMatch",
"m-singleValue: FALSE",
"m-usage: directoryOperation" );
- Dn dn = getAttributeTypeContainer( "notloaded" );
- dn = dn.add( "m-oid=" + OID );
-
try
{
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
fail( "Should not be there" );
}
- catch( NameNotFoundException nnfe )
+ catch( LdapException nnfe )
{
// Expected result.
}
assertFalse( "adding new attributeType to disabled schema should not register it into the registries",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
// The added entry must not be present on disk
assertFalse( isOnDisk( dn ) );
@@ -177,27 +186,26 @@ public class MetaAttributeTypeHandlerIT
@Test
public void testAddAttributeTypeToDisabledSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
- "m-oid:" + OID,
- "m-syntax:" + SchemaConstants.INTEGER_SYNTAX,
- "m-description:" + DESCRIPTION0,
+ "m-oid", OID,
+ "m-syntax", SchemaConstants.INTEGER_SYNTAX,
+ "m-description", DESCRIPTION0,
"m-equality: caseIgnoreMatch",
"m-singleValue: FALSE",
"m-usage: directoryOperation" );
- Dn dn = getAttributeTypeContainer( "nis" );
- dn = dn.add( "m-oid=" + OID );
-
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
assertFalse( "adding new attributeType to disabled schema should not register it into the registries",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
// The GlobalOidRegistries must not contain the AT
- assertFalse( getService().getSchemaManager().getGlobalOidRegistry().contains( OID ) );
+ assertFalse( schemaManager.getGlobalOidRegistry().contains( OID ) );
// The added entry must be present on disk
assertTrue( isOnDisk( dn ) );
@@ -211,7 +219,9 @@ public class MetaAttributeTypeHandlerIT
@Test
public void testAddAttributeTypeDescWithEndingSpace() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=1.3.6.1.4.1.8104.1.1.37,ou=attributeTypes,cn=apachemeta,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
@@ -225,19 +235,16 @@ public class MetaAttributeTypeHandlerIT
"m-singleValue: TRUE"
);
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=1.3.6.1.4.1.8104.1.1.37" );
-
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
+ assertFalse( schemaManager.getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
- assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
- assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( "1.3.6.1.4.1.8104.1.1.37" ), "apachemeta" );
+ assertTrue( schemaManager.getAttributeTypeRegistry().contains( "1.3.6.1.4.1.8104.1.1.37" ) );
+ assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( "1.3.6.1.4.1.8104.1.1.37" ), "apachemeta" );
assertTrue( isOnDisk( dn ) );
}
@@ -250,21 +257,20 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
// Check in Registries
assertTrue( "attributeType should be removed from the registry after being deleted",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
// Check on disk that the added SchemaObject exist
assertTrue( isOnDisk( dn ) );
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+ connection.delete( dn );
// Check in Registries
assertFalse( "attributeType should be removed from the registry after being deleted",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
// Check on disk that the deleted SchemaObject does not exist anymore
assertFalse( isOnDisk( dn ) );
@@ -282,23 +288,22 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToDisabledSchema();
- Dn dn = getAttributeTypeContainer( "nis" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
// Check in Registries
assertFalse( "attributeType should be removed from the registry after being deleted",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
// Check on disk that the added SchemaObject exists
assertTrue( isOnDisk( dn ) );
// Remove the AT
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+ connection.delete( dn );
// Check in Registries
assertFalse( "attributeType should be removed from the registry after being deleted",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
- assertFalse( getService().getSchemaManager().getGlobalOidRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
+ assertFalse( schemaManager.getGlobalOidRegistry().contains( OID ) );
// Check on disk that the deleted SchemaObject does not exist anymore
assertFalse( isOnDisk( dn ) );
@@ -310,21 +315,20 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
addDependeeAttributeType();
try
{
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+ connection.delete( dn );
fail( "should not be able to delete a attributeType in use" );
}
- catch( OperationNotSupportedException e )
+ catch( LdapException e )
{
}
assertTrue( "attributeType should still be in the registry after delete failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -337,27 +341,26 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- AttributeType at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+ AttributeType at = schemaManager.lookupAttributeTypeRegistry( OID );
assertEquals( at.getDescription(), DESCRIPTION0 );
assertEquals( at.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- ModificationItem[] mods = new ModificationItem[2];
- Attribute attr = new BasicAttribute( "m-description", DESCRIPTION1 );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- attr = new BasicAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
- mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+ Attribute attr = new DefaultAttribute( "m-description", DESCRIPTION1 );
+ Modification mod1 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+ attr = new DefaultAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
+ Modification mod2 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr );
+
+ connection.modify( dn, mod1, mod2 );
assertTrue( "attributeType OID should still be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
assertEquals( "attributeType schema should be set to apachemeta",
- getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+ schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
- at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+ at = schemaManager.lookupAttributeTypeRegistry( OID );
assertEquals( at.getDescription(), DESCRIPTION1 );
assertEquals( at.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
}
@@ -369,25 +372,27 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- AttributeType at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+ AttributeType at = schemaManager.lookupAttributeTypeRegistry( OID );
assertEquals( at.getDescription(), DESCRIPTION0 );
assertEquals( at.getSyntax().getOid(), SchemaConstants.INTEGER_SYNTAX );
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+
+ Modification mod1 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
+ new DefaultAttribute( "m-description", DESCRIPTION1 ) );
+
+ Modification mod2 = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
+ new DefaultAttribute( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX ) );
- Attributes mods = new BasicAttributes( true );
- mods.put( "m-description", DESCRIPTION1 );
- mods.put( "m-syntax", SchemaConstants.DIRECTORY_STRING_SYNTAX );
- getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), DirContext.REPLACE_ATTRIBUTE, mods );
+ connection.modify( dn, mod1, mod2 );
assertTrue( "attributeType OID should still be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
assertEquals( "attributeType schema should be set to apachemeta",
- getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+ schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
- at = getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+ at = schemaManager.lookupAttributeTypeRegistry( OID );
assertEquals( at.getDescription(), DESCRIPTION1 );
assertEquals( at.getSyntax().getOid(), SchemaConstants.DIRECTORY_STRING_SYNTAX );
}
@@ -402,21 +407,19 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- LdapContext schemaRoot = getSchemaContext( getService() );
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = getAttributeTypeContainer( "apachemeta" );
- dn = newdn.add( "m-oid=" + NEW_OID );
- schemaRoot.rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ Rdn rdn = new Rdn( "m-oid=" + NEW_OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+
+ connection.rename( dn, rdn );
assertFalse( "old attributeType OID should be removed from the registry after being renamed",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
- getService().getSchemaManager().lookupAttributeTypeRegistry( OID );
+ schemaManager.lookupAttributeTypeRegistry( OID );
fail( "attributeType lookup should fail after renaming the attributeType" );
- assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( NEW_OID ) );
+ assertTrue( schemaManager.getAttributeTypeRegistry().contains( NEW_OID ) );
}
@@ -426,16 +429,14 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
addDependeeAttributeType();
- Dn newdn = getAttributeTypeContainer( "apachemeta" );
- newdn = newdn.add( "m-oid=" + NEW_OID );
+ Rdn rdn = new Rdn( "m-oid=" + NEW_OID );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.rename( dn, rdn );
fail( "should not be able to rename a attributeType in use" );
}
catch( LdapUnwillingToPerformException e )
@@ -444,7 +445,7 @@ public class MetaAttributeTypeHandlerIT
}
assertTrue( "attributeType should still be in the registry after rename failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -457,19 +458,17 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = getAttributeTypeContainer( "apache" );
- newdn = newdn.add( "m-oid=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName(newdn) );
+ connection.move( dn, newDn );
assertTrue( "attributeType OID should still be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
assertEquals( "attributeType schema should be set to apache not apachemeta",
- getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
+ schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
}
@@ -479,22 +478,20 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = getAttributeTypeContainer( "apache" );
- newdn = newdn.add( "m-oid=" + NEW_OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
assertFalse( "old attributeType OID should NOT be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
assertTrue( "new attributeType OID should be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( NEW_OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( NEW_OID ) );
assertEquals( "attributeType with new oid should have schema set to apache NOT apachemeta",
- getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
+ schemaManager.getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
}
@@ -504,15 +501,14 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
Dn top = new Dn();
top = top.add( "m-oid=" + OID );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( top ) );
+ connection.move( dn, top );
fail( "should not be able to move a attributeType up to ou=schema" );
}
catch( LdapInvalidDnException e )
@@ -521,7 +517,7 @@ public class MetaAttributeTypeHandlerIT
}
assertTrue( "attributeType should still be in the registry after move failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -531,15 +527,13 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = new Dn( "ou=comparators,cn=apachemeta" );
- newdn = newdn.add( "m-oid=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
fail( "should not be able to move a attributeType into comparators container" );
}
catch( LdapInvalidDnException e )
@@ -548,7 +542,7 @@ public class MetaAttributeTypeHandlerIT
}
assertTrue( "attributeType should still be in the registry after move failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -558,17 +552,15 @@ public class MetaAttributeTypeHandlerIT
{
testAddAttributeTypeToEnabledSchema();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
// nis is inactive by default
- Dn newdn = getAttributeTypeContainer( "nis" );
- newdn = newdn.add( "m-oid=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=nis,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
assertFalse( "attributeType OID should no longer be present",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -579,15 +571,13 @@ public class MetaAttributeTypeHandlerIT
testAddAttributeTypeToEnabledSchema();
addDependeeAttributeType();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = getAttributeTypeContainer( "apache" );
- newdn = newdn.add( "m-oid=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
fail( "should not be able to move a attributeType in use" );
}
catch( LdapUnwillingToPerformException e )
@@ -596,7 +586,7 @@ public class MetaAttributeTypeHandlerIT
}
assertTrue( "attributeType should still be in the registry after move failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -607,15 +597,13 @@ public class MetaAttributeTypeHandlerIT
testAddAttributeTypeToEnabledSchema();
addDependeeAttributeType();
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
- Dn newdn = getAttributeTypeContainer( "apache" );
- newdn = newdn.add( "m-oid=" + NEW_OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=attributeTypes,cn=apache,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
fail( "should not be able to move a attributeType in use" );
}
catch( LdapUnwillingToPerformException e )
@@ -624,7 +612,7 @@ public class MetaAttributeTypeHandlerIT
}
assertTrue( "attributeType should still be in the registry after move failure",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
}
@@ -633,7 +621,9 @@ public class MetaAttributeTypeHandlerIT
// ----------------------------------------------------------------------
private void addDependeeAttributeType() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn dn = new Dn( "m-oid=" + DEPENDEE_OID + ",ou=attributeTypes,cn=apachemeta,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaAttributeType",
@@ -645,12 +635,10 @@ public class MetaAttributeTypeHandlerIT
"m-usage: directoryOperation",
"m-supAttributeType", OID );
- Dn dn = getAttributeTypeContainer( "apachemeta" );
- dn = dn.add( "m-oid=" + DEPENDEE_OID );
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
- assertTrue( getService().getSchemaManager().getAttributeTypeRegistry().contains( DEPENDEE_OID ) );
- assertEquals( getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
+ assertTrue( schemaManager.getAttributeTypeRegistry().contains( DEPENDEE_OID ) );
+ assertEquals( schemaManager.getAttributeTypeRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
}
@@ -669,18 +657,18 @@ public class MetaAttributeTypeHandlerIT
dn.add( "m-oid=" + OID );
assertFalse( "attributeType OID should NOT be present when added to disabled nis schema",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
Dn newdn = getAttributeTypeContainer( "apachemeta" );
newdn.add( "m-oid=" + OID );
- getSchemaContext( getService() ).rename( dn, newdn );
+ connection.rename( dn, newdn );
assertTrue( "attributeType OID should be present when moved to enabled schema",
- getService().getSchemaManager().getAttributeTypeRegistry().contains( OID ) );
+ schemaManager.getAttributeTypeRegistry().contains( OID ) );
assertEquals( "attributeType should be in apachemeta schema after move",
- getService().getSchemaManager().getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+ schemaManager.getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
}
*/
}
Modified: directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java?rev=1203604&r1=1203603&r2=1203604&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java (original)
+++ directory/apacheds/branches/apacheds-osgi/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java Fri Nov 18 11:21:55 2011
@@ -20,7 +20,6 @@
package org.apache.directory.server.core.schema;
-import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -29,29 +28,25 @@ import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import javax.naming.NameNotFoundException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-
+import org.apache.directory.ldap.client.api.LdapConnection;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
-import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
import org.apache.directory.shared.ldap.model.schema.MatchingRule;
import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.ldap.model.schema.comparators.BooleanComparator;
import org.apache.directory.shared.ldap.model.schema.comparators.StringComparator;
-import org.apache.directory.shared.ldap.util.JndiUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -71,7 +66,8 @@ public class MetaComparatorHandlerIT ext
private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
- public static SchemaManager schemaManager;
+ private static SchemaManager schemaManager;
+ private static LdapConnection connection;
class DummyMR extends MatchingRule
{
@@ -83,9 +79,12 @@ public class MetaComparatorHandlerIT ext
}
+
@Before
- public void setup()
+ public void init() throws Exception
{
+ super.init();
+ connection = IntegrationUtils.getAdminConnection( getService() );
schemaManager = getService().getSchemaManager();
}
@@ -98,19 +97,23 @@ public class MetaComparatorHandlerIT ext
@Test
public void testAddComparatorToEnabledSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
- "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
- "m-description: A test comparator" );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Entry entry = new DefaultEntry(
+ dn,
+ "objectClass: top",
+ "objectClass: metaTop",
+ "objectClass: metaComparator",
+ "m-fqcn", StringComparator.class.getName(),
+ "m-oid", OID,
+ "m-description: A test comparator" );
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
@@ -124,20 +127,23 @@ public class MetaComparatorHandlerIT ext
@Test
public void testAddComparatorToDisabledSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
- "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+ Entry entry = new DefaultEntry(
+ dn,
+ "objectClass: top",
+ "objectClass: metaTop",
+ "objectClass: metaComparator",
+ "m-fqcn", StringComparator.class.getName(),
+ "m-oid", OID,
"m-description: A test comparator" );
// nis is by default inactive
- Dn dn = getComparatorContainer( "nis" );
- dn = dn.add( "m-oid" + "=" + OID );
-
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
assertFalse( "adding new comparator to disabled schema should not register it into the registries",
@@ -149,25 +155,28 @@ public class MetaComparatorHandlerIT ext
@Test
public void testAddComparatorToUnloadedSchema() throws Exception
{
- Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
- "objectClass: metaComparator", "m-fqcn: " + StringComparator.class.getName(), "m-oid: " + OID,
- "m-description: A test comparator" );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=notloaded,ou=schema" );
- // nis is by default inactive
- Dn dn = getComparatorContainer( "notloaded" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Entry entry = new DefaultEntry(
+ dn,
+ "objectClass: top",
+ "objectClass: metaTop",
+ "objectClass: metaComparator",
+ "m-fqcn", StringComparator.class.getName(),
+ "m-oid", OID,
+ "m-description: A test comparator" );
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
// Addition
try
{
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
fail( "Should not be there" );
}
- catch ( NameNotFoundException nnfe )
+ catch ( LdapException nnfe )
{
// Expected result.
}
@@ -190,20 +199,24 @@ public class MetaComparatorHandlerIT ext
out.write( in.read() );
}
- Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
- "objectClass: metaComparator",
- "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator", "m-bytecode", out
- .toByteArray(), "m-oid", OID, "m-description: A test comparator" );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Entry entry = new DefaultEntry(
+ dn,
+ "objectClass: top",
+ "objectClass: metaTop",
+ "objectClass: metaComparator",
+ "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator",
+ "m-bytecode", out.toByteArray(),
+ "m-oid", OID,
+ "m-description: A test comparator" );
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
@@ -225,21 +238,25 @@ public class MetaComparatorHandlerIT ext
out.write( in.read() );
}
- Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop",
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+
+ Entry entry = new DefaultEntry(
+ dn,
+ "objectClass: top",
+ "objectClass: metaTop",
"objectClass: metaComparator",
- "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator", "m-bytecode", out
- .toByteArray(), "m-oid", OID, "m-description: A test comparator" );
+ "m-fqcn: org.apache.directory.shared.ldap.model.schema.comparators.DummyComparator",
+ "m-bytecode", out.toByteArray(),
+ "m-oid", OID,
+ "m-description: A test comparator" );
// nis is by default inactive
- Dn dn = getComparatorContainer( "nis" );
- dn = dn.add( "m-oid" + "=" + OID );
-
// Pre-checks
assertFalse( isOnDisk( dn ) );
- assertFalse( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertFalse( schemaManager.getComparatorRegistry().contains( OID ) );
// Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( dn ), attrs );
+ connection.add( entry );
// Post-checks
assertFalse( "adding new comparator to disabled schema should not register it into the registries",
@@ -255,8 +272,7 @@ public class MetaComparatorHandlerIT ext
@Test
public void testDeleteComparatorFromEnabledSchema() throws Exception
{
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
testAddComparatorToEnabledSchema();
@@ -265,7 +281,7 @@ public class MetaComparatorHandlerIT ext
assertTrue( isOnDisk( dn ) );
// Deletion
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+ connection.delete( dn );
// Post-checks
assertFalse( "comparator should be removed from the registry after being deleted", schemaManager
@@ -287,8 +303,8 @@ public class MetaComparatorHandlerIT ext
@Test
public void testDeleteComparatorFromDisabledSchema() throws Exception
{
- Dn dn = getComparatorContainer( "nis" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
+
testAddComparatorToDisabledSchema();
// Pre-checks
@@ -297,7 +313,7 @@ public class MetaComparatorHandlerIT ext
assertTrue( isOnDisk( dn ) );
// Deletion
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( dn ) );
+ connection.delete( dn );
// Post-checks
assertFalse( "comparator should be removed from the registry after being deleted", schemaManager
@@ -319,16 +335,17 @@ public class MetaComparatorHandlerIT ext
@Test
public void testDeleteComparatorWhenInUse() throws Exception
{
- Dn cDn = getComparatorContainer( "apachemeta" );
- cDn = cDn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
// Create a new Comparator
testAddComparatorToEnabledSchema();
- assertTrue( isOnDisk( cDn ) );
- assertTrue( getService().getSchemaManager().getComparatorRegistry().contains( OID ) );
+ assertTrue( isOnDisk( dn ) );
+ assertTrue( schemaManager.getComparatorRegistry().contains( OID ) );
// Create a MR using this comparator
- Attributes attrs = LdifUtils.createJndiAttributes(
+ Dn mrDn = new Dn( "m-oid=" + OID + ",ou=matchingRules,cn=apachemeta,ou=schema" );
+ Entry entry = new DefaultEntry(
+ mrDn,
"objectClass: top",
"objectClass: metaTop",
"objectClass: metaMatchingRule",
@@ -336,26 +353,23 @@ public class MetaComparatorHandlerIT ext
"m-syntax", SchemaConstants.INTEGER_SYNTAX,
"m-description: test" );
- Dn mrDn = getMatchingRuleContainer( "apachemeta" );
- mrDn = mrDn.add( "m-oid" + "=" + OID );
-
// Pre-checks
assertFalse( isOnDisk( mrDn ) );
- assertFalse( getService().getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+ assertFalse( schemaManager.getMatchingRuleRegistry().contains( OID ) );
// MatchingRule Addition
- getSchemaContext( getService() ).createSubcontext( JndiUtils.toName( mrDn ), attrs );
+ connection.add( entry );
// Post-checks
assertTrue( isOnDisk( mrDn ) );
- assertTrue( getService().getSchemaManager().getMatchingRuleRegistry().contains( OID ) );
+ assertTrue( schemaManager.getMatchingRuleRegistry().contains( OID ) );
try
{
- getSchemaContext( getService() ).destroySubcontext( JndiUtils.toName( cDn ) );
+ connection.delete( dn );
fail( "should not be able to delete a comparator in use" );
}
- catch ( OperationNotSupportedException e )
+ catch ( LdapException e )
{
}
@@ -373,13 +387,10 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- ModificationItem[] mods = new ModificationItem[1];
- Attribute attr = new BasicAttribute( "m-fqcn", BooleanComparator.class.getName() );
- mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
- getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName( dn ), mods );
+ connection.modify( dn, new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BooleanComparator.class.getName() ) );
assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
@@ -397,12 +408,10 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Attributes mods = new BasicAttributes( true );
- mods.put( "m-fqcn", BooleanComparator.class.getName() );
- getSchemaContext( getService() ).modifyAttributes( JndiUtils.toName(dn), DirContext.REPLACE_ATTRIBUTE, mods );
+ connection.modify( dn, new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "m-fqcn", BooleanComparator.class.getName() ) );
assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
@@ -421,13 +430,13 @@ public class MetaComparatorHandlerIT ext
@Ignore
public void testRenameComparator() throws Exception
{
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
+
testAddComparatorToEnabledSchema();
- Dn newdn = getComparatorContainer( "apachemeta" );
- newdn = newdn.add( "m-oid" + "=" + NEW_OID );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ Rdn rdn = new Rdn( "m-oid=" + NEW_OID );
+
+ connection.rename( dn, rdn );
assertFalse( "old comparator OID should be removed from the registry after being renamed", schemaManager
.getComparatorRegistry().contains( OID ) );
@@ -451,17 +460,16 @@ public class MetaComparatorHandlerIT ext
@Ignore
public void testRenameComparatorWhenInUse() throws Exception
{
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
+
testAddComparatorToEnabledSchema();
schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
- Dn newdn = getComparatorContainer( "apachemeta" );
- newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+ Rdn rdn = new Rdn( "m-oid" + "=" + NEW_OID );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.rename( dn, rdn );
fail( "should not be able to rename a comparator in use" );
}
catch ( LdapUnwillingToPerformException e )
@@ -472,7 +480,7 @@ public class MetaComparatorHandlerIT ext
assertTrue( "comparator should still be in the registry after rename failure", schemaManager
.getComparatorRegistry().contains( OID ) );
schemaManager.getMatchingRuleRegistry().unregister( OID );
- getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+ schemaManager.getGlobalOidRegistry().unregister( OID );
}
@@ -485,13 +493,11 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn newdn = getComparatorContainer( "apache" );
- newdn = newdn.add( "m-oid" + "=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apache,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
assertTrue( "comparator OID should still be present", schemaManager.getComparatorRegistry().contains( OID ) );
@@ -509,13 +515,11 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn newdn = getComparatorContainer( "apache" );
- newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+ Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=comparators,cn=apache,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.moveAndRename( dn, newDn );
assertFalse( "old comparator OID should NOT be present", schemaManager.getComparatorRegistry().contains( OID ) );
@@ -539,15 +543,13 @@ public class MetaComparatorHandlerIT ext
testAddComparatorToEnabledSchema();
schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn newdn = getComparatorContainer( "apache" );
- newdn = newdn.add( "m-oid" + "=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apache,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
fail( "should not be able to move a comparator in use" );
}
catch ( LdapUnwillingToPerformException e )
@@ -558,7 +560,7 @@ public class MetaComparatorHandlerIT ext
assertTrue( "comparator should still be in the registry after move failure", schemaManager
.getComparatorRegistry().contains( OID ) );
schemaManager.getMatchingRuleRegistry().unregister( OID );
- getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+ schemaManager.getGlobalOidRegistry().unregister( OID );
}
@@ -569,15 +571,13 @@ public class MetaComparatorHandlerIT ext
testAddComparatorToEnabledSchema();
schemaManager.getMatchingRuleRegistry().register( new DummyMR() );
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn newdn = getComparatorContainer( "apache" );
- newdn = newdn.add( "m-oid" + "=" + NEW_OID );
+ Dn newDn = new Dn( "m-oid=" + NEW_OID + ",ou=comparators,cn=apache,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.moveAndRename( dn, newDn );
fail( "should not be able to move a comparator in use" );
}
catch ( LdapUnwillingToPerformException e )
@@ -588,7 +588,7 @@ public class MetaComparatorHandlerIT ext
assertTrue( "comparator should still be in the registry after move failure", schemaManager
.getComparatorRegistry().contains( OID ) );
schemaManager.getMatchingRuleRegistry().unregister( OID );
- getService().getSchemaManager().getGlobalOidRegistry().unregister( OID );
+ schemaManager.getGlobalOidRegistry().unregister( OID );
}
@@ -602,15 +602,14 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
Dn top = new Dn();
top = top.add( "m-oid" + "=" + OID );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( top ) );
+ connection.move( dn, top );
fail( "should not be able to move a comparator up to ou=schema" );
}
catch ( LdapInvalidDnException e )
@@ -629,15 +628,13 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- Dn newdn = new Dn( "ou=normalizers,cn=apachemeta" );
- newdn = newdn.add( "m-oid" + "=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + "ou=normalizers,cn=apachemeta,ou=schema" );
try
{
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
fail( "should not be able to move a comparator up to normalizers container" );
}
catch ( LdapInvalidDnException e )
@@ -656,14 +653,12 @@ public class MetaComparatorHandlerIT ext
{
testAddComparatorToEnabledSchema();
- Dn dn = getComparatorContainer( "apachemeta" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
// nis is inactive by default
- Dn newdn = getComparatorContainer( "nis" );
- newdn = newdn.add( "m-oid" + "=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn);
assertFalse( "comparator OID should no longer be present", schemaManager.getComparatorRegistry().contains( OID ) );
}
@@ -676,16 +671,14 @@ public class MetaComparatorHandlerIT ext
testAddComparatorToDisabledSchema();
// nis is inactive by default
- Dn dn = getComparatorContainer( "nis" );
- dn = dn.add( "m-oid" + "=" + OID );
+ Dn dn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=nis,ou=schema" );
assertFalse( "comparator OID should NOT be present when added to disabled nis schema", schemaManager
.getComparatorRegistry().contains( OID ) );
- Dn newdn = getComparatorContainer( "apachemeta" );
- newdn = newdn.add( "m-oid" + "=" + OID );
+ Dn newDn = new Dn( "m-oid=" + OID + ",ou=comparators,cn=apachemeta,ou=schema" );
- getSchemaContext( getService() ).rename( JndiUtils.toName( dn ), JndiUtils.toName( newdn ) );
+ connection.move( dn, newDn );
assertTrue( "comparator OID should be present when moved to enabled schema", schemaManager
.getComparatorRegistry().contains( OID ) );