directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889257 - in /directory/shared/branches/shared-schema: ldap-schema-loader/src/test/java/org/apache/directory/server/schema/SchemaManagerAddTest.java ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java
Date Thu, 10 Dec 2009 13:33:57 GMT
Author: elecharny
Date: Thu Dec 10 13:33:56 2009
New Revision: 889257

URL: http://svn.apache.org/viewvc?rev=889257&view=rev
Log:
o Added a isValid() method to check the FQCN
o Fixed the Comparator add test accordingly

Modified:
    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/LoadableSchemaObject.java

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=889257&r1=889256&r2=889257&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 13:33:56 2009
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.server.schema;
 
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -49,67 +50,84 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
+
 /**
  * A test class for SchemaManager, testig the addition of a SchemaObject.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class SchemaManagerAddTest {
+public class SchemaManagerAddTest
+{
     // A directory in which the ldif files will be stored
     private static String workingDirectory;
 
     // The schema repository
-    private static File schemaRepository;
+    private static File   schemaRepository;
 
-    @BeforeClass
-    public static void setup() throws Exception {
-        workingDirectory = System.getProperty("workingDirectory");
 
-        if (workingDirectory == null) {
-            String path = SchemaManagerAddTest.class.getResource("").getPath();
-            int targetPos = path.indexOf("target");
-            workingDirectory = path.substring(0, targetPos + 6);
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = SchemaManagerAddTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
         }
 
-        schemaRepository = new File(workingDirectory, "schema");
+        schemaRepository = new File( workingDirectory, "schema" );
 
         // Cleanup the target directory
-        FileUtils.deleteDirectory(schemaRepository);
+        FileUtils.deleteDirectory( schemaRepository );
 
-        SchemaLdifExtractor extractor = new SchemaLdifExtractor(new File(workingDirectory));
+        SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory
) );
         extractor.extractOrCopy();
     }
 
+
     @AfterClass
-    public static void cleanup() throws IOException {
+    public static void cleanup() throws IOException
+    {
         // Cleanup the target directory
-        FileUtils.deleteDirectory(schemaRepository);
+        FileUtils.deleteDirectory( schemaRepository );
     }
 
-    private SchemaManager loadSystem() throws Exception {
-        LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
-        SchemaManager schemaManager = new DefaultSchemaManager(loader);
+
+    private SchemaManager loadSystem() throws Exception
+    {
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
 
         String schemaName = "system";
 
-        schemaManager.loadWithDeps(schemaName);
+        schemaManager.loadWithDeps( schemaName );
 
         return schemaManager;
     }
 
-    private boolean isATPresent(SchemaManager schemaManager, String oid) {
-        try {
-            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry(oid);
+
+    private boolean isATPresent( SchemaManager schemaManager, String oid )
+    {
+        try
+        {
+            AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid
);
 
             return attributeType != null;
-        } catch (NoSuchAttributeException nsae) {
+        }
+        catch ( NoSuchAttributeException nsae )
+        {
             return false;
-        } catch (NamingException ne) {
+        }
+        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
@@ -124,289 +142,309 @@
      * Try to inject an AttributeType without any superior nor Syntax : it's invalid
      */
     @Test
-    public void testAddAttributeTypeNoSupNoSyntaxNoSuperior() throws Exception {
+    public void testAddAttributeTypeNoSupNoSyntaxNoSuperior() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType which is Collective, and userApplication AT
      */
     @Test
-    public void testAddAttributeTypeNoSupCollectiveUser() throws Exception {
+    public void testAddAttributeTypeNoSupCollectiveUser() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
-        attributeType.setCollective(true);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+        attributeType.setCollective( true );
 
         // It should not fail
-        assertTrue(schemaManager.add(attributeType));
+        assertTrue( schemaManager.add( attributeType ) );
 
-        assertTrue(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize + 1, schemaManager.getOidRegistry().size());
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType which is Collective, but an operational AT
      */
     @Test
-    public void testAddAttributeTypeNoSupCollectiveOperational() throws Exception {
+    public void testAddAttributeTypeNoSupCollectiveOperational() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.DIRECTORY_OPERATION);
-        attributeType.setCollective(true);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.DIRECTORY_OPERATION );
+        attributeType.setCollective( true );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType which is a NO-USER-MODIFICATION and userApplication
      */
     @Test
-    public void testAddAttributeTypeNoSupNoUserModificationUserAplication() throws Exception
{
+    public void testAddAttributeTypeNoSupNoUserModificationUserAplication() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
-        attributeType.setUserModifiable(false);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
+        attributeType.setUserModifiable( false );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType which is a NO-USER-MODIFICATION and is operational
      */
     @Test
-    public void testAddAttributeTypeNoSupNoUserModificationOpAttr() throws Exception {
+    public void testAddAttributeTypeNoSupNoUserModificationOpAttr() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
-        attributeType.setUserModifiable(false);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
+        attributeType.setUserModifiable( false );
 
         // It should not fail
-        assertTrue(schemaManager.add(attributeType));
+        assertTrue( schemaManager.add( attributeType ) );
 
-        assertTrue(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize + 1, schemaManager.getOidRegistry().size());
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with an invalid EQUALITY MR
      */
     @Test
-    public void testAddAttributeTypeNoSupInvalidEqualityMR() throws Exception {
+    public void testAddAttributeTypeNoSupInvalidEqualityMR() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("0.0");
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "0.0" );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with an invalid ORDERING MR
      */
     @Test
-    public void testAddAttributeTypeNoSupInvalidOrderingMR() throws Exception {
+    public void testAddAttributeTypeNoSupInvalidOrderingMR() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid("0.0");
-        attributeType.setSubstringOid(null);
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( "0.0" );
+        attributeType.setSubstringOid( null );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with an invalid SUBSTR MR
      */
     @Test
-    public void testAddAttributeTypeNoSupInvalidSubstringMR() throws Exception {
+    public void testAddAttributeTypeNoSupInvalidSubstringMR() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid("0.0");
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( "0.0" );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with valid MRs
      */
     @Test
-    public void testAddAttributeTypeNoSupValidMR() throws Exception {
+    public void testAddAttributeTypeNoSupValidMR() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid("2.5.13.1");
-        attributeType.setSubstringOid("2.5.13.1");
-        attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
-        attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( "2.5.13.1" );
+        attributeType.setSubstringOid( "2.5.13.1" );
+        attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
+        attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
 
         // It should not fail
-        assertTrue(schemaManager.add(attributeType));
+        assertTrue( schemaManager.add( attributeType ) );
 
-        assertTrue(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize + 1, schemaManager.getOidRegistry().size());
+        assertTrue( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType which already exist
      */
     @Test
-    public void testAddAttributeTypeAlreadyExist() throws Exception {
+    public void testAddAttributeTypeAlreadyExist() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("2.5.18.4");
-        attributeType.setEqualityOid("2.5.13.1");
-        attributeType.setOrderingOid("2.5.13.1");
-        attributeType.setSubstringOid("2.5.13.1");
+        AttributeType attributeType = new AttributeType( "2.5.18.4" );
+        attributeType.setEqualityOid( "2.5.13.1" );
+        attributeType.setOrderingOid( "2.5.13.1" );
+        attributeType.setSubstringOid( "2.5.13.1" );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
         // The AT must be there
-        assertTrue(isATPresent(schemaManager, "2.5.18.4"));
+        assertTrue( isATPresent( schemaManager, "2.5.18.4" ) );
 
         // Check that it hasen't changed
-        AttributeType original = schemaManager.lookupAttributeTypeRegistry("2.5.18.4");
-        assertEquals("distinguishedNameMatch", original.getEqualityOid());
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        AttributeType original = schemaManager.lookupAttributeTypeRegistry( "2.5.18.4" );
+        assertEquals( "distinguishedNameMatch", original.getEqualityOid() );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     //-------------------------------------------------------------------------
     // Then, with a superior
     //-------------------------------------------------------------------------
@@ -415,270 +453,288 @@
      * take its superior' syntax and MR
      */
     @Test
-    public void testAddAttributeTypeSupNoSyntaxNoSuperior() throws Exception {
+    public void testAddAttributeTypeSupNoSyntaxNoSuperior() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSuperiorOid("2.5.18.4");
-        attributeType.setUsage(UsageEnum.DIRECTORY_OPERATION);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "2.5.18.4" );
+        attributeType.setUsage( UsageEnum.DIRECTORY_OPERATION );
 
         // It should not fail
-        assertTrue(schemaManager.add(attributeType));
+        assertTrue( schemaManager.add( attributeType ) );
 
-        AttributeType result = schemaManager.lookupAttributeTypeRegistry("1.1.0");
+        AttributeType result = schemaManager.lookupAttributeTypeRegistry( "1.1.0" );
 
-        assertEquals("1.3.6.1.4.1.1466.115.121.1.12", result.getSyntaxOid());
-        assertEquals("2.5.13.1", result.getEqualityOid());
-        assertEquals(atrSize + 1, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize + 1, schemaManager.getOidRegistry().size());
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.12", result.getSyntaxOid() );
+        assertEquals( "2.5.13.1", result.getEqualityOid() );
+        assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize + 1, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with a superior and different USAGE
      */
     @Test
-    public void testAddAttributeTypeSupDifferentUsage() throws Exception {
+    public void testAddAttributeTypeSupDifferentUsage() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSuperiorOid("2.5.18.4");
-        attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "2.5.18.4" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with itself as a superior
      */
     @Test
-    public void testAddAttributeTypeSupWithOwnSup() throws Exception {
+    public void testAddAttributeTypeSupWithOwnSup() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSuperiorOid("1.1.0");
-        attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "1.1.0" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     /**
      * Try to inject an AttributeType with a bad superior
      */
     @Test
-    public void testAddAttributeTypeSupBadSup() throws Exception {
+    public void testAddAttributeTypeSupBadSup() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int atrSize = schemaManager.getAttributeTypeRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
-        AttributeType attributeType = new AttributeType("1.1.0");
-        attributeType.setEqualityOid(null);
-        attributeType.setOrderingOid(null);
-        attributeType.setSubstringOid(null);
-        attributeType.setSuperiorOid("0.0");
-        attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
+        AttributeType attributeType = new AttributeType( "1.1.0" );
+        attributeType.setEqualityOid( null );
+        attributeType.setOrderingOid( null );
+        attributeType.setSubstringOid( null );
+        attributeType.setSuperiorOid( "0.0" );
+        attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );
 
         // It should fail
-        assertFalse(schemaManager.add(attributeType));
+        assertFalse( schemaManager.add( attributeType ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-        Throwable error = errors.get(0);
+        assertEquals( 1, errors.size() );
+        Throwable error = errors.get( 0 );
 
-        assertTrue(error instanceof LdapSchemaViolationException);
+        assertTrue( error instanceof LdapSchemaViolationException );
 
-        assertFalse(isATPresent(schemaManager, "1.1.0"));
-        assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertFalse( isATPresent( schemaManager, "1.1.0" ) );
+        assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
     }
 
+
     //=========================================================================
     // Comparator addition tests
     //-------------------------------------------------------------------------
     @Test
-    public void testAddNewComparator() throws Exception {
+    public void testAddNewComparator() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int ctrSize = schemaManager.getComparatorRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
         String oid = "0.0.0";
-        LdapComparator<?> lc = new BooleanComparator(oid);
+        LdapComparator<?> lc = new BooleanComparator( oid );
 
-        assertTrue(schemaManager.add(lc));
+        assertTrue( schemaManager.add( lc ) );
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(0, errors.size());
+        assertEquals( 0, errors.size() );
 
-        assertEquals(ctrSize + 1, schemaManager.getComparatorRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
 
-        try {
-            LdapComparator<?> added = schemaManager.lookupComparatorRegistry(oid);
+        try
+        {
+            LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );
 
-            assertNotNull(added);
-        } catch (NamingException ne) {
+            assertNotNull( added );
+        }
+        catch ( NamingException ne )
+        {
             fail();
         }
     }
 
+
     //@Test
-    public void testAddAlreadyExistingComparator() throws Exception {
+    public void testAddAlreadyExistingComparator() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int ctrSize = schemaManager.getComparatorRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
         String oid = "0.0.0";
-        LdapComparator<?> lc = new BooleanComparator(oid);
+        LdapComparator<?> lc = new BooleanComparator( oid );
 
-        assertTrue(schemaManager.add(lc));
+        assertTrue( schemaManager.add( lc ) );
 
-        try {
-            LdapComparator<?> added = schemaManager.lookupComparatorRegistry(oid);
+        try
+        {
+            LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );
 
-            assertNotNull(added);
-        } catch (NamingException ne) {
+            assertNotNull( added );
+        }
+        catch ( NamingException ne )
+        {
             fail();
         }
 
         List<Throwable> errors = schemaManager.getErrors();
-        assertEquals(0, errors.size());
-        assertEquals(ctrSize + 1, schemaManager.getComparatorRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertEquals( 0, errors.size() );
+        assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
 
-        lc = new CsnComparator(oid);
+        lc = new CsnComparator( oid );
 
-        assertFalse(schemaManager.add(lc));
+        assertFalse( schemaManager.add( lc ) );
 
         errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
+        assertEquals( 1, errors.size() );
 
-        assertEquals(ctrSize + 1, schemaManager.getComparatorRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
 
-        try {
-            LdapComparator<?> added = schemaManager.lookupComparatorRegistry(oid);
+        try
+        {
+            LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );
 
-            assertNotNull(added);
-        } catch (NamingException ne) {
+            assertNotNull( added );
+        }
+        catch ( NamingException ne )
+        {
             fail();
         }
     }
 
+
     /**
      * Test that we can't add two comparators with the same class code.
      * 
      * This is a questionable test, as there is no real reason why it could
      * be a problem.
      */
-    @Ignore
     @Test
-    public void testAddAnotherComparatorWithSameClass() throws Exception {
+    public void testAddComparatorWithWrongFQCN() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int ctrSize = schemaManager.getComparatorRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
         String oid = "0.0.0";
-        LdapComparator<?> lc = new BooleanComparator(oid);
+        LdapComparator<?> lc = new BooleanComparator( oid );
         // using java.sql.ResultSet cause it is very unlikely to get loaded
-        // in ADS
-        lc.setFqcn("java.sql.ResultSet");
+        // in ADS, as the FQCN is not the one expected
+        lc.setFqcn( "java.sql.ResultSet" );
 
-        assertTrue(schemaManager.add(lc));
+        assertFalse( schemaManager.add( lc ) );
 
         List<Throwable> errors = schemaManager.getErrors();
         errors = schemaManager.getErrors();
-        assertEquals(0, errors.size());
+        assertEquals( 1, errors.size() );
 
-        lc = new BooleanComparator("0.0.1");
-        lc.setFqcn("java.sql.ResultSet");
+        assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
 
-        // FIXME this has to fail cause the java.sql.ResultSet class was already used in
the above lc
-        assertFalse(schemaManager.add(lc));
-
-        errors = schemaManager.getErrors();
-        errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
-
-        assertEquals(ctrSize + 1, schemaManager.getComparatorRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
-
-        try {
-            LdapComparator<?> added = schemaManager.lookupComparatorRegistry(oid);
-
-            assertNotNull(added);
-        } catch (NamingException ne) {
+        try
+        {
+            LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );
             fail();
         }
-
+        catch ( Exception e )
+        {
+            // Expected
+            assertTrue( true );
+        }
     }
 
+
     @Ignore
     // Definitively not an issue.
     @Test
-    public void testAddNewComparatorWithDuplicateName() throws Exception {
+    public void testAddNewComparatorWithDuplicateName() throws Exception
+    {
         SchemaManager schemaManager = loadSystem();
         int ctrSize = schemaManager.getComparatorRegistry().size();
         int goidSize = schemaManager.getOidRegistry().size();
 
         List<String> names = new ArrayList<String>();
-        names.add("name");
-        names.add("name");
+        names.add( "name" );
+        names.add( "name" );
 
         String oid = "0.0.0";
-        LdapComparator<?> lc = new BooleanComparator(oid);
-        lc.setNames(names);
+        LdapComparator<?> lc = new BooleanComparator( oid );
+        lc.setNames( names );
 
         // FIXME this should fail cause the same name was set twice
-        assertTrue(schemaManager.add(lc));
+        assertTrue( schemaManager.add( lc ) );
 
         List<Throwable> errors = schemaManager.getErrors();
         errors = schemaManager.getErrors();
-        assertEquals(1, errors.size());
+        assertEquals( 1, errors.size() );
 
-        assertEquals(ctrSize + 1, schemaManager.getComparatorRegistry().size());
-        assertEquals(goidSize, schemaManager.getOidRegistry().size());
+        assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
+        assertEquals( goidSize, schemaManager.getOidRegistry().size() );
 
-        try {
-            LdapComparator<?> added = schemaManager.lookupComparatorRegistry(oid);
+        try
+        {
+            LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );
 
-            assertNotNull(added);
-        } catch (NamingException ne) {
+            assertNotNull( added );
+        }
+        catch ( NamingException ne )
+        {
             fail();
         }
 

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java?rev=889257&r1=889256&r2=889257&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/LoadableSchemaObject.java
Thu Dec 10 13:33:56 2009
@@ -23,6 +23,7 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -38,10 +39,10 @@
     private static final long serialVersionUID = 1L;
 
     /** The Full Qualified Class Name */
-    private String fqcn;
+    private String            fqcn;
 
     /** The base64 encoded bytecode for this schema */
-    private String bytecode;
+    private String            bytecode;
 
 
     /**
@@ -167,6 +168,27 @@
         {
             return fqcn.equals( that.fqcn );
         }
+    }
+
+
+    /**
+     * Test that the FQCN is equal to the instance's name. If the FQCN is
+     * empty, fill it with the instance's name
+     *
+     * @return true if the FQCN is correctly set
+     */
+    public boolean isValid()
+    {
+        String className = this.getClass().getName();
 
+        if ( StringTools.isEmpty( fqcn ) )
+        {
+            fqcn = className;
+            return true;
+        }
+        else
+        {
+            return className.equals( fqcn );
+        }
     }
 }



Mime
View raw message