directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889366 - 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 Thu, 10 Dec 2009 18:52:01 GMT
Author: elecharny
Date: Thu Dec 10 18:52:00 2009
New Revision: 889366

URL: http://svn.apache.org/viewvc?rev=889366&view=rev
Log:
o Added tests for SyntaxChecker add
o Added a lookupSyntaxCheckerRegistry() method in SchemaManager
o Fixed an issue in the chekOid() method, we were testing for LdapSyntax instead of SyntaxChecker

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=889366&r1=889365&r2=889366&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
Thu Dec 10 18:52:00 2009
@@ -1351,6 +1351,15 @@
 
 
     /**
+     * {@inheritDoc}
+     */
+    public SyntaxChecker lookupSyntaxCheckerRegistry( String oid ) throws NamingException
+    {
+        return registries.getSyntaxCheckerRegistry().lookup( oid );
+    }
+
+
+    /**
      * Check that the given OID exists in the globalOidRegistry.
      */
     private boolean checkOidExist( SchemaObject schemaObject )
@@ -1365,9 +1374,9 @@
             return registries.getComparatorRegistry().contains( schemaObject.getOid() );
         }
 
-        if ( schemaObject instanceof LdapSyntax )
+        if ( schemaObject instanceof SyntaxChecker )
         {
-            return registries.getLdapSyntaxRegistry().contains( schemaObject.getOid() );
+            return registries.getSyntaxCheckerRegistry().contains( schemaObject.getOid()
);
         }
 
         if ( schemaObject instanceof Normalizer )

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=889366&r1=889365&r2=889366&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
Thu Dec 10 18:52:00 2009
@@ -39,11 +39,13 @@
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.Normalizer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 import org.apache.directory.shared.ldap.schema.comparators.BooleanComparator;
 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.RegexSyntaxChecker;
 import org.apache.directory.shared.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 import org.junit.AfterClass;
@@ -810,6 +812,7 @@
         }
     }
 
+
     //=========================================================================
     // ObjectClass addition tests
     //-------------------------------------------------------------------------
@@ -823,6 +826,105 @@
     //=========================================================================
     // SyntaxChecker addition tests
     //-------------------------------------------------------------------------
-    // TODO
+    @Test
+    public void testAddNewSyntaxChecker() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        SyntaxChecker syntaxChecker = new RegexSyntaxChecker( oid );
+
+        assertTrue( schemaManager.add( syntaxChecker ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+
+        assertEquals( nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        SyntaxChecker added = schemaManager.lookupSyntaxCheckerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( syntaxChecker.getClass().getName(), added.getFqcn() );
+    }
+
 
+    @Test
+    public void testAddAlreadyExistingSyntaxChecker() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        SyntaxChecker syntaxChecker = new RegexSyntaxChecker( oid );
+
+        assertTrue( schemaManager.add( syntaxChecker ) );
+
+        SyntaxChecker added = schemaManager.lookupSyntaxCheckerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( syntaxChecker.getClass().getName(), added.getFqcn() );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+        assertEquals( nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        SyntaxChecker syntaxChecker2 = new RegexSyntaxChecker( oid );
+
+        assertFalse( schemaManager.add( syntaxChecker2 ) );
+
+        errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+
+        assertEquals( nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        added = schemaManager.lookupSyntaxCheckerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( syntaxChecker.getClass().getName(), added.getFqcn() );
+    }
+
+
+    /**
+     * Test that we can't add two SyntaxCheckers with the same class code.
+     */
+    @Test
+    public void testAddSyntaxCheckerWithWrongFQCN() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        SyntaxChecker syntaxChecker = new RegexSyntaxChecker( oid );
+
+        // using java.sql.ResultSet cause it is very unlikely to get loaded
+        // in ADS, as the FQCN is not the one expected
+        syntaxChecker.setFqcn( "java.sql.ResultSet" );
+
+        assertFalse( schemaManager.add( syntaxChecker ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+
+        assertEquals( nrSize, schemaManager.getSyntaxCheckerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        try
+        {
+            schemaManager.lookupSyntaxCheckerRegistry( oid );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            // Expected
+            assertTrue( true );
+        }
+    }
 }

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=889366&r1=889365&r2=889366&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
Thu Dec 10 18:52:00 2009
@@ -464,6 +464,16 @@
 
 
     /**
+     * Lookup for a SyntaxChecker in the SyntaxChecker registry
+     * 
+     * @param String oid the OID we are looking for
+     * @return The found SyntaxChecker 
+     * @throws NamingException if the OID is not found in the SyntaxChecker registry
+     */
+    SyntaxChecker lookupSyntaxCheckerRegistry( String oid ) throws NamingException;
+
+
+    /**
      * Get an immutable reference on the AttributeType registry
      * 
      * @return A reference to the AttributeType registry.



Mime
View raw message