directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r892740 - /directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Date Mon, 21 Dec 2009 09:28:21 GMT
Author: elecharny
Date: Mon Dec 21 09:28:20 2009
New Revision: 892740

URL: http://svn.apache.org/viewvc?rev=892740&view=rev
Log:
Added the service init (very dirty)

Modified:
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java?rev=892740&r1=892739&r2=892740&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Mon Dec 21 09:28:20 2009
@@ -19,15 +19,34 @@
 package org.apache.directory.server.core.integ;
 
 
+import static org.junit.Assert.fail;
+
+import java.io.File;
 import java.lang.reflect.Field;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
+import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+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.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.apache.directory.shared.schema.DefaultSchemaManager;
+import org.apache.directory.shared.schema.loader.ldif.JarLdifSchemaLoader;
 import org.junit.Ignore;
 import org.junit.runner.Description;
 import org.junit.runner.notification.RunNotifier;
@@ -44,6 +63,7 @@
 {
     private static final String DIRECTORYSERVICE_FIELD_NAME = "service";
     private FrameworkSuite suite;
+    protected DirectoryService service;
 
     public FrameworkRunner( Class<?> clazz ) throws InitializationError
     {
@@ -63,7 +83,7 @@
             if ( fac != null )
             {
                 val = fac.value().newInstance();
-                val = ( ( DirectoryServiceFactory ) val ).newInstance();
+                service = ( ( DirectoryServiceFactory ) val ).newInstance();
             }
             else // set the parent suit's factory value
             {
@@ -79,13 +99,14 @@
                     val = suitFactory.value().newInstance();
                 }
                 
-                val = ( ( DirectoryServiceFactory ) val ).newInstance();
-                applyLdifs( getSuite().getDescription(), ( DirectoryService ) val );
+                service = ( ( DirectoryServiceFactory ) val ).newInstance();
+                applyLdifs( getSuite().getDescription(), service );
             }
             
-            field.set( getTestClass().getJavaClass(), val );
+            field.set( getTestClass().getJavaClass(), service );
+            init();
             
-            applyLdifs( getDescription(), ( DirectoryService ) val );
+            applyLdifs( getDescription(), service );
             
             super.run( notifier );
         }
@@ -94,6 +115,66 @@
             e.printStackTrace();
         }
     }
+    
+    
+    public void init() throws Exception
+    {
+        SchemaPartition schemaPartition = service.getSchemaService().getSchemaPartition();
+
+        // Init the LdifPartition
+        LdifPartition ldifPartition = new LdifPartition();
+
+        String workingDirectory = service.getWorkingDirectory().getPath();
+
+        ldifPartition.setWorkingDirectory( workingDirectory + "/schema" );
+
+        // Extract the schema on disk (a brand new one) and load the registries
+        File schemaRepository = new File( workingDirectory, "schema" );
+        SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory
) );
+
+        schemaPartition.setWrappedPartition( ldifPartition );
+
+        JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+        service.setSchemaManager( schemaManager );
+
+        // We have to load the schema now, otherwise we won't be able
+        // to initialize the Partitions, as we won't be able to parse 
+        // and normalize their suffix DN
+        boolean loaded = schemaManager.loadAllEnabled();
+        schemaPartition.setSchemaManager( schemaManager );
+
+        List<Throwable> errors = schemaManager.getErrors();
+
+        if ( errors.size() != 0 )
+        {
+            fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
+        }
+
+        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.setSchemaManager( schemaManager );
+        ( ( 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 );
+    }
+
 
 
     @Override
@@ -156,6 +237,7 @@
         if ( ( annotation != null ) && ( annotation.value() != null ) )
         {
             String[] ldifs = annotation.value();
+            
             for( String s : ldifs )
             {
                 injectEntries( service, s );



Mime
View raw message