directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889340 - 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 17:25:50 GMT
Author: elecharny
Date: Thu Dec 10 17:25:47 2009
New Revision: 889340

URL: http://svn.apache.org/viewvc?rev=889340&view=rev
Log:
o Added tests for Normalizer add
o Added a lookupNormalizerRegistry() 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=889340&r1=889339&r2=889340&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 17:25:47 2009
@@ -90,32 +90,32 @@
 public class DefaultSchemaManager implements SchemaManager
 {
     /** static class logger */
-    private static final Logger   LOG       = LoggerFactory.getLogger( DefaultSchemaManager.class
);
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultSchemaManager.class
);
 
     /** The NamingContext this SchemaManager is associated with */
-    private LdapDN                namingContext;
+    private LdapDN namingContext;
 
     /** The global registries for this namingContext */
-    private volatile Registries   registries;
+    private volatile Registries registries;
 
     /** The list of errors produced when loading some schema elements */
-    private List<Throwable>       errors;
+    private List<Throwable> errors;
 
     /** The Schema schemaLoader used by this SchemaManager */
-    private SchemaLoader          schemaLoader;
+    private SchemaLoader schemaLoader;
 
     /** the factory that generates respective SchemaObjects from LDIF entries */
     protected final EntityFactory factory;
 
     /** the normalized name for the schema modification attributes */
-    private LdapDN                schemaModificationAttributesDN;
+    private LdapDN schemaModificationAttributesDN;
 
     /** A flag indicating that the SchemaManager is relaxed or not */
-    private boolean               isRelaxed = STRICT;
+    private boolean isRelaxed = STRICT;
 
     /** Two flags for RELAXED and STRUCT */
-    public static final boolean   STRICT    = false;
-    public static final boolean   RELAXED   = true;
+    public static final boolean STRICT = false;
+    public static final boolean RELAXED = true;
 
 
     /**
@@ -1342,6 +1342,15 @@
 
 
     /**
+     * {@inheritDoc}
+     */
+    public Normalizer lookupNormalizerRegistry( String oid ) throws NamingException
+    {
+        return registries.getNormalizerRegistry().lookup( oid );
+    }
+
+
+    /**
      * Check that the given OID exists in the globalOidRegistry.
      */
     private boolean checkOidExist( SchemaObject schemaObject )

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=889340&r1=889339&r2=889340&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 17:25:47 2009
@@ -37,11 +37,13 @@
 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.Normalizer;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 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.schema.DefaultSchemaManager;
 import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 import org.junit.AfterClass;
@@ -677,6 +679,7 @@
         }
     }
 
+
     //=========================================================================
     // DITContentRule addition tests
     //-------------------------------------------------------------------------
@@ -705,7 +708,107 @@
     //=========================================================================
     // Normalizer addition tests
     //-------------------------------------------------------------------------
-    // TODO
+    @Test
+    public void testAddNewNormalizer() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getNormalizerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        Normalizer normalizer = new NoOpNormalizer( oid );
+
+        assertTrue( schemaManager.add( normalizer ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+
+        assertEquals( nrSize + 1, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        Normalizer added = schemaManager.lookupNormalizerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( normalizer.getClass().getName(), added.getFqcn() );
+    }
+
+
+    @Test
+    public void testAddAlreadyExistingNormalizer() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getNormalizerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        Normalizer normalizer = new NoOpNormalizer( oid );
+
+        assertTrue( schemaManager.add( normalizer ) );
+
+        Normalizer added = schemaManager.lookupNormalizerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( normalizer.getClass().getName(), added.getFqcn() );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        assertEquals( 0, errors.size() );
+        assertEquals( nrSize + 1, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        Normalizer normalizer2 = new NoOpNormalizer( oid );
+
+        assertFalse( schemaManager.add( normalizer2 ) );
+
+        errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+
+        assertEquals( nrSize + 1, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        added = schemaManager.lookupNormalizerRegistry( oid );
+
+        assertNotNull( added );
+        assertEquals( normalizer.getClass().getName(), added.getFqcn() );
+    }
+
+
+    /**
+     * Test that we can't add two Normalizers with the same class code.
+     */
+    @Test
+    public void testAddNormalizerWithWrongFQCN() throws Exception
+    {
+        SchemaManager schemaManager = loadSystem();
+        int nrSize = schemaManager.getNormalizerRegistry().size();
+        int goidSize = schemaManager.getOidRegistry().size();
+
+        String oid = "0.0.0";
+        Normalizer normalizer = new NoOpNormalizer( oid );
+
+        // using java.sql.ResultSet cause it is very unlikely to get loaded
+        // in ADS, as the FQCN is not the one expected
+        normalizer.setFqcn( "java.sql.ResultSet" );
+
+        assertFalse( schemaManager.add( normalizer ) );
+
+        List<Throwable> errors = schemaManager.getErrors();
+        errors = schemaManager.getErrors();
+        assertEquals( 1, errors.size() );
+
+        assertEquals( nrSize, schemaManager.getNormalizerRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
+
+        try
+        {
+            schemaManager.lookupNormalizerRegistry( oid );
+            fail();
+        }
+        catch ( Exception e )
+        {
+            // Expected
+            assertTrue( true );
+        }
+    }
 
     //=========================================================================
     // ObjectClass 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=889340&r1=889339&r2=889340&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 17:25:47 2009
@@ -454,6 +454,16 @@
 
 
     /**
+     * Lookup for a Normalizer in the Normalizer registry
+     * 
+     * @param String oid the OID we are looking for
+     * @return The found Normalizer 
+     * @throws NamingException if the OID is not found in the Normalizer registry
+     */
+    Normalizer lookupNormalizerRegistry( String oid ) throws NamingException;
+
+
+    /**
      * Get an immutable reference on the AttributeType registry
      * 
      * @return A reference to the AttributeType registry.



Mime
View raw message