directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r813577 - in /directory/apacheds/branches/apacheds-schema: core-integ/src/test/java/org/apache/directory/server/core/jndi/ core/src/main/java/org/apache/directory/server/core/ core/src/main/java/org/apache/directory/server/core/partition/
Date Thu, 10 Sep 2009 20:38:25 GMT
Author: elecharny
Date: Thu Sep 10 20:38:24 2009
New Revision: 813577

URL: http://svn.apache.org/viewvc?rev=813577&view=rev
Log:
Added partitions have the registries injected if it's not already done
Fixed a NPE by injecting the working directory in the JDBMPartition

Modified:
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java?rev=813577&r1=813576&r2=813577&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
Thu Sep 10 20:38:24 2009
@@ -20,33 +20,16 @@
 package org.apache.directory.server.core.jndi;
 
 
-import org.apache.directory.server.core.DefaultDirectoryService;
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.entry.ServerEntry;
-import org.apache.directory.server.core.integ.CiRunner;
-import org.apache.directory.server.core.integ.DirectoryServiceFactory;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
-import org.apache.directory.server.core.integ.Level;
-import org.apache.directory.server.core.integ.annotations.Factory;
-import org.apache.directory.server.core.integ.annotations.CleanupLevel;
-import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.xdbm.Index;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
-import org.apache.directory.server.core.partition.ldif.LdifPartition;
-import org.apache.directory.server.core.schema.SchemaPartition;
-import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
-import org.apache.directory.shared.ldap.name.LdapDN;
-
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attribute;
@@ -58,8 +41,31 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
-import java.util.HashSet;
-import java.util.Set;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.DefaultDirectoryService;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.DirectoryServiceFactory;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.core.partition.ldif.LdifPartition;
+import org.apache.directory.server.core.schema.SchemaPartition;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.schema.loader.ldif.JarLdifSchemaLoader;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
 
 /**
@@ -82,15 +88,61 @@
     {
         public DirectoryService newInstance() throws Exception
         {
-            DefaultDirectoryService service = new DefaultDirectoryService();
-            SchemaPartition schemaPartition = new SchemaPartition();
-            schemaPartition.setWrappedPartition( new LdifPartition() );
-            service.getSchemaService().setSchemaPartition( schemaPartition );
+            String workingDirectory = System.getProperty( "workingDirectory" );
+
+            if ( workingDirectory == null )
+            {
+                String path = DirectoryServiceFactory.class.getResource( "" ).getPath();
+                int targetPos = path.indexOf( "target" );
+                workingDirectory = path.substring( 0, targetPos + 6 ) + "/server-work";
+            }
+
+            DirectoryService service = new DefaultDirectoryService();
+            service.setWorkingDirectory( new File( workingDirectory ) );
+            SchemaPartition schemaPartition = service.getSchemaService().getSchemaPartition();
+            Registries registries = service.getRegistries();
+            
+            // Init the LdifPartition
+            LdifPartition ldifPartition = new LdifPartition();
+            
+            ldifPartition.setWorkingDirectory( workingDirectory + "/schema" );
+            
+            // Extract the schema on disk (a brand new one) and load the registries
+            SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory
) );
+            
+            schemaPartition.setWrappedPartition( ldifPartition );
+            schemaPartition.setRegistries( registries );
+            
+            JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
+            loader.loadAllEnabled( registries );
+            extractor.extractOrCopy();
+
             service.getChangeLog().setEnabled( true );
 
+            // change the working directory to something that is unique
+            // on the system and somewhere either under target directory
+            // or somewhere in a temp area of the machine.
+            
+            // Inject the System Partition
+            Partition systemPartition = new JdbmPartition();
+            systemPartition.setId( "system" );
+            ((JdbmPartition)systemPartition).setCacheSize( 500 );
+            systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
+            systemPartition.setRegistries( registries );
+            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
+    
+            // Add objectClass attribute for the system partition
+            Set<Index<?,ServerEntry>> indexedAttrs = new HashSet<Index<?,ServerEntry>>();
+            indexedAttrs.add( 
+                new JdbmIndex<Object,ServerEntry>( SchemaConstants.OBJECT_CLASS_AT
) );
+            ( ( JdbmPartition ) systemPartition ).setIndexedAttributes( indexedAttrs );
+            
+            service.setSystemPartition( systemPartition );
+
             JdbmPartition partition = new JdbmPartition();
             partition.setId( "apache" );
             partition.setSuffix( SUFFIX_DN );
+            partition.setPartitionDir( new File( workingDirectory, "apache" ) );
 
             HashSet<Index<?, ServerEntry>> indexedAttributes = new HashSet<Index<?,
ServerEntry>>();
             indexedAttributes.add( new JdbmIndex<String,ServerEntry>( "objectClass"
) );
@@ -98,10 +150,8 @@
             indexedAttributes.add( new JdbmIndex<String,ServerEntry>( "uid" ) );
             partition.setIndexedAttributes( indexedAttributes );
 
-            Set<Partition> partitions = new HashSet<Partition>();
-            partitions.add( partition );
+            service.addPartition( partition );
 
-            service.setPartitions( partitions );
             return service;
         }
     }

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=813577&r1=813576&r2=813577&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
Thu Sep 10 20:38:24 2009
@@ -332,13 +332,16 @@
         Set<Partition> cloned = new HashSet<Partition>();
         cloned.addAll( partitions );
         Set<String> names = new HashSet<String>();
+        
         for ( Partition partition : cloned )
         {
             String id = partition.getId();
+            
             if ( names.contains( id ) )
             {
                 LOG.warn( "Encountered duplicate partition {} identifier.", id );
             }
+            
             names.add( id );
         }
 

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=813577&r1=813576&r2=813577&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
Thu Sep 10 20:38:24 2009
@@ -238,7 +238,7 @@
         {
             for ( Partition partition : directoryService.getPartitions() )
             {
-                //adminDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping()
);
+                partition.setRegistries( registries );
                 CoreSession adminSession = new DefaultCoreSession( 
                     new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), directoryService
);
     



Mime
View raw message