From commits-return-12439-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Mon Feb 12 00:30:24 2007 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 51162 invoked from network); 12 Feb 2007 00:30:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Feb 2007 00:30:23 -0000 Received: (qmail 87606 invoked by uid 500); 12 Feb 2007 00:30:31 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 87556 invoked by uid 500); 12 Feb 2007 00:30:30 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 87545 invoked by uid 99); 12 Feb 2007 00:30:30 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Feb 2007 16:30:30 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Feb 2007 16:30:22 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 7A6561A9820; Sun, 11 Feb 2007 16:30:02 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r506193 - /directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java Date: Mon, 12 Feb 2007 00:30:02 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070212003002.7A6561A9820@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Sun Feb 11 16:30:01 2007 New Revision: 506193 URL: http://svn.apache.org/viewvc?view=rev&rev=506193 Log: added more test cases for matchingRules Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java Modified: directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java?view=diff&rev=506193&r1=506192&r2=506193 ============================================================================== --- directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java (original) +++ directory/apacheds/trunk/core-unit/src/test/java/org/apache/directory/server/core/schema/SubschemaSubentryITest.java Sun Feb 11 16:30:01 2007 @@ -50,12 +50,14 @@ import org.apache.directory.shared.ldap.schema.syntax.AttributeTypeDescription; import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription; import org.apache.directory.shared.ldap.schema.syntax.LdapSyntaxDescription; +import org.apache.directory.shared.ldap.schema.syntax.MatchingRuleDescription; import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription; import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker; import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription; import org.apache.directory.shared.ldap.schema.syntax.parser.AttributeTypeDescriptionSchemaParser; import org.apache.directory.shared.ldap.schema.syntax.parser.ComparatorDescriptionSchemaParser; import org.apache.directory.shared.ldap.schema.syntax.parser.LdapSyntaxDescriptionSchemaParser; +import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleDescriptionSchemaParser; import org.apache.directory.shared.ldap.schema.syntax.parser.NormalizerDescriptionSchemaParser; import org.apache.directory.shared.ldap.schema.syntax.parser.SyntaxCheckerDescriptionSchemaParser; import org.apache.directory.shared.ldap.util.Base64; @@ -83,6 +85,8 @@ new NormalizerDescriptionSchemaParser(); private LdapSyntaxDescriptionSchemaParser ldapSyntaxDescriptionSchemaParser = new LdapSyntaxDescriptionSchemaParser(); + private MatchingRuleDescriptionSchemaParser matchingRuleDescriptionSchemaParser = + new MatchingRuleDescriptionSchemaParser(); /** @@ -828,11 +832,210 @@ } - // ----------------------------------------------------------------------- // MatchingRule Tests // ----------------------------------------------------------------------- + + private void checkMatchingRulePresent( String oid, String schemaName, boolean isPresent ) throws Exception + { + // ------------------------------------------------------------------- + // check first to see if it is present in the subschemaSubentry + // ------------------------------------------------------------------- + + Attributes attrs = getSubschemaSubentryAttributes(); + Attribute attrTypes = attrs.get( "matchingRules" ); + MatchingRuleDescription matchingRuleDescription = null; + for ( int ii = 0; ii < attrTypes.size(); ii++ ) + { + String desc = ( String ) attrTypes.get( ii ); + if ( desc.indexOf( oid ) != -1 ) + { + matchingRuleDescription = matchingRuleDescriptionSchemaParser.parseMatchingRuleDescription( desc ); + break; + } + } + + if ( isPresent ) + { + assertNotNull( matchingRuleDescription ); + assertEquals( oid, matchingRuleDescription.getNumericOid() ); + } + else + { + assertNull( matchingRuleDescription ); + } + + // ------------------------------------------------------------------- + // check next to see if it is present in the schema partition + // ------------------------------------------------------------------- + + attrs = null; + + if ( isPresent ) + { + attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=matchingRules,cn=" + schemaName ); + assertNotNull( attrs ); + } + else + { + try + { + attrs = schemaRoot.getAttributes( "m-oid=" + oid + ",ou=matchingRules,cn=" + schemaName ); + fail( "should never get here" ); + } + catch( NamingException e ) + { + } + assertNull( attrs ); + } + + // ------------------------------------------------------------------- + // check to see if it is present in the matchingRuleRegistry + // ------------------------------------------------------------------- + + if ( isPresent ) + { + assertTrue( registries.getMatchingRuleRegistry().hasMatchingRule( oid ) ); + } + else + { + assertFalse( registries.getMatchingRuleRegistry().hasMatchingRule( oid ) ); + } + } + + + /** + * Tests a number of modify add, remove and replace operation combinations for + * matchingRules on the schema subentry. + */ + public void testAddRemoveReplaceMatchingRules() throws Exception + { + enableSchema( "nis" ); + List descriptions = new ArrayList(); + + // ------------------------------------------------------------------- + // test rejection with non-existant syntax + // ------------------------------------------------------------------- + + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10000 DESC 'bogus desc' SYNTAX 1.2.3.4 X-SCHEMA 'nis' )" ); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10001 DESC 'bogus desc' SYNTAX 1.2.3.4 X-SCHEMA 'nis' )" ); + + try + { + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + fail( "Cannot add matchingRule with bogus non-existant syntax" ); + } + catch( LdapOperationNotSupportedException e ) + { + assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() ); + } + + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", false ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", false ); + + // ------------------------------------------------------------------- + // test add with existant syntax but no name and no desc + // ------------------------------------------------------------------- + + descriptions.clear(); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10000 " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10001 " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", true ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", true ); + + // ------------------------------------------------------------------- + // test add with existant syntax but no name + // ------------------------------------------------------------------- + + // clear the matchingRules out now + modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", false ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", false ); + + descriptions.clear(); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10000 DESC 'bogus desc' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10001 DESC 'bogus desc' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", true ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", true ); + + // ------------------------------------------------------------------- + // test add success with name + // ------------------------------------------------------------------- + + modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", false ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", false ); + + descriptions.clear(); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10000 NAME 'blah0' DESC 'bogus desc' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10001 NAME ( 'blah1' 'othername1' ) DESC 'bogus desc' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", true ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", true ); + + // ------------------------------------------------------------------- + // test add success full (with obsolete) + // ------------------------------------------------------------------- + + modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", false ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", false ); + + descriptions.clear(); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10000 NAME 'blah0' DESC 'bogus desc' " + + "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10001 NAME ( 'blah1' 'othername1' ) DESC 'bogus desc' " + + "OBSOLETE SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-SCHEMA 'nis' )" ); + + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", true ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", true ); + + // ------------------------------------------------------------------- + // test failure to replace + // ------------------------------------------------------------------- + + modify( DirContext.REMOVE_ATTRIBUTE, descriptions, "matchingRules" ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10000", "nis", false ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10001", "nis", false ); + + try + { + modify( DirContext.REPLACE_ATTRIBUTE, descriptions, "matchingRules" ); + fail( "modify REPLACE operations should not be allowed" ); + } + catch ( LdapOperationNotSupportedException e ) + { + assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() ); + } + + // ------------------------------------------------------------------- + // check add no schema info + // ------------------------------------------------------------------- + + descriptions.clear(); + descriptions.add( "( 1.3.6.1.4.1.18060.0.4.1.1.10002 DESC 'bogus desc' " + + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ); + modify( DirContext.ADD_ATTRIBUTE, descriptions, "matchingRules" ); + checkMatchingRulePresent( "1.3.6.1.4.1.18060.0.4.1.1.10002", "other", true ); + } + // ----------------------------------------------------------------------- // AttributeType Tests