directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r892458 - in /directory/sandbox/kayyagari/integ-test-framework: ./ src/test/java/org/apache/directory/server/core/integ/
Date Sat, 19 Dec 2009 11:08:03 GMT
Author: kayyagari
Date: Sat Dec 19 11:08:02 2009
New Revision: 892458

URL: http://svn.apache.org/viewvc?rev=892458&view=rev
Log:
o renamed Factory to TestLevelFactory
o injected the DirecoryService attribute in test classes and modified Factory annotation
o copied ApplyLdifs and DirServiceFactory classes from core-integ
o added some more dependencies in pom and bumped the version to 1.5.6-SNAPSHOT

Added:
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/ApplyLdifs.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkDirectoryServiceFactory.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestLevelFactory.java
Removed:
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/Factory.java
Modified:
    directory/sandbox/kayyagari/integ-test-framework/pom.xml
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkRunner.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkSuite.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassA.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuite.java

Modified: directory/sandbox/kayyagari/integ-test-framework/pom.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/pom.xml?rev=892458&r1=892457&r2=892458&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/pom.xml (original)
+++ directory/sandbox/kayyagari/integ-test-framework/pom.xml Sat Dec 19 11:08:02 2009
@@ -1,10 +1,15 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
+    <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-parent</artifactId>
+    <version>1.5.6-SNAPSHOT</version>
+  </parent>
   <groupId>org.apache.directory.server.core.integ</groupId>
   <artifactId>integ-test-framework</artifactId>
   <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
+  <version>1.5.6-SNAPSHOT</version>
   <name>integ-test-framework</name>
   <description>an experimental test framework for integration tests without depending
on the InheritableSettings</description>
   <dependencies>
@@ -14,5 +19,42 @@
       <version>4.7</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-core-jndi</artifactId>
+      <version>${pom.version}</version>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-jdbm-partition</artifactId>
+      <version>${pom.version}</version>
+      <!--scope>test</scope-->
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-avl-partition</artifactId>
+      <version>${pom.version}</version>
+    </dependency>  
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-ldif-partition</artifactId>
+      <version>${pom.version}</version>
+    </dependency>  
+
+
+    <dependency>
+      <groupId>org.apache.directory.server</groupId>
+      <artifactId>apacheds-avl-partition</artifactId>
+      <version>${pom.version}</version>
+    </dependency>  
+
   </dependencies>
 </project>

Added: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/ApplyLdifs.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/ApplyLdifs.java?rev=892458&view=auto
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/ApplyLdifs.java
(added)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/ApplyLdifs.java
Sat Dec 19 11:08:02 2009
@@ -0,0 +1,46 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.directory.server.core.integ;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+
+
+/**
+ * A annotation used to specify an sequence of LDIF's to be applied to
+ * the instance for integration testing.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+@Documented
+@Inherited
+@Retention ( RetentionPolicy.RUNTIME )
+@Target ( { ElementType.METHOD, ElementType.TYPE } )
+public @interface ApplyLdifs
+{
+     String[] value();
+}

Added: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java?rev=892458&view=auto
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
(added)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/DirectoryServiceFactory.java
Sat Dec 19 11:08:02 2009
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.integ;
+
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+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.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.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;
+
+
+/**
+ * A factory used to generate differently configured DirectoryService objects.
+ * Since the DirectoryService itself is what is configured then a factory for
+ * these objects acts as a configurator.  Tests can provide different factory
+ * methods to be used.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface DirectoryServiceFactory
+{
+    /**
+     * The default factory returns stock instances of a directory
+     * service with smart defaults
+     */
+    DirectoryServiceFactory DEFAULT = new DirectoryServiceFactory()
+    {
+        private DirectoryService service;
+
+
+        public DirectoryService newInstance() throws Exception
+        {
+            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";
+            }
+
+            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 ) );
+            }
+
+            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 );
+        }
+    };
+
+
+    void init() throws Exception;
+
+
+    DirectoryService newInstance() throws Exception;
+}

Added: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkDirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkDirectoryServiceFactory.java?rev=892458&view=auto
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkDirectoryServiceFactory.java
(added)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkDirectoryServiceFactory.java
Sat Dec 19 11:08:02 2009
@@ -0,0 +1,108 @@
+package org.apache.directory.server.core.integ;
+
+
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+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.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.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;
+
+
+public class FrameworkDirectoryServiceFactory implements DirectoryServiceFactory
+{
+    private DirectoryService service;
+
+
+    public DirectoryService newInstance() throws Exception
+    {
+        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";
+        }
+
+        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();
+
+        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 );
+        service.setAccessControlEnabled( false );
+    }
+}

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=892458&r1=892457&r2=892458&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
Sat Dec 19 11:08:02 2009
@@ -20,7 +20,14 @@
 
 
 import java.lang.reflect.Field;
+import java.util.List;
 
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.junit.Ignore;
 import org.junit.runner.Description;
 import org.junit.runner.notification.RunNotifier;
@@ -35,9 +42,9 @@
  */
 public class FrameworkRunner extends BlockJUnit4ClassRunner
 {
+    private static final String DIRECTORYSERVICE_FIELD_NAME = "service";
     private FrameworkSuite suite;
 
-
     public FrameworkRunner( Class<?> clazz ) throws InitializationError
     {
         super( clazz );
@@ -47,24 +54,39 @@
     @Override
     public void run( final RunNotifier notifier )
     {
-        Factory fac = getDescription().getAnnotation( Factory.class );
+        TestLevelFactory fac = getDescription().getAnnotation( TestLevelFactory.class );
         try
         {
-            Field field = getTestClass().getJavaClass().getDeclaredField( "factoryLabel"
);
-            
-            Object oldVal = field.get( getTestClass().getJavaClass() );
+            Field field = getTestClass().getJavaClass().getDeclaredField( DIRECTORYSERVICE_FIELD_NAME
);
             
+            Object val = null;
             if ( fac != null )
             {
-                field.set( getTestClass().getJavaClass(), fac.value() );
+                val = fac.value().newInstance();
+                val = ( ( DirectoryServiceFactory ) val ).newInstance();
             }
             else // set the parent suit's factory value
             {
-                Factory suitFactory = getSuite().getDescription().getAnnotation( Factory.class
);
+                TestLevelFactory suitFactory = getSuite().getDescription().getAnnotation(
TestLevelFactory.class );
+                
+                if( suitFactory == null )
+                {
+                    // instantiate a default factory
+                    val = DirectoryServiceFactory.DEFAULT;
+                }
+                else
+                {
+                    val = suitFactory.value().newInstance();
+                }
                 
-                field.set( getTestClass().getJavaClass(), suitFactory.value() );
+                val = ( ( DirectoryServiceFactory ) val ).newInstance();
+                applyLdifs( getSuite().getDescription(), ( DirectoryService ) val );
             }
             
+            field.set( getTestClass().getJavaClass(), val );
+            
+            applyLdifs( getDescription(), ( DirectoryService ) val );
+            
             super.run( notifier );
         }
         catch ( Exception e )
@@ -86,21 +108,26 @@
 
         try
         {
-            Field field = getTestClass().getJavaClass().getDeclaredField( "factoryLabel"
);
+            Field field = getTestClass().getJavaClass().getDeclaredField( DIRECTORYSERVICE_FIELD_NAME
);
 
-            Object oldVal = field.get( getTestClass().getJavaClass() );
+            Object parentDirServiceObj = field.get( getTestClass().getJavaClass() );
 
-            Factory fac = description.getAnnotation( Factory.class );
+            TestLevelFactory fac = description.getAnnotation( TestLevelFactory.class );
 
+            Object  childDirServiceObj = null; 
             if ( fac != null )
             {
-                field.set( getTestClass().getJavaClass(), fac.value() );
+                childDirServiceObj = ( ( DirectoryServiceFactory ) fac.value().newInstance()
).newInstance();
+                field.set( getTestClass().getJavaClass(), childDirServiceObj );
             }
 
+            // TODO only applying is present, revert should be added
+            applyLdifs( description, ( ( DirectoryService ) ( childDirServiceObj == null
? parentDirServiceObj : childDirServiceObj ) ) );
+            
             super.runChild( method, notifier );
 
             // reset the parent's value
-            field.set( getTestClass().getJavaClass(), oldVal );
+            field.set( getTestClass().getJavaClass(), parentDirServiceObj );
         }
         catch ( Exception e )
         {
@@ -112,7 +139,6 @@
 
     public void setSuite( FrameworkSuite suite )
     {
-        System.out.println( "setting the suite" );
         this.suite = suite;
     }
 
@@ -121,4 +147,59 @@
     {
         return suite;
     }
+    
+
+    private void applyLdifs( Description description, DirectoryService service ) throws Exception
+    {
+        ApplyLdifs annotation = description.getAnnotation( ApplyLdifs.class );
+        
+        if ( ( annotation != null ) && ( annotation.value() != null ) )
+        {
+            String[] ldifs = annotation.value();
+            for( String s : ldifs )
+            {
+                injectEntries( service, s );
+            }
+        }
+    }
+    
+    
+    // copied from IntegrationUtils
+    /**
+     * Inject an ldif String into the server. DN must be relative to the
+     * root.
+     *
+     * @param service the directory service to use 
+     * @param ldif the ldif containing entries to add to the server.
+     * @throws NamingException if there is a problem adding the entries from the LDIF
+     */
+    public static void injectEntries( DirectoryService service, String ldif ) throws Exception
+    {
+        LdifReader reader = new LdifReader();
+        List<LdifEntry> entries = reader.parseLdif( ldif );
+
+        for ( LdifEntry entry : entries )
+        {
+            if ( entry.isChangeAdd() )
+            {
+                service.getAdminSession().add( 
+                    new DefaultServerEntry( service.getSchemaManager(), entry.getEntry()
) );
+            }
+            else if ( entry.isChangeModify() )
+            {
+                service.getAdminSession().modify( 
+                    entry.getDn(), entry.getModificationItems() );
+            }
+            else
+            {
+                String message = "Unsupported changetype found in LDIF: " + 
+                    entry.getChangeType();
+                throw new NamingException( message );
+            }
+        }
+        
+        // And close the reader
+        reader.close();
+    }
+
 }

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkSuite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkSuite.java?rev=892458&r1=892457&r2=892458&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkSuite.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/FrameworkSuite.java
Sat Dec 19 11:08:02 2009
@@ -42,25 +42,9 @@
     @Override
     protected void runChild( Runner runner, RunNotifier notifier )
     {
+        System.out.println( runner );
         ( ( FrameworkRunner ) runner ).setSuite( this );
         super.runChild( runner, notifier );
     }
 
-
-    @Override
-    public void run( final RunNotifier notifier )
-    {
-        Factory fac = getDescription().getAnnotation( Factory.class );
-        if ( fac != null )
-        {
-            System.out.println( fac.value() );
-        }
-        else
-        {
-            System.out.println( "no annotation found" );
-        }
-
-        super.run( notifier );
-    }
-
 }

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassA.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassA.java?rev=892458&r1=892457&r2=892458&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassA.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassA.java
Sat Dec 19 11:08:02 2009
@@ -1,31 +1,41 @@
 package org.apache.directory.server.core.integ;
 
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-@RunWith( FrameworkRunner.class )
-@Factory( "ClassAFactory" )
+
+@RunWith(FrameworkRunner.class)
+@TestLevelFactory(FrameworkDirectoryServiceFactory.class)
+@ApplyLdifs(
+    {
+    "dn: cn=testClassA,ou=system\n" + "objectClass: person\n" + "cn: testClassA\n" + "sn:
sn_testClassA\n" })
 public class TestClassA
 {
 
-    public static String factoryLabel;
-    
+    public static DirectoryService service;
+
+
     @Test
-    @Factory( "ClassATestFactory" )
-    public void testWithFactoryAnnotation()
+    @TestLevelFactory(FrameworkDirectoryServiceFactory.class)
+    @ApplyLdifs(
+        {
+        "dn: cn=testMethodA,ou=system\n" + "objectClass: person\n" + "cn: testMethodA\n"
+ "sn: sn_testMethodA\n" })
+    public void testWithFactoryAnnotation() throws Exception
     {
-        assertEquals( "ClassATestFactory", factoryLabel );
-        System.out.println( "factoryLabel = " + factoryLabel );
+        assertNull( service.getAdminSession().lookup( new LdapDN( "cn=testClassA,ou=system"
) ) );
+        assertNotNull( service.getAdminSession().lookup( new LdapDN( "cn=testMethodA,ou=system"
) ) );
     }
-    
-    
+
+
     @Test
-    public void testWithoutFactoryAnnotation()
+    public void testWithoutFactoryAnnotation() throws Exception
     {
-        assertEquals( "ClassAFactory", factoryLabel );
-        System.out.println( "factoryLabel = " + factoryLabel );
+        assertNotNull( service.getAdminSession().lookup( new LdapDN( "cn=testClassA,ou=system"
) ) );
     }
 }

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java?rev=892458&r1=892457&r2=892458&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
Sat Dec 19 11:08:02 2009
@@ -1,8 +1,11 @@
 package org.apache.directory.server.core.integ;
 
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -10,23 +13,19 @@
 public class TestClassB
 {
 
-    public static String factoryLabel;
+    public static DirectoryService service;
     
     @Test
-    @Factory( "ClassBTestFactory" )
-    public void testWithFactoryAnnotation()
+    @TestLevelFactory( FrameworkDirectoryServiceFactory.class )
+    public void testWithFactoryAnnotation() throws Exception
     {
-        assertEquals( "ClassBTestFactory", factoryLabel );
-        System.out.println( "factoryLabel = " + factoryLabel );
+        assertNull( service.getAdminSession().lookup( new LdapDN( "cn=testSuite,ou=system"
) ) );
     }
     
     
     @Test
-    public void testWithoutFactoryAnnotation()
+    public void testWithoutFactoryAnnotation() throws Exception
     {
-        // FIXME this gives a null factoryLabel cause of the bug in FrameworkRunner
-        // in accessing the suite class's annotation
-        assertEquals( "SuiteFactory", factoryLabel );
-        System.out.println( "factoryLabel = " + factoryLabel );
+        assertNotNull( service.getAdminSession().lookup( new LdapDN( "cn=testSuite,ou=system"
) ) );
     }
 }

Added: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestLevelFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestLevelFactory.java?rev=892458&view=auto
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestLevelFactory.java
(added)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestLevelFactory.java
Sat Dec 19 11:08:02 2009
@@ -0,0 +1,14 @@
+
+package org.apache.directory.server.core.integ;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( {ElementType.METHOD, ElementType.TYPE } )
+public @interface TestLevelFactory
+{
+    Class value();
+}

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuite.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuite.java?rev=892458&r1=892457&r2=892458&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuite.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuite.java
Sat Dec 19 11:08:02 2009
@@ -5,7 +5,10 @@
 
 @RunWith( FrameworkSuite.class )
 @Suite.SuiteClasses({ TestClassA.class, TestClassB.class })
-@Factory( "SuiteFactory" )
+@TestLevelFactory(FrameworkDirectoryServiceFactory.class)
+@ApplyLdifs(
+    {
+    "dn: cn=testSuite,ou=system\n" + "objectClass: person\n" + "cn: testSuite\n" + "sn: sn_testSuite\n"
})
 public class TestSuite
 {
 }



Mime
View raw message