directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889474 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/ ldap-schema-loader/src/test/java/org/apache/directory/server/schema/ ldap/src/main/java/org/apache/directory/shared/...
Date Fri, 11 Dec 2009 00:03:17 GMT
Author: elecharny
Date: Fri Dec 11 00:03:16 2009
New Revision: 889474

URL: http://svn.apache.org/viewvc?rev=889474&view=rev
Log:
o Added a first test for LdapSyntax
o Added a lookupLdapSyntax() method in SchemaManager

Modified:
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=889474&r1=889473&r2=889474&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Fri Dec 11 00:03:16 2009
@@ -1353,6 +1353,15 @@
     /**
      * {@inheritDoc}
      */
+    public LdapSyntax lookupLdapSyntaxRegistry( String oid ) throws NamingException
+    {
+        return registries.getLdapSyntaxRegistry().lookup( StringTools.toLowerCase( oid ).trim()
);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
     public SyntaxChecker lookupSyntaxCheckerRegistry( String oid ) throws NamingException
     {
         return registries.getSyntaxCheckerRegistry().lookup( oid );

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java?rev=889474&r1=889473&r2=889474&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java
Fri Dec 11 00:03:16 2009
@@ -37,6 +37,7 @@
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.schema.LdapSyntax;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.SyntaxChecker;
@@ -45,6 +46,7 @@
 import org.apache.directory.shared.ldap.schema.comparators.CsnComparator;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
+import org.apache.directory.shared.ldap.schema.syntaxCheckers.OctetStringSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntaxCheckers.RegexSyntaxChecker;
 import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
@@ -130,6 +132,25 @@
     }
 
 
+    private boolean isSyntaxPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry( oid );
+
+            return syntax != null;
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
+            return false;
+        }
+        catch ( NamingException ne )
+        {
+            return false;
+        }
+    }
+
+
     //=========================================================================
     // For each test, we will check many different things.
     // If the test is successful, we want to know if the SchemaObject
@@ -821,7 +842,35 @@
     //=========================================================================
     // Syntax addition tests
     //-------------------------------------------------------------------------
-    // TODO
+    /**
+     * Try to inject a new valid Syntax
+     */
+    @Test
+    public void testAddValidSyntax() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int sSize = schemaManager.getLdapSyntaxRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        LdapSyntax syntax = new LdapSyntax( "1.1.0" );
+        //syntax.setSyntaxChecker( new RegexSyntaxChecker( "1.1.0" ) );
+
+        // It should not fail
+        assertTrue( schemaManager.add( syntax ) );
+
+        LdapSyntax added = schemaManager.lookupLdapSyntaxRegistry( "1.1.0" );
+
+        assertNotNull( added );
+        assertEquals( OctetStringSyntaxChecker.class.getName(), added.getSyntaxChecker().getClass().getName()
);
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+
+        assertTrue( isSyntaxPresent( schemaManager, "1.1.0" ) );
+        assertEquals( sSize + 1, schemaManager.getLdapSyntaxRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
+    }
+
 
     //=========================================================================
     // SyntaxChecker addition tests

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=889474&r1=889473&r2=889474&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Fri Dec 11 00:03:16 2009
@@ -464,6 +464,16 @@
 
 
     /**
+     * Lookup for an LdapSyntax in the LdapSyntax registry
+     * 
+     * @param String oid the OID we are looking for
+     * @return The found LdapSyntax 
+     * @throws NamingException if the OID is not found in the LdapSyntax registry
+     */
+    LdapSyntax lookupLdapSyntaxRegistry( String oid ) throws NamingException;
+
+
+    /**
      * Lookup for a SyntaxChecker in the SyntaxChecker registry
      * 
      * @param String oid the OID we are looking for



Mime
View raw message