directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r893791 - in /directory/apacheds/branches/apacheds-schema/test-framework/src: main/java/org/apache/directory/server/core/integ/ test/java/org/apache/directory/server/core/integ/ test/resources/
Date Thu, 24 Dec 2009 17:39:16 GMT
Author: kayyagari
Date: Thu Dec 24 17:39:15 2009
New Revision: 893791

URL: http://svn.apache.org/viewvc?rev=893791&view=rev
Log:
o added support for applying LDIF files' entries
o added a test LDIF file
o copied the AppliedLdifFiles annotation class from core-integ project

Added:
    directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/ApplyLdifFiles.java
    directory/apacheds/branches/apacheds-schema/test-framework/src/test/resources/test-entry.ldif
Modified:
    directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
    directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java

Added: directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/ApplyLdifFiles.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/ApplyLdifFiles.java?rev=893791&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/ApplyLdifFiles.java
(added)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/ApplyLdifFiles.java
Thu Dec 24 17:39:15 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 array of ldif files to load and apply
+ * on the instance used 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 ApplyLdifFiles
+{
+     String[] value();
+}

Modified: directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java?rev=893791&r1=893790&r2=893791&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
(original)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Thu Dec 24 17:39:15 2009
@@ -19,7 +19,10 @@
 package org.apache.directory.server.core.integ;
 
 
+import java.io.File;
 import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URL;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -163,15 +166,15 @@
         }
 
         // Get the applyLdifs for each level
-        ApplyLdifs suiteLdifs = null;
+        Description suiteDescription = null;
         
         if ( suite != null )
         {
-            suiteLdifs = suite.getSuiteLdifs();
+            suiteDescription = suite.getDescription();
         }
         
-        ApplyLdifs classLdifs = getDescription().getAnnotation( ApplyLdifs.class );
-        ApplyLdifs methodLdifs = method.getAnnotation( ApplyLdifs.class );
+        Description classDescription = getDescription();
+        Description methodDescription = describeChild( method );
 
         // Ok, ready to run the test
         try
@@ -190,9 +193,9 @@
                 methodDS = service;
 
                 // Apply all the LDIFs
-                applyLdifs( suiteLdifs, service );
-                applyLdifs( classLdifs, service );
-                applyLdifs( methodLdifs, service );
+                applyLdifs( suiteDescription, service );
+                applyLdifs( classDescription, service );
+                applyLdifs( methodDescription, service );
             }
             else if ( classDSBuilder != null )
             {
@@ -206,7 +209,7 @@
 
                     // Only apply the method LDIF, the class and suite(if present) LDIFs
have
                     // already been applied
-                    applyLdifs( methodLdifs, service );
+                    applyLdifs( methodDescription, service );
                 }
                 else
                 {
@@ -215,13 +218,13 @@
                     service = classService;
 
                     // Apply all the LDIFs
-                    applyLdifs( suiteLdifs, service );
-                    applyLdifs( classLdifs, service );
+                    applyLdifs( suiteDescription, service );
+                    applyLdifs( classDescription, service );
 
                     // get the current revision, we need it to revert the modifications
                     revision = service.getChangeLog().getCurrentRevision();
                  
-                    applyLdifs( methodLdifs, service );
+                    applyLdifs( methodDescription, service );
                 }
             }
             else if ( ( suite != null ) && ( suite.getSuiteDSBuilder() != null )
)
@@ -238,11 +241,11 @@
                     // LDIFs haven't been applied yet
                     if ( !classStarted )
                     {
-                        applyLdifs( classLdifs, service );
+                        applyLdifs( classDescription, service );
                     }
 
                     // And also apply the method's LDIFs
-                    applyLdifs( methodLdifs, service );
+                    applyLdifs( methodDescription, service );
                 }
                 else if ( suite.getSuiteDSBuilder() != null ) 
                 {
@@ -252,14 +255,14 @@
 
                     // apply the suite LDIFs first, these will never be reverted
                     // during the running time of a test suite
-                    applyLdifs( suiteLdifs, service );
+                    applyLdifs( suiteDescription, service );
 
                     // get the current revision, we need it to revert the modifications
                     revision = service.getChangeLog().getCurrentRevision();
 
                     // Apply all the other LDIFs
-                    applyLdifs( classLdifs, service );
-                    applyLdifs( methodLdifs, service );
+                    applyLdifs( classDescription, service );
+                    applyLdifs( methodDescription, service );
                 }
             }
             else if ( ( suite != null ) && ( suite.getSuiteService() == null ) )
@@ -272,15 +275,15 @@
                 // same as in above else-if condition 
                 // apply the suite LDIFs first, these will never be reverted
                 // during the running time of a test suite
-                applyLdifs( suiteLdifs, service );
+                applyLdifs( suiteDescription, service );
 
                 suite.setSuiteService( service );
                 // get the current revision, we need it to revert the modifications
                 revision = service.getChangeLog().getCurrentRevision();
 
                 // Apply all the other LDIFs
-                applyLdifs( classLdifs, service );
-                applyLdifs( methodLdifs, service );
+                applyLdifs( classDescription, service );
+                applyLdifs( methodDescription, service );
             }
             // FIXME the below else if is kind of supication as
             // the above else if ( classDSBuilder != null ) condition
@@ -294,12 +297,12 @@
                 
                 // apply only class LDIFs, no need to apply suite LDIFs casue if this block
is executing
                 // means there is no suite associated with the class
-                applyLdifs( classLdifs, service );
+                applyLdifs( classDescription, service );
 
                 // get the current revision, we need it to revert the modifications
                 revision = service.getChangeLog().getCurrentRevision();
 
-                applyLdifs( methodLdifs, service );
+                applyLdifs( methodDescription, service );
             }
             else if ( classService != null )
             {
@@ -307,7 +310,7 @@
                 // get the current revision, we need it to revert the modifications
                 revision = service.getChangeLog().getCurrentRevision();
 
-                applyLdifs( methodLdifs, service );
+                applyLdifs( methodDescription, service );
             }
 
             // At this point, we know which service to use.
@@ -360,8 +363,22 @@
     /**
      * Apply the LDIF entries to the given service
      */
-    private void applyLdifs( ApplyLdifs applyLdifs, DirectoryService service ) throws Exception
+    private void applyLdifs( Description desc, DirectoryService service ) throws Exception
     {
+        if( desc == null )
+        {
+            return;
+        }
+        
+        ApplyLdifFiles applyLdifFiles = desc.getAnnotation( ApplyLdifFiles.class );
+
+        if( applyLdifFiles != null )
+        {
+            injectLdifFiles( service, applyLdifFiles.value() );
+        }
+        
+        ApplyLdifs applyLdifs = desc.getAnnotation( ApplyLdifs.class ); 
+        
         if ( ( applyLdifs != null ) && ( applyLdifs.value() != null ) )
         {
             String[] ldifs = applyLdifs.value();
@@ -373,7 +390,41 @@
         }
     }
 
+    /**
+     * injects the LDIF entries present in a LDIF file
+     * 
+     * @param service the DirectoryService 
+     * @param ldifFiles the array of LDIF file names (only )
+     * @throws Exception
+     */
+    public void injectLdifFiles( DirectoryService service, String[] ldifFiles ) throws Exception
+    {
+        if ( ldifFiles != null && ldifFiles.length > 0 )
+        {
+            for ( String ldifFile : ldifFiles )
+            {
+                try
+                {
+                    Class<?> klaz = getTestClass().getJavaClass();
 
+                    LdifReader ldifReader = new LdifReader( klaz.getClassLoader().getResourceAsStream(
ldifFile ) ); 
+    
+                    for ( LdifEntry entry : ldifReader )
+                    {
+                        injectEntry( entry, service );
+                    }
+                    
+                    ldifReader.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( "Cannot inject the following entry : {}. Error : {}.", ldifFile,
e.getMessage() );
+                }
+            }
+        }
+    }
+    
+    
     /**
      * Inject an ldif String into the server. DN must be relative to the
      * root.
@@ -382,30 +433,42 @@
      * @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
+    public 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 );
-            }
+            injectEntry( entry, service );
         }
 
         // And close the reader
         reader.close();
     }
 
+    
+    /**
+     * injects an LDIF entry in the given DirectoryService
+     * 
+     * @param entry the LdifEntry to be injected
+     * @param service the DirectoryService
+     * @throws Exception
+     */
+    private void injectEntry( LdifEntry entry, DirectoryService service ) throws Exception
+    {
+        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 );
+        }
+    }
 }

Modified: directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java?rev=893791&r1=893790&r2=893791&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
(original)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
Thu Dec 24 17:39:15 2009
@@ -51,4 +51,12 @@
         assertFalse( service.getAdminSession().exists( new LdapDN( "cn=testClassB,ou=system"
) ) );
     }
     
+    
+    @Test
+    @ApplyLdifFiles( "test-entry.ldif" )
+    public void testWithApplyLdifFiles() throws Exception
+    {
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testPerson1,ou=system"
) ) );
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testPerson2,ou=system"
) ) );
+    }
 }

Added: directory/apacheds/branches/apacheds-schema/test-framework/src/test/resources/test-entry.ldif
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/test/resources/test-entry.ldif?rev=893791&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/test/resources/test-entry.ldif
(added)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/test/resources/test-entry.ldif
Thu Dec 24 17:39:15 2009
@@ -0,0 +1,9 @@
+dn: cn=testPerson1,ou=system 
+objectClass: person 
+cn: testPerson1 
+sn: sn_testPerson1
+
+dn: cn=testPerson2,ou=system 
+objectClass: person 
+cn: testPerson2 
+sn: sn_testPerson2



Mime
View raw message