directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r892287 - in /directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ: FrameworkRunner.java TestClassA.java TestClassB.java TestSuite.java
Date Fri, 18 Dec 2009 15:55:38 GMT
Author: kayyagari
Date: Fri Dec 18 15:55:35 2009
New Revision: 892287

URL: http://svn.apache.org/viewvc?rev=892287&view=rev
Log:
o added a field to set the value
o added a new test class

Added:
    directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
Modified:
    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/TestClassA.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/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=892287&r1=892286&r2=892287&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
Fri Dec 18 15:55:35 2009
@@ -19,6 +19,8 @@
 package org.apache.directory.server.core.integ;
 
 
+import java.lang.reflect.Field;
+
 import org.junit.Ignore;
 import org.junit.runner.Description;
 import org.junit.runner.notification.RunNotifier;
@@ -35,7 +37,8 @@
 public class FrameworkRunner extends BlockJUnit4ClassRunner
 {
     private FrameworkSuite suite;
-    
+
+
     public FrameworkRunner( Class<?> clazz ) throws InitializationError
     {
         super( clazz );
@@ -46,15 +49,32 @@
     public void run( final RunNotifier notifier )
     {
         Factory fac = getDescription().getAnnotation( Factory.class );
-        if( fac != null )
+        try
         {
-            System.out.println( fac.value() );
+            Field field = getTestClass().getJavaClass().getDeclaredField( "factoryLabel"
);
+            
+            Object oldVal = field.get( getTestClass().getJavaClass() );
+            
+            if ( fac != null )
+            {
+                field.set( getTestClass().getJavaClass(), fac.value() );
+            }
+            else // set the parent suit's factory value
+            {
+                // FIXME the getSuite() is rturning null
+                /*
+                Factory suitFactory = getSuite().getDescription().getAnnotation( Factory.class
);
+                
+                field.set( getTestClass().getJavaClass(), suitFactory.value() );
+                */
+            }
+            
+            super.run( notifier );
         }
-        else
+        catch ( Exception e )
         {
-            System.out.println( "no annotation found" );
+            e.printStackTrace();
         }
-        super.run( notifier );
     }
 
 
@@ -68,18 +88,29 @@
             return;
         }
 
-        Factory fac = description.getAnnotation( Factory.class );
-        if( fac != null )
+        try
         {
-            System.out.println( fac.value() );
+            Field field = getTestClass().getJavaClass().getDeclaredField( "factoryLabel"
);
+
+            Object oldVal = field.get( getTestClass().getJavaClass() );
+
+            Factory fac = description.getAnnotation( Factory.class );
+
+            if ( fac != null )
+            {
+                field.set( getTestClass().getJavaClass(), fac.value() );
+            }
+
+            super.runChild( method, notifier );
+
+            // reset the parent's value
+            field.set( getTestClass().getJavaClass(), oldVal );
         }
-        else
+        catch ( Exception e )
         {
-            System.out.println( "no annotation found" );
+            e.printStackTrace();
         }
 
-        Statement statement = methodBlock( method );
-        //test( getTestClass(), statement, notifier, new InheritableSettings( description,
getSettings() ) );
     }
 
 

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=892287&r1=892286&r2=892287&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
Fri Dec 18 15:55:35 2009
@@ -9,9 +9,19 @@
 public class TestClassA
 {
 
+    public static String factoryLabel;
+    
     @Test
     @Factory( "testDummyFactory" )
-    public void testDummy()
+    public void testWithFactoryAnnotation()
     {
+        System.out.println( "factoryLabel = " + factoryLabel );
+    }
+    
+    
+    @Test
+    public void testWithoutFactoryAnnotation()
+    {
+        System.out.println( "factoryLabel = " + factoryLabel );
     }
 }

Added: 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=892287&view=auto
==============================================================================
--- directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
(added)
+++ directory/sandbox/kayyagari/integ-test-framework/src/test/java/org/apache/directory/server/core/integ/TestClassB.java
Fri Dec 18 15:55:35 2009
@@ -0,0 +1,28 @@
+package org.apache.directory.server.core.integ;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( FrameworkRunner.class )
+public class TestClassB
+{
+
+    public static String factoryLabel;
+    
+    @Test
+    @Factory( "TestClassBMethodFactory" )
+    public void testWithFactoryAnnotation()
+    {
+        System.out.println( "factoryLabel = " + factoryLabel );
+    }
+    
+    
+    @Test
+    public void testWithoutFactoryAnnotation()
+    {
+        // FIXME this gives a null factoryLabel cause of the bug in FrameworkRunner
+        // in accessing the suite class's annotation
+        System.out.println( "factoryLabel = " + factoryLabel );
+    }
+}

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=892287&r1=892286&r2=892287&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
Fri Dec 18 15:55:35 2009
@@ -4,7 +4,7 @@
 import org.junit.runners.Suite;
 
 @RunWith( FrameworkSuite.class )
-@Suite.SuiteClasses({ TestClassA.class })
+@Suite.SuiteClasses({ TestClassA.class, TestClassB.class })
 @Factory( "suitlevelFactory" )
 public class TestSuite
 {



Mime
View raw message