directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r893463 - in /directory/sandbox/kayyagari/integ-test-framework/src: main/java/org/apache/directory/server/core/integ/ test/java/org/apache/directory/server/core/integ/
Date Wed, 23 Dec 2009 10:36:01 GMT
Author: kayyagari
Date: Wed Dec 23 10:36:00 2009
New Revision: 893463

URL: http://svn.apache.org/viewvc?rev=893463&view=rev
Log:
o added support for reverting the DS state after running tests based on the levels(Suite,Class).
  For method level DS reverting is not required
o added test cases to verify the revert operation
o removed ugly casting in FrameworkRunner

Modified:
    directory/sandbox/kayyagari/integ-test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.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/TestClassC.java

Modified: directory/sandbox/kayyagari/integ-test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java?rev=893463&r1=893462&r2=893463&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/main/java/org/apache/directory/server/core/integ/FrameworkRunner.java
Wed Dec 23 10:36:00 2009
@@ -70,63 +70,68 @@
         {
             Field field = getTestClass().getJavaClass().getDeclaredField( DIRECTORYSERVICE_FIELD_NAME
);
 
-            Object val = null;
+            DirectoryService dirService = null;
             if ( fac != null )
             {
                 DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) fac.value().newInstance();
-                val = dsf.newInstance();
+                dirService = dsf.newInstance();
                 dsf.init();
                 
                 if ( getSuite() != null )
                 {
-                    applyLdifs( getSuite().getDescription(), ( DirectoryService ) val );
+                    applyLdifs( getSuite().getDescription(), dirService );
                 }
                 
             }
             else if( getSuite() == null ) // for a class without a @Factory and running standalone
without a suite
             {
                 DirectoryServiceFactory dsf = DirectoryServiceFactory.DEFAULT;
-                val = dsf.newInstance();
+                dirService = dsf.newInstance();
                 dsf.init();
             }
             else if( suiteDirectoryService == null ) // set the parent suit's factory value
             {
                 TestLevelFactory suitFactory = getSuite().getDescription().getAnnotation(
TestLevelFactory.class );
                 
+                DirectoryServiceFactory dsf;
                 if ( suitFactory == null )
                 {
                     // instantiate a default factory
-                    val = DirectoryServiceFactory.DEFAULT;
+                    dsf = DirectoryServiceFactory.DEFAULT;
                 }
                 else
                 {
-                    val = suitFactory.value().newInstance();
+                    dsf = ( DirectoryServiceFactory ) suitFactory.value().newInstance();
                 }
 
-                DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) val;
                 suiteDirectoryService = dsf.newInstance();
-                val = suiteDirectoryService;
+                dirService = suiteDirectoryService;
                 
                 dsf.init();
                 applyLdifs( getSuite().getDescription(), suiteDirectoryService );
             }
             else
             {
-                val = suiteDirectoryService;
+                dirService = suiteDirectoryService;
             }
 
-            applyLdifs( getDescription(), ( DirectoryService ) val );
+            long revision = dirService.getChangeLog().getCurrentRevision();
             
-            field.set( getTestClass().getJavaClass(), val );
+            applyLdifs( getDescription(), dirService );
+            
+            field.set( getTestClass().getJavaClass(), dirService );
 
             super.run( notifier );
             
             // clean the DS ONLY if it is class level DS
-            if( val != suiteDirectoryService )
+            if( dirService != suiteDirectoryService )
+            {
+                dirService.shutdown();
+                FileUtils.deleteDirectory( dirService.getWorkingDirectory() );
+            }
+            else if( suiteDirectoryService != null )
             {
-                DirectoryService ds = ( DirectoryService ) val;
-                ds.shutdown();
-                FileUtils.deleteDirectory( ds.getWorkingDirectory() );
+                suiteDirectoryService.revert( revision );
             }
             
             if( suiteDirectoryService != null ) // not null means there is a suite associated
@@ -169,34 +174,40 @@
         {
             Field field = getTestClass().getJavaClass().getDeclaredField( DIRECTORYSERVICE_FIELD_NAME
);
 
-            Object parentDirServiceObj = field.get( getTestClass().getJavaClass() );
+            DirectoryService classDirService = ( DirectoryService ) field.get( getTestClass().getJavaClass()
);
 
+            long revision = classDirService.getChangeLog().getCurrentRevision();
+            
             TestLevelFactory fac = description.getAnnotation( TestLevelFactory.class );
 
-            Object childDirServiceObj = null;
+            DirectoryService methodDirService = null;
             if ( fac != null )
             {
                 DirectoryServiceFactory dsf = ( DirectoryServiceFactory ) fac.value().newInstance();
-                childDirServiceObj = dsf.newInstance();
+                methodDirService = dsf.newInstance();
 
-                DirectoryService service = ( DirectoryService ) childDirServiceObj;
-                
                 dsf.init();
-                // TODO only applying is present, revert should be added
-                applyLdifs( description, service );
-                field.set( getTestClass().getJavaClass(), childDirServiceObj );
+                applyLdifs( description, methodDirService );
+                field.set( getTestClass().getJavaClass(), methodDirService );
             }
-
+            else
+            {
+                applyLdifs( description, classDirService );
+            }
+            
             super.runChild( method, notifier );
 
             // reset the parent's value
-            field.set( getTestClass().getJavaClass(), parentDirServiceObj );
+            field.set( getTestClass().getJavaClass(), classDirService );
             
-            if( childDirServiceObj != null )
+            if( methodDirService != null )
+            {
+                methodDirService.shutdown();
+                FileUtils.deleteDirectory( methodDirService.getWorkingDirectory() );
+            }
+            else
             {
-                DirectoryService ds = ( DirectoryService ) childDirServiceObj;
-                ds.shutdown();
-                FileUtils.deleteDirectory( ds.getWorkingDirectory() );
+                classDirService.revert( revision );
             }
         }
         catch ( Exception e )

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=893463&r1=893462&r2=893463&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
Wed Dec 23 10:36:00 2009
@@ -42,9 +42,17 @@
 
 
     @Test
+    @ApplyLdifs(
+        {
+            "dn: cn=testMethodWithApplyLdif,ou=system\n" + 
+            "objectClass: person\n" + 
+            "cn: testMethodWithApplyLdif\n" + 
+            "sn: sn_testMethodWithApplyLdif\n" 
+        })
     public void testWithoutFactoryAnnotation() throws Exception
     {
         assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testClassA,ou=system"
) ) );
         assertFalse( service.getAdminSession().exists( new LdapDN( "cn=testMethodA,ou=system"
) ) );
+        assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testMethodWithApplyLdif,ou=system"
) ) );
     }
 }

Modified: directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
URL: http://svn.apache.org/viewvc/directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java?rev=893463&r1=893462&r2=893463&view=diff
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
(original)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassC.java
Wed Dec 23 10:36:00 2009
@@ -1,6 +1,7 @@
 package org.apache.directory.server.core.integ;
 
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.directory.server.core.DirectoryService;
@@ -26,8 +27,10 @@
     {
         //assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testSuite,ou=system"
) ) );
         assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testClassC,ou=system"
) ) );
-        // the below will not present if we apply the revert operation
-        //assertTrue( service.getAdminSession().exists( new LdapDN( "cn=testClassB,ou=system"
) ) );
+        
+        // the below DN will be injected in TestClassB when ran as suite, but that DN
+        // shouldn't be present in the suite level DS cause of revert operation
+        assertFalse( service.getAdminSession().exists( new LdapDN( "cn=testClassB,ou=system"
) ) );
     }
     
 }



Mime
View raw message