directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r889323 - in /directory/apacheds/branches/apacheds-schema/core-integ/src: main/java/org/apache/directory/server/core/integ/ main/java/org/apache/directory/server/core/integ/state/ test/java/org/apache/directory/server/core/authz/ test/java/...
Date Thu, 10 Dec 2009 16:44:42 GMT
Author: elecharny
Date: Thu Dec 10 16:44:41 2009
New Revision: 889323

URL: http://svn.apache.org/viewvc?rev=889323&view=rev
Log:
Fix for DIRSERVER-1437 : the DS initialization wasn't done in a separate place, so the cleanup
was destroying the schema partition, leading to exceptions later

Modified:
    directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/authz/AutzIntegUtils.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/jndi/MixedCaseITest.java
    directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java?rev=889323&r1=889322&r2=889323&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
Thu Dec 10 16:44:41 2009
@@ -59,8 +59,11 @@
      * The default factory returns stock instances of a directory
      * service with smart defaults
      */
-    DirectoryServiceFactory DEFAULT = new DirectoryServiceFactory() 
+    DirectoryServiceFactory DEFAULT = new DirectoryServiceFactory()
     {
+        private DirectoryService service;
+
+
         public DirectoryService newInstance() throws Exception
         {
             String workingDirectory = System.getProperty( "workingDirectory" );
@@ -72,33 +75,42 @@
                 workingDirectory = path.substring( 0, targetPos + 6 ) + "/server-work";
             }
 
-            DirectoryService service = new DefaultDirectoryService();
+            service = new DefaultDirectoryService();
             service.setWorkingDirectory( new File( workingDirectory ) );
+
+            return service;
+        }
+
+
+        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 ) );
@@ -111,26 +123,27 @@
             // 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 );
+            ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
             systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
             systemPartition.setSchemaManager( schemaManager );
-            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
-    
+            ( ( 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
) );
+            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 );
-            
-            return service;
         }
     };
 
+
+    void init() throws Exception;
+
+
     DirectoryService newInstance() throws Exception;
 }

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java?rev=889323&r1=889322&r2=889323&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
Thu Dec 10 16:44:41 2009
@@ -108,9 +108,11 @@
      *
      * @throws Exception on failures to start the core directory service
      */
-    public void startup() throws Exception
+    public void startup( InheritableSettings settings ) throws Exception
     {
         LOG.debug( "calling startup()" );
+        DirectoryServiceFactory factory = settings.getFactory();
+        factory.init();
         context.getService().startup();
     }
 
@@ -161,12 +163,10 @@
                     return;
                 }
 
-                
                 context.setState( context.getStartedNormalState() );
                 context.getState().test( testClass, statement, notifier, settings );
                 return;
 
-
             case PRISTINE:
             case ROLLBACK:
                 try
@@ -180,7 +180,6 @@
                     return;
                 }
 
-                /*
                 try
                 {
                     cleanup();
@@ -191,11 +190,9 @@
                     testAborted( notifier, settings.getDescription(), ioe );
                     return;
                 }
-                */
-
                 try
                 {
-                    startup();
+                    startup( settings );
                 }
                 catch ( Exception e )
                 {

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/authz/AutzIntegUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/authz/AutzIntegUtils.java?rev=889323&r1=889322&r2=889323&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/authz/AutzIntegUtils.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/authz/AutzIntegUtils.java
Thu Dec 10 16:44:41 2009
@@ -71,7 +71,6 @@
 {
     public static DirectoryService service;
 
-
     public static class ServiceFactory implements DirectoryServiceFactory
     {
         public DirectoryService newInstance() throws Exception
@@ -85,30 +84,39 @@
                 workingDirectory = path.substring( 0, targetPos + 6 ) + "/server-work";
             }
 
-            DirectoryService service = new DefaultDirectoryService();
+            service = new DefaultDirectoryService();
             service.setWorkingDirectory( new File( workingDirectory ) );
+
+            return service;
+        }
+
+
+        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 );
 
             schemaManager.loadAllEnabled();
-            
+
             List<Throwable> errors = schemaManager.getErrors();
-            
+
             if ( errors.size() != 0 )
             {
                 fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
@@ -123,29 +131,26 @@
             // 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 );
+            ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
             systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
             systemPartition.setSchemaManager( schemaManager );
-            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
-    
+            ( ( 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
) );
+            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 );
             service.setAccessControlEnabled( true );
             AutzIntegUtils.service = service;
-            return service;
         }
     }
 
-
     public static class DefaultServiceFactory implements DirectoryServiceFactory
     {
         public DirectoryService newInstance() throws Exception
@@ -161,32 +166,41 @@
 
             DirectoryService service = new DefaultDirectoryService();
             service.setWorkingDirectory( new File( workingDirectory ) );
+
+            return service;
+        }
+
+
+        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 );
 
             schemaManager.loadAllEnabled();
-            
+
             List<Throwable> errors = schemaManager.getErrors();
-            
+
             if ( errors.size() != 0 )
             {
                 fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
             }
-            
+
             schemaPartition.setSchemaManager( schemaManager );
 
             extractor.extractOrCopy();
@@ -196,25 +210,23 @@
             // 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 );
+            ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
             systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
             systemPartition.setSchemaManager( schemaManager );
-            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
-    
+            ( ( 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
) );
+            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 );
             service.setAccessControlEnabled( false );
             AutzIntegUtils.service = service;
-            return service;
         }
     }
 
@@ -248,7 +260,7 @@
     public static DirContext getContextAsAdmin( String dn ) throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
-        Hashtable<String,Object> env = ( Hashtable<String,Object> ) sysRoot.getEnvironment().clone();
+        Hashtable<String, Object> env = ( Hashtable<String, Object> ) sysRoot.getEnvironment().clone();
         env.put( DirContext.PROVIDER_URL, dn );
         env.put( DirContext.SECURITY_AUTHENTICATION, "simple" );
         env.put( DirContext.SECURITY_PRINCIPAL, "uid=admin, ou=system" );
@@ -342,7 +354,7 @@
         group.put( objectClass );
         objectClass.add( "top" );
         objectClass.add( "groupOfUniqueNames" );
-        
+
         // TODO might be ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED
         group.put( "uniqueMember", "uid=admin, ou=system" );
         adminCtx.createSubcontext( "cn=" + groupName + ",ou=groups", group );
@@ -408,7 +420,7 @@
     public static DirContext getContextAs( Name user, String password, String dn ) throws
Exception
     {
         LdapContext sysRoot = getSystemContext( service );
-        Hashtable<String,Object> env = ( Hashtable<String,Object> ) sysRoot.getEnvironment().clone();
+        Hashtable<String, Object> env = ( Hashtable<String, Object> ) sysRoot.getEnvironment().clone();
         env.put( DirContext.PROVIDER_URL, dn );
         env.put( DirContext.SECURITY_AUTHENTICATION, "simple" );
         env.put( DirContext.SECURITY_PRINCIPAL, user.toString() );
@@ -508,8 +520,8 @@
         Attributes changes = new BasicAttributes( "subentryACI", aciItem, true );
         adminCtx.modifyAttributes( "", DirContext.ADD_ATTRIBUTE, changes );
     }
-    
-    
+
+
     /**
      * Replaces values of an prescriptiveACI attribute of a subentry subordinate
      * to ou=system.
@@ -524,7 +536,8 @@
         Attributes changes = new BasicAttributes( "prescriptiveACI", aciItem, true );
         adminCtx.modifyAttributes( "cn=" + cn, DirContext.REPLACE_ATTRIBUTE, changes );
     }
-    
+
+
     public static void addPrescriptiveACI( String cn, String aciItem ) throws Exception
     {
         DirContext adminCtx = getContextAsAdmin();

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=889323&r1=889322&r2=889323&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 Dec 10 16:44:41 2009
@@ -77,16 +77,15 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith ( CiRunner.class )
-@CleanupLevel ( Level.CLASS )
-@Factory ( MixedCaseITest.MyFactory.class )
+@RunWith(CiRunner.class)
+@CleanupLevel(Level.CLASS)
+@Factory(MixedCaseITest.MyFactory.class)
 public class MixedCaseITest
 {
     public static DirectoryService service;
 
     private static final String SUFFIX_DN = "dc=Apache,dc=Org";
 
-
     public static class MyFactory implements DirectoryServiceFactory
     {
         public DirectoryService newInstance() throws Exception
@@ -100,36 +99,45 @@
                 workingDirectory = path.substring( 0, targetPos + 6 ) + "/server-work";
             }
 
-            DirectoryService service = new DefaultDirectoryService();
+            service = new DefaultDirectoryService();
             service.setWorkingDirectory( new File( workingDirectory ) );
+
+            return service;
+        }
+
+
+        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
             SchemaLdifExtractor extractor = new SchemaLdifExtractor( new File( workingDirectory
) );
-            
+
             schemaPartition.setWrappedPartition( ldifPartition );
-            
+
             JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
 
             SchemaManager schemaManager = new DefaultSchemaManager( loader );
             service.setSchemaManager( schemaManager );
-            
+
             schemaManager.loadAllEnabled();
-            
+
             List<Throwable> errors = schemaManager.getErrors();
-            
+
             if ( errors.size() != 0 )
             {
                 fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
             }
-            
+
             schemaPartition.setSchemaManager( schemaManager );
-            
+
             extractor.extractOrCopy();
 
             service.getChangeLog().setEnabled( true );
@@ -137,21 +145,20 @@
             // 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 );
+            ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
             systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
             systemPartition.setSchemaManager( schemaManager );
-            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
-    
+            ( ( 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
) );
+            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();
@@ -160,18 +167,16 @@
             partition.setPartitionDir( new File( workingDirectory, "apache" ) );
 
             HashSet<Index<?, ServerEntry>> indexedAttributes = new HashSet<Index<?,
ServerEntry>>();
-            indexedAttributes.add( new JdbmIndex<String,ServerEntry>( "objectClass"
) );
-            indexedAttributes.add( new JdbmIndex<String,ServerEntry>( "ou" ) );
-            indexedAttributes.add( new JdbmIndex<String,ServerEntry>( "uid" ) );
+            indexedAttributes.add( new JdbmIndex<String, ServerEntry>( "objectClass"
) );
+            indexedAttributes.add( new JdbmIndex<String, ServerEntry>( "ou" ) );
+            indexedAttributes.add( new JdbmIndex<String, ServerEntry>( "uid" ) );
             partition.setIndexedAttributes( indexedAttributes );
 
             service.addPartition( partition );
-
-            return service;
         }
     }
 
-    
+
     @Before
     public void setUp() throws Exception
     {
@@ -181,8 +186,8 @@
         entry.add( "dc", "Apache" );
         service.getAdminSession().add( entry );
     }
-    
-    
+
+
     @Test
     public void testSearch() throws Exception
     {
@@ -207,11 +212,8 @@
 
         String dn = "ou=Test";
 
-        Attributes attributes = AttributeUtils.createAttributes( 
-            "objectClass: top",
-            "objectClass: organizationalUnit",
-            "ou: Test"
-            );
+        Attributes attributes = AttributeUtils.createAttributes( "objectClass: top", "objectClass:
organizationalUnit",
+            "ou: Test" );
 
         DirContext ctx = ctxRoot.createSubcontext( dn, attributes );
         assertNotNull( ctx );
@@ -236,12 +238,8 @@
         String dn = "ou=Test";
         String description = "New Value";
 
-        Attributes attributes = AttributeUtils.createAttributes( 
-            "objectClass: top",
-            "objectClass: organizationalUnit",
-            "ou: Test",
-            "description: Old Value"
-            );
+        Attributes attributes = AttributeUtils.createAttributes( "objectClass: top", "objectClass:
organizationalUnit",
+            "ou: Test", "description: Old Value" );
 
         DirContext ctx = ctxRoot.createSubcontext( dn, attributes );
         assertNotNull( ctx );
@@ -275,11 +273,8 @@
 
         String dn = "ou=Test";
 
-        Attributes attributes = AttributeUtils.createAttributes( 
-            "objectClass: top",
-            "objectClass: organizationalUnit",
-            "ou: Test"
-            );
+        Attributes attributes = AttributeUtils.createAttributes( "objectClass: top", "objectClass:
organizationalUnit",
+            "ou: Test" );
 
         DirContext ctx = ctxRoot.createSubcontext( dn, attributes );
         assertNotNull( ctx );

Modified: directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java?rev=889323&r1=889322&r2=889323&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-integ/src/test/java/org/apache/directory/server/core/partition/PartitionIT.java
Thu Dec 10 16:44:41 2009
@@ -61,41 +61,30 @@
 import org.slf4j.LoggerFactory;
 
 
-
 /**
  * Test cases for partition handling.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-@RunWith ( CiRunner.class )
-@Factory ( PartitionIT.Factory.class )
-@ApplyLdifs (
-    {
-        "dn: dc=foo,dc=com\n" +
-        "objectClass: top\n" +
-        "objectClass: domain\n" +
-        "dc: foo\n\n" +
-
-        "dn: dc=bar,dc=com\n" +
-        "objectClass: top\n" +
-        "objectClass: domain\n" +
-        "dc: bar\n\n"
-    }
-)
+@RunWith(CiRunner.class)
+@Factory(PartitionIT.Factory.class)
+@ApplyLdifs(
+    { "dn: dc=foo,dc=com\n" + "objectClass: top\n" + "objectClass: domain\n" + "dc: foo\n\n"
+
+
+    "dn: dc=bar,dc=com\n" + "objectClass: top\n" + "objectClass: domain\n" + "dc: bar\n\n"
})
 public final class PartitionIT
 {
     private static final Logger LOG = LoggerFactory.getLogger( PartitionIT.class );
     public static DirectoryService service;
 
-    
     /**
      * Creates a DirectoryService configured with two separate dc=com based 
      * domains to test multiple partitions.
      */
     public static class Factory implements DirectoryServiceFactory
     {
-        public DirectoryService newInstance() throws Exception 
+        public DirectoryService newInstance() throws Exception
         {
             String workingDirectory = System.getProperty( "workingDirectory" );
 
@@ -106,30 +95,39 @@
                 workingDirectory = path.substring( 0, targetPos + 6 ) + "/server-work";
             }
 
-            DirectoryService service = new DefaultDirectoryService();
+            service = new DefaultDirectoryService();
             service.setWorkingDirectory( new File( workingDirectory ) );
+
+            return service;
+        }
+
+
+        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 );
-            
+
             schemaManager.loadAllEnabled();
-            
+
             List<Throwable> errors = schemaManager.getErrors();
-            
+
             if ( errors.size() != 0 )
             {
                 fail( "Schema load failed : " + ExceptionUtils.printErrors( errors ) );
@@ -144,21 +142,20 @@
             // 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 );
+            ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
             systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
             systemPartition.setSchemaManager( schemaManager );
-            ((JdbmPartition)systemPartition).setPartitionDir( new File( workingDirectory,
"system" ) );
-    
+            ( ( 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
) );
+            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 );
             schemaPartition.setSchemaManager( schemaManager );
 
@@ -166,20 +163,18 @@
             foo.setId( "foo" );
             foo.setSuffix( "dc=foo,dc=com" );
             foo.setSchemaManager( schemaManager );
-            ((JdbmPartition)foo).setPartitionDir( new File( workingDirectory, "foo" ) );
+            ( ( JdbmPartition ) foo ).setPartitionDir( new File( workingDirectory, "foo"
) );
             service.addPartition( foo );
-            
+
             Partition bar = new JdbmPartition();
             bar.setId( "bar" );
             bar.setSuffix( "dc=bar,dc=com" );
             bar.setSchemaManager( schemaManager );
-            ((JdbmPartition)bar).setPartitionDir( new File( workingDirectory, "bar" ) );
+            ( ( JdbmPartition ) bar ).setPartitionDir( new File( workingDirectory, "bar"
) );
             service.addPartition( bar );
-            
-            return service;
         }
     }
-    
+
 
     /**
      * Test case to weed out issue in DIRSERVER-1118.
@@ -193,13 +188,13 @@
          * Confirm the presence of the partitions foo and bar through DS API
          */
         HashMap<String, Partition> partitionMap = new HashMap<String, Partition>();
-        
+
         for ( Partition partition : service.getPartitions() )
         {
             LOG.debug( "partition id = {}", partition.getId() );
             partitionMap.put( partition.getId(), partition );
         }
-        
+
         assertNotNull( partitionMap.containsKey( "foo" ) );
         assertNotNull( partitionMap.containsKey( "bar" ) );
 
@@ -208,19 +203,19 @@
          * namingContexts as values innamingContexts attribute of the rootDSE
          */
         LdapContext rootDSE = getRootContext( service );
-        Attribute namingContexts = rootDSE.getAttributes( "", 
-            new String[] { "namingContexts" } ).get( "namingContexts" );
+        Attribute namingContexts = rootDSE.getAttributes( "", new String[]
+            { "namingContexts" } ).get( "namingContexts" );
         assertTrue( namingContexts.contains( "dc=foo,dc=com" ) );
         assertTrue( namingContexts.contains( "dc=bar,dc=com" ) );
         LOG.debug( "Found both dc=foo,dc=com and dc=bar,dc=com in namingContexts" );
-        
+
         /*
          * Add, lookup, then delete entry in both foo and bar partitions
          */
         addLookupDelete( "dc=foo,dc=com" );
         addLookupDelete( "dc=bar,dc=com" );
     }
-    
+
 
     /**
      * Given the suffix DN of a partition this method will add an entry, look 
@@ -236,12 +231,12 @@
         String entryDn = "ou=people," + partitionSuffix;
         rootDSE.createSubcontext( entryDn, attrs );
         LOG.debug( "added entry {} to partition {}", entryDn, partitionSuffix );
-        
+
         Attributes reloaded = rootDSE.getAttributes( entryDn );
         assertNotNull( reloaded );
         assertTrue( reloaded.get( "ou" ).contains( "people" ) );
         LOG.debug( "looked up entry {} from partition {}", entryDn, partitionSuffix );
-        
+
         rootDSE.destroySubcontext( entryDn );
         try
         {



Mime
View raw message