directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r601657 [1/6] - in /directory/apacheds/branches/bigbang: core-integ/src/main/java/org/apache/directory/server/core/integ/ core-integ/src/test/java/org/apache/directory/server/core/jndi/ core-integ/src/test/java/org/apache/directory/server/c...
Date Thu, 06 Dec 2007 08:39:27 GMT
Author: akarasulu
Date: Thu Dec  6 00:39:23 2007
New Revision: 601657

URL: http://svn.apache.org/viewvc?rev=601657&view=rev
Log:
moved all schema tests but found serveral issues and bugs which were fixed - tests are a bit broken though

Added:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/
      - copied from r601149, directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/schema/
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaISuite.java
      - copied, changed from r601149, directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/StockCoreISuite.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryIT.java   (with props)
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/schema/
      - copied from r601149, directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/schema/DummyComparator.bytecode
      - copied unchanged from r601650, directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/DummyComparator.bytecode
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/schema/DummyNormalizer.bytecode
      - copied unchanged from r601650, directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/DummyNormalizer.bytecode
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/schema/DummySyntaxChecker.bytecode
      - copied unchanged from r601650, directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/DummySyntaxChecker.bytecode
    directory/apacheds/branches/bigbang/core-integ/src/test/resources/org/apache/directory/server/core/schema/nonspecific.ldif
      - copied unchanged from r601650, directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/nonspecific.ldif
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaOperationControl.java   (contents, props changed)
      - copied, changed from r601149, directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
Removed:
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/IllegalModifyAddITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaNormalizerHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaObjectClassHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSchemaHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxCheckerHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/ObjectClassCreateITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaPersistenceITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SchemaServiceITest.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java
    directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/schema/
    directory/apacheds/branches/bigbang/core-unit/src/test/resources/org/apache/directory/server/core/schema/
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaManager.java
Modified:
    directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
    directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java
    directory/apacheds/branches/bigbang/core-unit/src/test/java/org/apache/directory/server/core/changelog/DefaultChangeLogITest.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/changelog/ChangeLogInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/PartitionSchemaLoader.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
    directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java
    directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=601657&r1=601656&r2=601657&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Thu Dec  6 00:39:23 2007
@@ -107,6 +107,12 @@
     }
 
 
+    public static LdapContext getSchemaContext( DirectoryService service ) throws NamingException
+    {
+        return getContext( "uid=admin,ou=system", service, "ou=schema" );
+    }
+
+
     public static LdapContext getRootContext( DirectoryService service ) throws NamingException
     {
         return getContext( "uid=admin,ou=system", service, "" );

Modified: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java?rev=601657&r1=601656&r2=601657&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/jndi/ModifyContextIT.java Thu Dec  6 00:39:23 2007
@@ -22,7 +22,11 @@
 
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.integ.CiRunner;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getRootContext;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.ldif.Entry;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import static org.junit.Assert.*;
@@ -56,6 +60,8 @@
      */
     protected void createData() throws NamingException
     {
+        Entry akarasulu = getUserAddLdif();
+        getRootContext( service ).createSubcontext( akarasulu.getDn(), akarasulu.getAttributes() );
         LdapContext sysRoot = getSystemContext( service );
 
         /*
@@ -152,6 +158,39 @@
         assertTrue( attribute.contains( "top" ) );
         assertTrue( attribute.contains( "organizationalUnit" ) );
     }
+
+
+    /**
+     * Add a new attribute without any value to a person entry: testcase for
+     * http://issues.apache.org/jira/browse/DIRSERVER-630.
+     * 
+     * @throws NamingException on error
+     */
+    public void testIllegalModifyAdd() throws NamingException
+    {
+        createData();
+
+        LdapContext sysRoot = getSystemContext( service );
+
+        Attribute attr = new AttributeImpl( "description" );
+        Attributes attrs = new AttributesImpl();
+        attrs.put( attr );
+
+        try
+        {
+            sysRoot.modifyAttributes( "uid=akarasulu,ou=users", DirContext.ADD_ATTRIBUTE, attrs );
+            fail( "error expected due to empty attribute value" );
+        }
+        catch ( LdapInvalidAttributeValueException e )
+        {
+            // expected
+        }
+
+        // Check whether entry is unmodified, i.e. no description
+        Attributes entry = sysRoot.getAttributes( "uid=akarasulu,ou=users" );
+        assertNull( entry.get( "description" ) );
+    }
+
 
 
     @Test

Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java?rev=601657&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java Thu Dec  6 00:39:23 2007
@@ -0,0 +1,534 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.schema;
+
+
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.SetupMode;
+import org.apache.directory.server.core.integ.annotations.Mode;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
+import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
+
+/**
+ * A test case which tests the addition of various schema elements
+ * to the ldap server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+@RunWith ( CiRunner.class )
+@Mode ( SetupMode.PRISTINE )
+public class MetaAttributeTypeHandlerIT
+{
+    private static final String DESCRIPTION0 = "A test attributeType";
+    private static final String DESCRIPTION1 = "An alternate description";
+
+    private static final String INTEGER_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.27";
+    private static final String DIRSTR_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.15";
+    
+    private static final String OID = "1.3.6.1.4.1.18060.0.4.0.2.100000";
+    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";
+
+
+    public static DirectoryService service;
+
+    
+    /**
+     * 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 NamingException on failure
+     */
+    private LdapDN getAttributeTypeContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=attributeTypes,cn=" + schemaName );
+    }
+
+
+    private static AttributeTypeRegistry getAttributeTypeRegistry()
+    {
+        return service.getRegistries().getAttributeTypeRegistry();
+    }
+    
+    
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+    
+    @Test
+    public void testAddAttributeType() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        attrs.put( MetaSchemaConstants.M_EQUALITY_AT, "caseIgnoreMatch" );
+        attrs.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, "FALSE" );
+        attrs.put( MetaSchemaConstants.M_USAGE_AT, "directoryOperation" );
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( service.getRegistries().getAttributeTypeRegistry().hasAttributeType( OID ) );
+        assertEquals( getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+    
+    
+    @Test
+    public void testDeleteAttributeType() throws NamingException
+    {
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        
+        getSchemaContext( service ).destroySubcontext( dn );
+
+        assertFalse( "attributeType should be removed from the registry after being deleted", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        try
+        {
+            getAttributeTypeRegistry().lookup( OID );
+            fail( "attributeType lookup should fail after deleting it" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    @Test
+    public void testRenameAttributeType() throws NamingException
+    {
+        LdapContext schemaRoot = getSchemaContext( service );
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        
+        LdapDN newdn = getAttributeTypeContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        schemaRoot.rename( dn, newdn );
+
+        assertFalse( "old attributeType OID should be removed from the registry after being renamed", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        try
+        {
+            getAttributeTypeRegistry().lookup( OID );
+            fail( "attributeType lookup should fail after renaming the attributeType" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( getAttributeTypeRegistry().hasAttributeType( NEW_OID ) );
+    }
+
+
+    @Test
+    public void testMoveAttributeType() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "attributeType OID should still be present",
+                getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apache not apachemeta", 
+            getAttributeTypeRegistry().getSchemaName( OID ), "apache" );
+    }
+
+
+    @Test
+    public void testMoveAttributeTypeAndChangeRdn() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old attributeType OID should NOT be present", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertTrue( "new attributeType OID should be present", 
+            getAttributeTypeRegistry().hasAttributeType( NEW_OID ) );
+        
+        assertEquals( "attributeType with new oid should have schema set to apache NOT apachemeta", 
+            getAttributeTypeRegistry().getSchemaName( NEW_OID ), "apache" );
+    }
+
+    
+    @Test
+    public void testModifyAttributeTypeWithModificationItems() throws NamingException
+    {
+        testAddAttributeType();
+        
+        AttributeType at = getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION0 );
+        assertEquals( at.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItemImpl[] mods = new ModificationItemImpl[2];
+        Attribute attr = new AttributeImpl( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        attr = new AttributeImpl( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        mods[1] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        getSchemaContext( service ).modifyAttributes( dn, mods );
+
+        assertTrue( "attributeType OID should still be present", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apachemeta", 
+            getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+        
+        at = getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION1 );
+        assertEquals( at.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+
+    
+    @Test
+    public void testModifyAttributeTypeWithAttributes() throws NamingException
+    {
+        testAddAttributeType();
+        
+        AttributeType at = getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION0 );
+        assertEquals( at.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        mods.put( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "attributeType OID should still be present", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType schema should be set to apachemeta", 
+            getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+
+        at = getAttributeTypeRegistry().lookup( OID );
+        assertEquals( at.getDescription(), DESCRIPTION1 );
+        assertEquals( at.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Normalizer
+    // ----------------------------------------------------------------------
+
+    
+    private void addDependeeAttributeType() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, DEPENDEE_OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        attrs.put( MetaSchemaConstants.M_EQUALITY_AT, "caseIgnoreMatch" );
+        attrs.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, "FALSE" );
+        attrs.put( MetaSchemaConstants.M_USAGE_AT, "directoryOperation" );
+        attrs.put( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT, OID );
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + DEPENDEE_OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( getAttributeTypeRegistry().hasAttributeType( DEPENDEE_OID ) );
+        assertEquals( getAttributeTypeRegistry().getSchemaName( DEPENDEE_OID ), "apachemeta" );
+    }
+
+
+    @Test
+    public void testDeleteAttributeTypeWhenInUse() throws NamingException
+    {
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        addDependeeAttributeType();
+        
+        try
+        {
+            getSchemaContext( service ).destroySubcontext( dn );
+            fail( "should not be able to delete a attributeType in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "attributeType should still be in the registry after delete failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+    
+    
+    @Test
+    public void testMoveAttributeTypeWhenInUse() throws NamingException
+    {
+        testAddAttributeType();
+        addDependeeAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a attributeType in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    @Test
+    public void testMoveAttributeTypeAndChangeRdnWhenInUse() throws NamingException
+    {
+        testAddAttributeType();
+        addDependeeAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getAttributeTypeContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a attributeType in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+    
+    @Test
+    public void testRenameAttributeTypeWhenInUse() throws NamingException
+    {
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddAttributeType();
+        addDependeeAttributeType();
+        
+        LdapDN newdn = getAttributeTypeContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to rename a attributeType in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "attributeType should still be in the registry after rename failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    @Test
+    public void testMoveAttributeTypeToTop() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN top = new LdapDN();
+        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, top );
+            fail( "should not be able to move a attributeType up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    @Test
+    public void testMoveAttributeTypeToComparatorContainer() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = new LdapDN( "ou=comparators,cn=apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a attributeType into comparators container" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "attributeType should still be in the registry after move failure", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+    
+    
+    @Test
+    public void testAddAttributeTypeToDisabledSchema() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        attrs.put( MetaSchemaConstants.M_EQUALITY_AT, "caseIgnoreMatch" );
+        attrs.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, "FALSE" );
+        attrs.put( MetaSchemaConstants.M_USAGE_AT, "directoryOperation" );
+        
+        LdapDN dn = getAttributeTypeContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new attributeType to disabled schema should not register it into the registries", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    @Test
+    public void testMoveAttributeTypeToDisabledSchema() throws NamingException
+    {
+        testAddAttributeType();
+        
+        LdapDN dn = getAttributeTypeContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getAttributeTypeContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "attributeType OID should no longer be present", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+    }
+
+
+    @Test
+    public void testMoveMatchingRuleToEnabledSchema() throws NamingException
+    {
+        testAddAttributeTypeToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getAttributeTypeContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "attributeType OID should NOT be present when added to disabled nis schema", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+
+        LdapDN newdn = getAttributeTypeContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "attributeType OID should be present when moved to enabled schema", 
+            getAttributeTypeRegistry().hasAttributeType( OID ) );
+        
+        assertEquals( "attributeType should be in apachemeta schema after move", 
+            getAttributeTypeRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+}

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaAttributeTypeHandlerIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java?rev=601657&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java Thu Dec  6 00:39:23 2007
@@ -0,0 +1,597 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.schema;
+
+
+import jdbm.helper.IntegerComparator;
+import jdbm.helper.StringComparator;
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.SetupMode;
+import org.apache.directory.server.core.integ.annotations.Mode;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
+import org.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.schema.Syntax;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Comparator;
+
+
+/**
+ * A test case which tests the addition of various schema elements
+ * to the ldap server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+@RunWith ( CiRunner.class )
+@Mode ( SetupMode.PRISTINE )
+public class MetaComparatorHandlerIT
+{
+    private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
+    private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
+
+
+    public static DirectoryService service;
+
+    
+    /**
+     * Gets relative DN to ou=schema.
+     *
+     * @param schemaName the name of the schema
+     * @return the dn to the ou underwhich comparators are found for a schmea
+     * @throws NamingException if there are dn construction issues
+     */
+    private LdapDN getComparatorContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=comparators,cn=" + schemaName );
+    }
+
+
+    private static ComparatorRegistry getComparatorRegistry()
+    {
+        return service.getRegistries().getComparatorRegistry();
+    }
+    
+
+    private static MatchingRuleRegistry getMatchingRuleRegistry()
+    {
+        return service.getRegistries().getMatchingRuleRegistry();
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+
+    @Test
+    public void testAddComparator() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, StringComparator.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( getComparatorRegistry().hasComparator( OID ) );
+        assertEquals( getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+        Class clazz = getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+    
+
+    @Test
+    public void testAddComparatorWithByteCode() throws Exception
+    {
+        InputStream in = getClass().getResourceAsStream( "DummyComparator.bytecode" );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        while ( in.available() > 0 )
+        {
+            out.write( in.read() );
+        }
+        
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, "DummyComparator" );
+        attrs.put( MetaSchemaConstants.M_BYTECODE_AT, out.toByteArray() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( getComparatorRegistry().hasComparator( OID ) );
+        assertEquals( getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+        Class clazz = getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz.getName(), "DummyComparator" );
+    }
+    
+
+    @Test
+    public void testDeleteComparator() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        
+        getSchemaContext( service ).destroySubcontext( dn );
+
+        assertFalse( "comparator should be removed from the registry after being deleted", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        try
+        {
+            getComparatorRegistry().lookup( OID );
+            fail( "comparator lookup should fail after deleting the comparator" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    @Test
+    public void testRenameComparator() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old comparator OID should be removed from the registry after being renamed", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        try
+        {
+            getComparatorRegistry().lookup( OID );
+            fail( "comparator lookup should fail after deleting the comparator" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( getComparatorRegistry().hasComparator( NEW_OID ) );
+        Class clazz = getComparatorRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+
+    @Test
+    public void testMoveComparator() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "comparator OID should still be present", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apache not apachemeta", 
+            getComparatorRegistry().getSchemaName( OID ), "apache" );
+
+        Class clazz = getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+
+    @Test
+    public void testMoveComparatorAndChangeRdn() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old comparator OID should NOT be present", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        assertTrue( "new comparator OID should be present", 
+            getComparatorRegistry().hasComparator( NEW_OID ) );
+        
+        assertEquals( "comparator with new oid should have schema set to apache NOT apachemeta", 
+            getComparatorRegistry().getSchemaName( NEW_OID ), "apache" );
+
+        Class clazz = getComparatorRegistry().lookup( NEW_OID ).getClass();
+        assertEquals( clazz, StringComparator.class );
+    }
+
+
+    @Test
+    public void testModifyComparatorWithModificationItems() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItemImpl[] mods = new ModificationItemImpl[1];
+        Attribute attr = new AttributeImpl( MetaSchemaConstants.M_FQCN_AT, IntegerComparator.class.getName() );
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        getSchemaContext( service ).modifyAttributes( dn, mods );
+
+        assertTrue( "comparator OID should still be present", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apachemeta", 
+            getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, IntegerComparator.class );
+    }
+
+
+    @Test
+    public void testModifyComparatorWithAttributes() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( MetaSchemaConstants.M_FQCN_AT, IntegerComparator.class.getName() );
+        getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "comparator OID should still be present", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator schema should be set to apachemeta", 
+            getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+
+        Class clazz = getComparatorRegistry().lookup( OID ).getClass();
+        assertEquals( clazz, IntegerComparator.class );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Comparator
+    // ----------------------------------------------------------------------
+
+    
+    @Test
+    public void testDeleteComparatorWhenInUse() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        getMatchingRuleRegistry().register( new DummyMR() );
+        
+        try
+        {
+            getSchemaContext( service ).destroySubcontext( dn );
+            fail( "should not be able to delete a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after delete failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+        getMatchingRuleRegistry().unregister( OID );
+    }
+    
+    
+    @Test
+    public void testMoveComparatorWhenInUse() throws NamingException
+    {
+        testAddComparator();
+        getMatchingRuleRegistry().register( new DummyMR() );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+        getMatchingRuleRegistry().unregister( OID );
+    }
+
+
+    @Test
+    public void testMoveComparatorAndChangeRdnWhenInUse() throws NamingException
+    {
+        testAddComparator();
+        getMatchingRuleRegistry().register( new DummyMR() );
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getComparatorContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+        getMatchingRuleRegistry().unregister( OID );
+    }
+
+    
+    @Test
+    public void testRenameComparatorWhenInUse() throws NamingException
+    {
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddComparator();
+        getMatchingRuleRegistry().register( new DummyMR() );
+        
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to rename a comparator in use" );
+        }
+        catch( LdapOperationNotSupportedException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
+        assertTrue( "comparator should still be in the registry after rename failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+        getMatchingRuleRegistry().unregister( OID );
+    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    @Test
+    public void testMoveComparatorToTop() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN top = new LdapDN();
+        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, top );
+            fail( "should not be able to move a comparator up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    @Test
+    public void testMoveComparatorToNormalizers() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = new LdapDN( "ou=normalizers,cn=apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a comparator up to normalizers container" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "comparator should still be in the registry after move failure", 
+            getComparatorRegistry().hasComparator( OID ) );
+    }
+    
+    
+    @Test
+    public void testAddComparatorToDisabledSchema() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_COMPARATOR_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_FQCN_AT, StringComparator.class.getName() );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, "A test comparator" );
+        
+        // nis is by default inactive
+        LdapDN dn = getComparatorContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new comparator to disabled schema should not register it into the registries", 
+            getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    @Test
+    public void testMoveComparatorToDisabledSchema() throws NamingException
+    {
+        testAddComparator();
+        
+        LdapDN dn = getComparatorContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getComparatorContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "comparator OID should no longer be present", 
+            getComparatorRegistry().hasComparator( OID ) );
+    }
+
+
+    @Test
+    public void testMoveComparatorToEnabledSchema() throws NamingException
+    {
+        testAddComparatorToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getComparatorContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "comparator OID should NOT be present when added to disabled nis schema", 
+            getComparatorRegistry().hasComparator( OID ) );
+
+        LdapDN newdn = getComparatorContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "comparator OID should be present when moved to enabled schema", 
+            getComparatorRegistry().hasComparator( OID ) );
+        
+        assertEquals( "comparator should be in apachemeta schema after move", 
+            getComparatorRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+
+
+    class DummyMR implements MatchingRule
+    {
+        private static final long serialVersionUID = 1L;
+
+        public Comparator getComparator() throws NamingException
+        {
+            return null;
+        }
+
+        public Normalizer getNormalizer() throws NamingException
+        {
+            return null;
+        }
+
+        public Syntax getSyntax() throws NamingException
+        {
+            return null;
+        }
+
+        public String getDescription()
+        {
+            return null;
+        }
+
+        public String getName()
+        {
+            return "dummy";
+        }
+
+        public String[] getNames()
+        {
+            return new String[] { "dummy" };
+        }
+
+        public String getOid()
+        {
+            return OID;
+        }
+
+        public boolean isObsolete()
+        {
+            return false;
+        }
+
+        public String getSchema()
+        {
+            return null;
+        }
+
+        public void setSchema( String schemaName )
+        {
+        }
+    }
+}

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaComparatorHandlerIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java?rev=601657&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java Thu Dec  6 00:39:23 2007
@@ -0,0 +1,505 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.schema;
+
+
+import org.apache.directory.server.constants.MetaSchemaConstants;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.SetupMode;
+import org.apache.directory.server.core.integ.annotations.Mode;
+import static org.apache.directory.server.core.integ.IntegrationUtils.getSchemaContext;
+import org.apache.directory.server.schema.registries.MatchingRuleRegistry;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapInvalidNameException;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+
+/**
+ * A test case which tests the addition of various schema elements
+ * to the ldap server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+@RunWith ( CiRunner.class )
+@Mode ( SetupMode.PRISTINE )
+public class MetaMatchingRuleHandlerIT
+{
+    private static final String DESCRIPTION0 = "A test matchingRule";
+    private static final String DESCRIPTION1 = "An alternate description";
+
+    private static final String INTEGER_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.27";
+    private static final String DIRSTR_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.15";
+    
+    private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.100000";
+    private static final String NEW_OID = "1.3.6.1.4.1.18060.0.4.0.1.100001";
+
+
+    public static DirectoryService service;
+
+
+    private static MatchingRuleRegistry getMatchingRuleRegistry()
+    {
+        return service.getRegistries().getMatchingRuleRegistry();
+    }
+    
+    
+    /**
+     * Gets relative DN to ou=schema.
+     * 
+     * @param schemaName the name of the schema
+     * @return  the dn of the container of matchingRules for a schema
+     * @throws NamingException on error
+     */
+    private LdapDN getMatchingRuleContainer( String schemaName ) throws NamingException
+    {
+        return new LdapDN( "ou=matchingRules,cn=" + schemaName );
+    }
+    
+    
+    // ----------------------------------------------------------------------
+    // Test all core methods with normal operational pathways
+    // ----------------------------------------------------------------------
+
+
+    @Test
+    public void testAddMatchingRule() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_MATCHING_RULE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertTrue( getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        assertEquals( getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+    
+
+    @Test
+    public void testDeleteMatchingRule() throws NamingException
+    {
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddMatchingRule();
+        
+        getSchemaContext( service ).destroySubcontext( dn );
+
+        assertFalse( "matchingRule should be removed from the registry after being deleted", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        try
+        {
+            getMatchingRuleRegistry().lookup( OID );
+            fail( "matchingRule lookup should fail after deleting it" );
+        }
+        catch( NamingException e )
+        {
+        }
+    }
+
+
+    @Test
+    public void testRenameMatchingRule() throws NamingException
+    {
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        testAddMatchingRule();
+        
+        LdapDN newdn = getMatchingRuleContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old matchingRule OID should be removed from the registry after being renamed", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        try
+        {
+            getMatchingRuleRegistry().lookup( OID );
+            fail( "matchingRule lookup should fail after renaming the matchingRule" );
+        }
+        catch( NamingException e )
+        {
+        }
+
+        assertTrue( getMatchingRuleRegistry().hasMatchingRule( NEW_OID ) );
+    }
+
+
+    @Test
+    public void testMoveMatchingRule() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getMatchingRuleContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "matchingRule OID should still be present", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        assertEquals( "matchingRule schema should be set to apache not apachemeta", 
+            getMatchingRuleRegistry().getSchemaName( OID ), "apache" );
+    }
+
+
+    @Test
+    public void testMoveMatchingRuleAndChangeRdn() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = getMatchingRuleContainer( "apache" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "old matchingRule OID should NOT be present", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        assertTrue( "new matchingRule OID should be present", 
+            getMatchingRuleRegistry().hasMatchingRule( NEW_OID ) );
+        
+        assertEquals( "matchingRule with new oid should have schema set to apache NOT apachemeta", 
+            getMatchingRuleRegistry().getSchemaName( NEW_OID ), "apache" );
+    }
+
+
+    @Test
+    public void testModifyMatchingRuleWithModificationItems() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        MatchingRule mr = getMatchingRuleRegistry().lookup( OID );
+        assertEquals( mr.getDescription(), DESCRIPTION0 );
+        assertEquals( mr.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        ModificationItemImpl[] mods = new ModificationItemImpl[2];
+        Attribute attr = new AttributeImpl( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        mods[0] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        attr = new AttributeImpl( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        mods[1] = new ModificationItemImpl( DirContext.REPLACE_ATTRIBUTE, attr );
+        getSchemaContext( service ).modifyAttributes( dn, mods );
+
+        assertTrue( "matchingRule OID should still be present", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        assertEquals( "matchingRule schema should be set to apachemeta", 
+            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+        
+        mr = getMatchingRuleRegistry().lookup( OID );
+        assertEquals( mr.getDescription(), DESCRIPTION1 );
+        assertEquals( mr.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+
+    
+    @Test
+    public void testModifyMatchingRuleWithAttributes() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        MatchingRule mr = getMatchingRuleRegistry().lookup( OID );
+        assertEquals( mr.getDescription(), DESCRIPTION0 );
+        assertEquals( mr.getSyntax().getOid(), INTEGER_SYNTAX_OID );
+
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        Attributes mods = new AttributesImpl();
+        mods.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION1 );
+        mods.put( MetaSchemaConstants.M_SYNTAX_AT, DIRSTR_SYNTAX_OID );
+        getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );
+
+        assertTrue( "matchingRule OID should still be present", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        assertEquals( "matchingRule schema should be set to apachemeta", 
+            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+
+        mr = getMatchingRuleRegistry().lookup( OID );
+        assertEquals( mr.getDescription(), DESCRIPTION1 );
+        assertEquals( mr.getSyntax().getOid(), DIRSTR_SYNTAX_OID );
+    }
+    
+
+    // ----------------------------------------------------------------------
+    // Test move, rename, and delete when a MR exists and uses the Normalizer
+    // ----------------------------------------------------------------------
+
+    
+//    public void testDeleteSyntaxWhenInUse() throws NamingException
+//    {
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        try
+//        {
+//            super.schemaRoot.destroySubcontext( dn );
+//            fail( "should not be able to delete a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after delete failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//    
+//    
+//    public void testMoveSyntaxWhenInUse() throws NamingException
+//    {
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//
+//        LdapDN newdn = getSyntaxContainer( "apache" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to move a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after move failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//
+//
+//    public void testMoveSyntaxAndChangeRdnWhenInUse() throws NamingException
+//    {
+//        testAddSyntax();
+//        addDependeeMatchingRule()
+//        
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//
+//        LdapDN newdn = getSyntaxContainer( "apache" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to move a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after move failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+//
+//    
+
+    // Need to add body to this method which creates a new matchingRule after 
+    // the matchingRule addition code has been added.
+    
+//    private void addDependeeMatchingRule()
+//    {
+//        throw new NotImplementedException();
+//    }
+//    
+//    public void testRenameNormalizerWhenInUse() throws NamingException
+//    {
+//        LdapDN dn = getSyntaxContainer( "apachemeta" );
+//        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+//        testAddSyntax();
+//        addDependeeMatchingRule();
+//        
+//        LdapDN newdn = getSyntaxContainer( "apachemeta" );
+//        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + NEW_OID );
+//        
+//        try
+//        {
+//            super.schemaRoot.rename( dn, newdn );
+//            fail( "should not be able to rename a syntax in use" );
+//        }
+//        catch( LdapOperationNotSupportedException e ) 
+//        {
+//            assertEquals( e.getResultCode(), ResultCodeEnum.UNWILLING_TO_PERFORM );
+//        }
+//
+//        assertTrue( "syntax should still be in the registry after rename failure", 
+//            registries.getSyntaxRegistry().hasSyntax( OID ) );
+//    }
+
+
+    // ----------------------------------------------------------------------
+    // Let's try some freaky stuff
+    // ----------------------------------------------------------------------
+
+
+    @Test
+    public void testMoveMatchingRuleToTop() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN top = new LdapDN();
+        top.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, top );
+            fail( "should not be able to move a matchingRule up to ou=schema" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "matchingRule should still be in the registry after move failure", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+    }
+
+
+    @Test
+    public void testMoveMatchingRuleToComparatorContainer() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        LdapDN newdn = new LdapDN( "ou=comparators,cn=apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        try
+        {
+            getSchemaContext( service ).rename( dn, newdn );
+            fail( "should not be able to move a matchingRule into comparators container" );
+        }
+        catch( LdapInvalidNameException e ) 
+        {
+            assertEquals( e.getResultCode(), ResultCodeEnum.NAMING_VIOLATION );
+        }
+
+        assertTrue( "matchingRule should still be in the registry after move failure", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+    }
+    
+    
+    @Test
+    public void testAddMatchingRuleToDisabledSchema() throws NamingException
+    {
+        Attributes attrs = new AttributesImpl();
+        Attribute oc = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT, "top" );
+        oc.add( MetaSchemaConstants.META_TOP_OC );
+        oc.add( MetaSchemaConstants.META_MATCHING_RULE_OC );
+        attrs.put( oc );
+        attrs.put( MetaSchemaConstants.M_OID_AT, OID );
+        attrs.put( MetaSchemaConstants.M_SYNTAX_AT, INTEGER_SYNTAX_OID );
+        attrs.put( MetaSchemaConstants.M_DESCRIPTION_AT, DESCRIPTION0 );
+        
+        LdapDN dn = getMatchingRuleContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        getSchemaContext( service ).createSubcontext( dn, attrs );
+        
+        assertFalse( "adding new matchingRule to disabled schema should not register it into the registries", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+    }
+
+
+    @Test
+    public void testMoveMatchingRuleToDisabledSchema() throws NamingException
+    {
+        testAddMatchingRule();
+        
+        LdapDN dn = getMatchingRuleContainer( "apachemeta" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        // nis is inactive by default
+        LdapDN newdn = getMatchingRuleContainer( "nis" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertFalse( "matchingRule OID should no longer be present", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+    }
+
+
+    @Test
+    public void testMoveMatchingRuleToEnabledSchema() throws NamingException
+    {
+        testAddMatchingRuleToDisabledSchema();
+        
+        // nis is inactive by default
+        LdapDN dn = getMatchingRuleContainer( "nis" );
+        dn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+
+        assertFalse( "matchingRule OID should NOT be present when added to disabled nis schema", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+
+        LdapDN newdn = getMatchingRuleContainer( "apachemeta" );
+        newdn.add( MetaSchemaConstants.M_OID_AT + "=" + OID );
+        
+        getSchemaContext( service ).rename( dn, newdn );
+
+        assertTrue( "matchingRule OID should be present when moved to enabled schema", 
+            getMatchingRuleRegistry().hasMatchingRule( OID ) );
+        
+        assertEquals( "matchingRule should be in apachemeta schema after move", 
+            getMatchingRuleRegistry().getSchemaName( OID ), "apachemeta" );
+    }
+}

Propchange: directory/apacheds/branches/bigbang/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaMatchingRuleHandlerIT.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message