directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r894520 - in /directory/apacheds/branches/apacheds-schema: core-annotations/src/main/java/org/apache/directory/server/core/factory/ test-framework/src/test/java/org/apache/directory/server/core/integ/
Date Wed, 30 Dec 2009 00:35:25 GMT
Author: elecharny
Date: Wed Dec 30 00:35:25 2009
New Revision: 894520

URL: http://svn.apache.org/viewvc?rev=894520&view=rev
Log:
o Aggregated DS creation in a private method
o Removed a useless method
o Created a Test to check that the Partition is correctly created and fed
o Changed the testSuiteServer to call only the test which involves a LdapServer
 

Added:
    directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassServer.java
Modified:
    directory/apacheds/branches/apacheds-schema/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java

Modified: directory/apacheds/branches/apacheds-schema/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=894520&r1=894519&r2=894520&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
Wed Dec 30 00:35:25 2009
@@ -54,89 +54,12 @@
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( DSAnnotationProcessor.class
);
 
-    /**
-     * Create a DirectoryService from a Unit test annotation
-     *
-     * @param description The annotations containing the info from which we will create the
DS
-     * @return A valid DS
-     */
-    public static DirectoryService getDirectoryService( Description description )
-    {
-        try
-        {
-            CreateDS dsBuilder = description.getAnnotation( CreateDS.class );
-            
-            if ( dsBuilder != null )
-            {
-                LOG.debug( "Starting DS {}...", dsBuilder.name() );
-                Class<?> factory = dsBuilder.factory();
-                DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) factory.newInstance();
-                
-                DirectoryService service = dsf.getDirectoryService();
-                service.setAccessControlEnabled( dsBuilder.enableAccessControl() );
-                service.setAllowAnonymousAccess( dsBuilder.allowAnonAccess() );
-                
-                dsf.init( dsBuilder.name() );
-                
-                return service;
-            }
-            else
-            {
-                LOG.debug( "No {} DS.", description.getDisplayName() );
-                return null;
-            }
-        }
-        catch ( Exception e )
-        {
-            return null;
-        }
-    }
-    
     
     /**
-     * Create a DirectoryService from an annotation. The @CreateDS annotation must
-     * be associated with either the method or the encapsulating class. We will first
-     * try to get the annotation from the method, and if there is none, then we try
-     * at the class level. 
-     *
-     * @return A valid DS
+     * Create the DirectoryService
      */
-    public static DirectoryService getDirectoryService() throws Exception
+    private static DirectoryService createDS( CreateDS dsBuilder )
     {
-        CreateDS dsBuilder = null;
-        
-        // Get the caller by inspecting the stackTrace
-        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
-        
-        // Get the enclosing class
-        Class<?> classCaller = Class.forName( stackTrace[2].getClassName() );
-        
-        // Get the current method
-        String methodCaller = stackTrace[2].getMethodName();
-        
-        // Check if we have any annotation associated with the method
-        Method[] methods = classCaller.getMethods();
-        
-        for ( Method method : methods )
-        {
-            if ( methodCaller.equals( method.getName() ) )
-            {
-                dsBuilder = method.getAnnotation( CreateDS.class );
-                
-                if ( dsBuilder != null )
-                {
-                    break;
-                }
-            }
-        }
-
-        // No : look at the class level
-        if ( dsBuilder == null )
-        {
-            dsBuilder = classCaller.getAnnotation( CreateDS.class );
-        }
-        
-        // Ok, we have found a CreateDS annotation. Process it now.
         try
         {
             LOG.debug( "Starting DS {}...", dsBuilder.name() );
@@ -196,32 +119,24 @@
     
     
     /**
-     * Create a DirectoryService using the class annotation
-     * TODO getClassDirectoryService.
+     * Create a DirectoryService from a Unit test annotation
      *
-     * @param clazz
-     * @return
+     * @param description The annotations containing the info from which we will create the
DS
+     * @return A valid DS
      */
-    public static DirectoryService getClassDirectoryService( Class<?> clazz )
+    public static DirectoryService getDirectoryService( Description description )
     {
         try
         {
-            CreateDS dsBuilder = clazz.getAnnotation( CreateDS.class );
+            CreateDS dsBuilder = description.getAnnotation( CreateDS.class );
             
             if ( dsBuilder != null )
             {
-                LOG.debug( "Starting the {} DS...", clazz.getName() );
-                Class<?> factory = dsBuilder.factory();
-                DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) factory.newInstance();
-                dsf.init( dsBuilder.name() );
-                
-                DirectoryService service = dsf.getDirectoryService();
-                
-                return service;
+                return createDS( dsBuilder );
             }
             else
             {
-                LOG.debug( "No {} DS.", clazz.getName() );
+                LOG.debug( "No {} DS.", description.getDisplayName() );
                 return null;
             }
         }
@@ -230,6 +145,54 @@
             return null;
         }
     }
+    
+    
+    /**
+     * Create a DirectoryService from an annotation. The @CreateDS annotation must
+     * be associated with either the method or the encapsulating class. We will first
+     * try to get the annotation from the method, and if there is none, then we try
+     * at the class level. 
+     *
+     * @return A valid DS
+     */
+    public static DirectoryService getDirectoryService() throws Exception
+    {
+        CreateDS dsBuilder = null;
+        
+        // Get the caller by inspecting the stackTrace
+        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+        
+        // Get the enclosing class
+        Class<?> classCaller = Class.forName( stackTrace[2].getClassName() );
+        
+        // Get the current method
+        String methodCaller = stackTrace[2].getMethodName();
+        
+        // Check if we have any annotation associated with the method
+        Method[] methods = classCaller.getMethods();
+        
+        for ( Method method : methods )
+        {
+            if ( methodCaller.equals( method.getName() ) )
+            {
+                dsBuilder = method.getAnnotation( CreateDS.class );
+                
+                if ( dsBuilder != null )
+                {
+                    break;
+                }
+            }
+        }
+
+        // No : look at the class level
+        if ( dsBuilder == null )
+        {
+            dsBuilder = classCaller.getAnnotation( CreateDS.class );
+        }
+        
+        // Ok, we have found a CreateDS annotation. Process it now.
+        return createDS( dsBuilder );
+    }
 
     
     /**
@@ -344,5 +307,4 @@
             }
         }
     }
-
 }

Added: directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassServer.java?rev=894520&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassServer.java
(added)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassServer.java
Wed Dec 30 00:35:25 2009
@@ -0,0 +1,44 @@
+/*
+ * 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.assertTrue;
+
+import org.apache.directory.server.core.annotations.ApplyLdifFiles;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( FrameworkRunner.class )
+public class TestClassServer extends AbstractLdapTestUnit
+{
+    @Test
+    @ApplyLdifFiles( "test-entry.ldif" )
+    public void testWithApplyLdifFiles() throws Exception
+    {
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testPerson1,ou=system"
) ) );
+        
+        if ( isRunInSuite )
+        {
+            assertTrue( service.getAdminSession().exists( new LdapDN( "dc=example,dc=com"
) ) );
+        }
+        
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testPerson2,ou=system"
) ) );
+    }
+}

Modified: directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java?rev=894520&r1=894519&r2=894520&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestSuiteServer.java
Wed Dec 30 00:35:25 2009
@@ -29,7 +29,7 @@
 import org.junit.runners.Suite;
 
 @RunWith( FrameworkSuite.class )
-@Suite.SuiteClasses( { TestClassA.class, TestClassB.class, TestClassC.class } )
+@Suite.SuiteClasses( { TestClassServer.class } )
 @CreateDS( 
     name = "SuiteDS",
     partitions =



Mime
View raw message