directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r894986 - in /directory/apacheds/branches/apacheds-schema/test-framework/src: main/java/org/apache/directory/server/core/integ/FrameworkRunner.java test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java
Date Fri, 01 Jan 2010 09:52:34 GMT
Author: kayyagari
Date: Fri Jan  1 09:52:33 2010
New Revision: 894986

URL: http://svn.apache.org/viewvc?rev=894986&view=rev
Log:
o fixed the way LdapServer is initialized
o updated the FrameworkRunner to inject an inherited DirectoryService in LdapServer(i.e a
Class level 
  LdapServer can use its Suite's or a default DirectoryService if not declared at the Class
level)
o added a test class to test these changes

Added:
    directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java
Modified:
    directory/apacheds/branches/apacheds-schema/test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java

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=894986&r1=894985&r2=894986&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
Fri Jan  1 09:52:33 2010
@@ -95,53 +95,8 @@
             classDS = DSAnnotationProcessor.getDirectoryService( getDescription() );
             long revision = 0L;
             DirectoryService directoryService = null;
-
             
-            // check first if it is a LdapServerBuilder
-            // then use the DS in LdapServer alone
-            if( classLdapServerBuilder != null )
-            {
-                if( classDS == null )
-                {
-                    throw new IllegalStateException( "missing CreateDS annotation on class
" + getDescription().getClassName() );
-                }
-
-                directoryService = classDS;
-                // Then tag for reversion and apply the class LDIFs
-                revision = directoryService.getChangeLog().getCurrentRevision();
-                LOG.debug( "Create revision {}", revision );
-
-                DSAnnotationProcessor.applyLdifs( getDescription(), classDS );
-                int minPort = 0;
-                
-                if ( suite != null )
-                {
-                    LdapServer suiteServer = suite.getLdapServer();
-                    
-                    for ( Transport transport : suiteServer.getTransports() )
-                    {
-                        if ( minPort <= transport.getPort() )
-                        {
-                            minPort = transport.getPort();
-                        }
-                    }
-                }
-                
-                classLdapServer = ServerAnnotationProcessor.getLdapServer( getDescription(),
classDS, minPort + 1 );
-            }
-            else if( suite != null && suite.getLdapServer() != null )
-            {
-                classLdapServer = suite.getLdapServer();
-                classDS = classLdapServer.getDirectoryService();
-                
-                directoryService = classDS;
-                // Then tag for reversion and apply the class LDIFs
-                revision = directoryService.getChangeLog().getCurrentRevision();
-                LOG.debug( "Create revision {}", revision );
-
-                DSAnnotationProcessor.applyLdifs( getDescription(), classDS );
-            }
-            else if ( classDS != null )
+            if ( classDS != null )
             {
                 // We have a class DS defined, update it
                 directoryService = classDS;
@@ -206,41 +161,60 @@
                 }
             }
 
+            // check if it has a LdapServerBuilder
+            // then use the DS created above
+            if( classLdapServerBuilder != null )
+            {
+                int minPort = 0;
+                
+                if ( suite != null )
+                {
+                    LdapServer suiteServer = suite.getLdapServer();
+                    
+                    for ( Transport transport : suiteServer.getTransports() )
+                    {
+                        if ( minPort <= transport.getPort() )
+                        {
+                            minPort = transport.getPort();
+                        }
+                    }
+                }
+                
+                classLdapServer = ServerAnnotationProcessor.getLdapServer( getDescription(),
directoryService, minPort + 1 );
+            }
+            else if( suite != null && suite.getLdapServer() != null )
+            {
+                classLdapServer = suite.getLdapServer();
+                directoryService = classLdapServer.getDirectoryService();
+                // no need to inject the LDIF data that would have been done above
+                // if ApplyLdifs is present
+            }
+
             // Now run the class
             super.run( notifier );
 
-            boolean stopped = false;
-            
             if( classLdapServer != null )
             {
                 if( suite == null || suite.getLdapServer() != classLdapServer )
                 {
                     classLdapServer.stop();
-                    LOG.debug( "Shuting down DS for {}", classDS.getInstanceId() );
-                    classDS.shutdown();
-                    FileUtils.deleteDirectory( classDS.getWorkingDirectory() );
-                    stopped = true;
                 }
             }
+            
             // cleanup classService if it is not the same as suite service or
             // it is not null (this second case happens in the absence of a suite)
-            else if ( classDS != null )
+            if ( classDS != null )
             {
                 LOG.debug( "Shuting down DS for {}", classDS.getInstanceId() );
                 classDS.shutdown();
                 FileUtils.deleteDirectory( classDS.getWorkingDirectory() );
-                stopped = true;
             }
-            
-            if( !stopped )
+            else if ( revision < directoryService.getChangeLog().getCurrentRevision()
)
             {
                 // Revert the ldifs
-                if ( revision < directoryService.getChangeLog().getCurrentRevision() )
-                {
-                    LOG.debug( "Revert revision {}", revision );
-                    // We use a class or suite DS, just revert the current test's modifications
-                    directoryService.revert( revision );
-                }
+                LOG.debug( "Revert revision {}", revision );
+                // We use a class or suite DS, just revert the current test's modifications
+                directoryService.revert( revision );
             }
         }
         catch ( Exception e )
@@ -288,9 +262,11 @@
             // Check if this method has a dedicated DSBuilder
             DirectoryService methodDS = DSAnnotationProcessor.getDirectoryService( methodDescription
);
 
+            // we don't support method level LdapServer so
+            // we check for the presence of Class level LdapServer first 
             if( classLdapServer != null )
             {
-                directoryService = classDS;
+                directoryService = classLdapServer.getDirectoryService();
                 
                 revision = directoryService.getChangeLog().getCurrentRevision();
                 LOG.debug( "Create revision {}", revision );
@@ -340,41 +316,24 @@
             if( classLdapServer != null )
             {
                 field = getTestClass().getJavaClass().getField( DIRECTORY_SERVICE_FIELD_NAME
);
-                field.set( getTestClass().getJavaClass(), classDS );
+                field.set( getTestClass().getJavaClass(), classLdapServer.getDirectoryService()
);
                 
                 field = getTestClass().getJavaClass().getField( LDAP_SERVER_FIELD_NAME );
                 field.set( getTestClass().getJavaClass(), classLdapServer );
             }
-//            // Last not least, see if we have to start a server
-//            else if ( suite != null )
-//            {
-//                // If we have a LdapServer instance, feed the associated field too
-//                field = getTestClass().getJavaClass().getField( LDAP_SERVER_FIELD_NAME
);
-//                field.set( getTestClass().getJavaClass(), suite.getLdapServer() );
-//                
-//                /*
-//                CreateLdapServer ldapServerBuilder = suite.getLdapServerBuilder();
-//                
-//                DefaultLdapServerFactory ldapServerFactory = (DefaultLdapServerFactory)ldapServerBuilder.factory().newInstance();
-//                ldapServerFactory.setDirectoryService( directoryService );
-//                */
-//            }
             
 
             // Run the test
             super.runChild( method, notifier );
 
-            boolean stopped = false;
             // Cleanup the methodDS if it has been created
             if ( methodDS != null )
             {
                 LOG.debug( "Shuting down DS for {}", methodDS.getInstanceId() );
                 methodDS.shutdown();
                 FileUtils.deleteDirectory( methodDS.getWorkingDirectory() );
-                stopped = true;
             }
-            
-            if ( ( !stopped ) && ( revision < directoryService.getChangeLog().getCurrentRevision()
) )
+            else if ( ( revision < directoryService.getChangeLog().getCurrentRevision()
) )
             {
                 // We use a class or suite DS, just revert the current test's modifications
                 directoryService.revert( revision );

Added: directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java?rev=894986&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java
(added)
+++ directory/apacheds/branches/apacheds-schema/test-framework/src/test/java/org/apache/directory/server/core/integ/TestWithClassLevelLdapServer.java
Fri Jan  1 09:52:33 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.annotations.CreateTransport;
+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 )
+@CreateLdapServer ( 
+    transports = 
+    {
+        @CreateTransport( protocol = "LDAP" )
+    })
+public class TestWithClassLevelLdapServer 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"
) ) );
+            // the SuiteDS is the name given to the DS instance in the enclosing TestSuite
+            assertEquals( "SuiteDS", ldapServer.getDirectoryService().getInstanceId() );
+        }
+        else // should run with a default DS created in FrameworkRunner
+        {
+            assertTrue( ldapServer.getDirectoryService().getInstanceId().startsWith( "default"
) ); // after 'default' a UUID follows
+        }
+        
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testPerson2,ou=system"
) ) );
+        
+        assertNotNull( ldapServer );
+    }
+}



Mime
View raw message