directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r662788 - in /directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ: ./ state/
Date Tue, 03 Jun 2008 13:30:16 GMT
Author: elecharny
Date: Tue Jun  3 06:30:16 2008
New Revision: 662788

URL: http://svn.apache.org/viewvc?rev=662788&view=rev
Log:
o Replaced the 7 states by 3 states
o Added a lot of missing javadoc
o Added an abstract state to handle errors and removing the error message from the inherited classes

Added:
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java
Removed:
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedDirtyState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedRevertedState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StoppedDirtyState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StoppedPristineState.java
Modified:
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceContext.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceState.java

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java Tue Jun  3 06:30:16 2008
@@ -19,11 +19,15 @@
 package org.apache.directory.server.core.integ;
 
 
-//port static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
+import java.io.IOException;
+import java.lang.reflect.Method;
+
+import javax.naming.NamingException;
+
 import static org.apache.directory.server.core.integ.state.TestServiceContext.cleanup;
 import static org.apache.directory.server.core.integ.state.TestServiceContext.destroy;
-import static org.apache.directory.server.core.integ.state.TestServiceContext.test;
 import static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
+import static org.apache.directory.server.core.integ.state.TestServiceContext.test;
 import org.junit.internal.runners.InitializationError;
 import org.junit.internal.runners.JUnit4ClassRunner;
 import org.junit.runner.Description;
@@ -32,8 +36,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.reflect.Method;
-
 
 /**
  * A test runner for ApacheDS Core integration tests.
@@ -83,12 +85,18 @@
                 cleanup();
                 destroy();
             }
-            catch ( Exception e )
+            catch ( NamingException e )
             {
                 LOG.error( "Encountered exception while trying to cleanup after test class: "
                         + this.getDescription().getDisplayName(), e );
                 notifier.fireTestFailure( new Failure( getDescription(), e ) );
             }
+            catch ( IOException ioe )
+            {
+                LOG.error( "Encountered exception while trying to cleanup after test class: "
+                        + this.getDescription().getDisplayName(), ioe );
+                notifier.fireTestFailure( new Failure( getDescription(), ioe ) );
+            }
         }
     }
 
@@ -109,11 +117,17 @@
                 cleanup();
                 destroy();
             }
-            catch ( Exception e )
+            catch ( NamingException ne )
             {
                 LOG.error( "Encountered exception while trying to cleanup after test class: "
-                        + this.getDescription().getDisplayName(), e );
-                notifier.fireTestFailure( new Failure( getDescription(), e ) );
+                        + this.getDescription().getDisplayName(), ne );
+                notifier.fireTestFailure( new Failure( getDescription(), ne ) );
+            }
+            catch ( IOException ioe )
+            {
+                LOG.error( "Encountered exception while trying to cleanup after test class: "
+                        + this.getDescription().getDisplayName(), ioe );
+                notifier.fireTestFailure( new Failure( getDescription(), ioe ) );
             }
         }
     }

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java Tue Jun  3 06:30:16 2008
@@ -19,9 +19,13 @@
 package org.apache.directory.server.core.integ;
 
 
-import static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
+import java.io.IOException;
+import java.util.List;
+import javax.naming.NamingException;
+
 import static org.apache.directory.server.core.integ.state.TestServiceContext.cleanup;
 import static org.apache.directory.server.core.integ.state.TestServiceContext.destroy;
+import static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
 import org.junit.internal.requests.IgnoredClassRunner;
 import org.junit.internal.runners.InitializationError;
 import org.junit.runner.Runner;
@@ -29,10 +33,6 @@
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.Suite;
 
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.util.List;
-
 
 /**
  * A replacement for standard JUnit 4 suites. Note that this test suite

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java Tue Jun  3 06:30:16 2008
@@ -19,13 +19,19 @@
 package org.apache.directory.server.core.integ;
 
 
-import org.apache.directory.server.core.integ.annotations.*;
-import org.junit.runner.Description;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.directory.server.core.integ.annotations.ApplyLdifFiles;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.server.core.integ.annotations.Factory;
+import org.apache.directory.server.core.integ.annotations.Mode;
+
+
+import org.junit.runner.Description;
+
 
 /**
  * Inheritable settings of a test suite, test class, or test method.
@@ -35,15 +41,18 @@
  */
 public class InheritableSettings
 {
-    /** the default setup mode to use if inheritence leads to null value */
+    /** the default setup mode to use if inheritance leads to null value */
     public static final SetupMode DEFAULT_MODE = SetupMode.ROLLBACK;
-    /** the default factory to use if inheritence leads to a null value */
+    
+    /** the default factory to use if inheritance leads to a null value */
     public static final DirectoryServiceFactory DEFAULT_FACTORY = DirectoryServiceFactory.DEFAULT;
 
     /** parent settings to inherit from */
     private final InheritableSettings parent;
-    /** junit test description containing all annotations queried */
+    
+    /** JUnit test description containing all annotations queried */
     private final Description description;
+    
     /** default level at which a service is cleaned up */
     private static final Level DEFAULT_CLEANUP_LEVEL = Level.SUITE;
 
@@ -51,7 +60,7 @@
     /**
      * Creates a new InheritableSettings instance for test suites description.
      *
-     * @param description junit description for the suite
+     * @param description JUnit description for the suite
      */
     public InheritableSettings( Description description )
     {
@@ -64,7 +73,7 @@
      * Creates a new InheritableSettings instance based on a test object's
      * description and it's parent's settings.
      *
-     * @param description junit description for the test object
+     * @param description JUnit description for the test object
      * @param parent the parent settings or null if the test entity is a suite
      */
     public InheritableSettings( Description description, InheritableSettings parent )
@@ -80,45 +89,66 @@
     }
 
 
+    /**
+     * @return the description of the running test
+     */
     public Description getDescription()
     {
         return description;
     }
 
 
+    /**
+     * @return the settings inherited from the parent
+     */
     public InheritableSettings getParent()
     {
         return parent;
     }
 
 
+    /**
+     * @return <code>true</code> if we are at the suite level
+     */
     public boolean isSuiteLevel()
     {
         return parent == null;
     }
 
 
+    /**
+     * @return <code>true</code> if we are at the class level
+     */
     public boolean isClassLevel()
     {
-        return parent != null && parent.getParent() == null;
+        return ( parent != null ) && ( parent.getParent() == null );
     }
 
 
+    /**
+     * @return <code>true</code> if we are at the method level
+     */
     public boolean isMethodLevel()
     {
-        return parent != null && parent.getParent() != null;
+        return ( parent != null ) && ( parent.getParent() != null );
     }
 
 
+    /**
+     * @return the test mode. Default to ROLLBACK
+     */
     public SetupMode getMode()
     {
         SetupMode parentMode = DEFAULT_MODE;
+        
         if ( parent != null )
         {
             parentMode = parent.getMode();
         }
 
+        // Get the @Mode annotation
         Mode annotation = description.getAnnotation( Mode.class );
+        
         if ( annotation == null )
         {
             return parentMode;
@@ -130,15 +160,22 @@
     }
 
 
+    /**
+     * @return the DirectoryService factory 
+     * @throws IllegalAccessException if we can't access the factory
+     * @throws InstantiationException if the DirectoryService can't be instanciated
+     */
     public DirectoryServiceFactory getFactory() throws IllegalAccessException, InstantiationException
     {
         DirectoryServiceFactory parentFactory = DEFAULT_FACTORY;
+        
         if ( parent != null )
         {
             parentFactory = parent.getFactory();
         }
 
         Factory annotation = description.getAnnotation( Factory.class );
+        
         if ( annotation == null )
         {
             return parentFactory;
@@ -150,6 +187,12 @@
     }
 
 
+    /**
+     * Get a list of entries from a LDIF declared as an annotation
+     *
+     * @param ldifs the list of LDIFs we want to feed  
+     * @return a list of entries described using a LDIF format
+     */
     public List<String> getLdifs( List<String> ldifs )
     {
         if ( ldifs == null )
@@ -163,7 +206,8 @@
         }
 
         ApplyLdifs annotation = description.getAnnotation( ApplyLdifs.class );
-        if ( annotation != null && annotation.value() != null )
+        
+        if ( ( annotation != null ) && ( annotation.value() != null ) )
         {
             ldifs.addAll( Arrays.asList( annotation.value() ) );
         }
@@ -172,6 +216,12 @@
     }
 
 
+    /**
+     * Get a list of files containing entries described using the LDIF format.
+     *
+     * @param ldifFiles the list to feed
+     * @return a list of files containing some LDIF data
+     */
     public List<String> getLdifFiles( List<String> ldifFiles )
     {
         if ( ldifFiles == null )
@@ -185,6 +235,7 @@
         }
 
         ApplyLdifFiles annotation = description.getAnnotation( ApplyLdifFiles.class );
+        
         if ( annotation != null && annotation.value() != null )
         {
             ldifFiles.addAll( Arrays.asList( annotation.value() ) );
@@ -194,15 +245,20 @@
     }
 
 
+    /**
+     * @return teh cleanup level. Defualt to SUITE
+     */
     public Level getCleanupLevel()
     {
         Level parentCleanupLevel = DEFAULT_CLEANUP_LEVEL;
+        
         if ( parent != null )
         {
             parentCleanupLevel = parent.getCleanupLevel();
         }
 
         CleanupLevel annotation = description.getAnnotation( CleanupLevel.class );
+        
         if ( annotation == null )
         {
             return parentCleanupLevel;

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Tue Jun  3 06:30:16 2008
@@ -19,6 +19,13 @@
 package org.apache.directory.server.core.integ;
 
 
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DirectoryService;
@@ -32,13 +39,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.naming.InvalidNameException;
-import javax.naming.NamingException;
-import javax.naming.ldap.LdapContext;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
 
 /**
  * Integration test utility methods.

Added: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java?rev=662788&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java (added)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java Tue Jun  3 06:30:16 2008
@@ -0,0 +1,162 @@
+/*
+ * 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.state;
+
+
+import java.io.IOException;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.integ.InheritableSettings;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The abstract state of a test service, containing the default state 
+ * transitions
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractState implements TestServiceState
+{
+    /** The class logger */
+    private static final Logger LOG = LoggerFactory.getLogger( AbstractState.class );
+
+    /** The context for this test */
+    protected final TestServiceContext context;
+
+    /** Error message when we can't destroy the service */
+    private static final String DESTROY_ERR = "Cannot destroy when service is in NonExistant state";
+    private static final String CLEANUP_ERROR = "Cannot cleanup when service is in NonExistant state";
+    private static final String STARTUP_ERR = "Cannot startup when service is in NonExistant state";
+    private static final String SHUTDOWN_ERR = "Cannot shutdown service in NonExistant state.";
+    private static final String REVERT_ERROR = "Cannot revert when service is in NonExistant state";
+
+    /**
+     * 
+     * Creates a new instance of AbstractState.
+     *
+     * @param context The associated context
+     */
+    protected AbstractState( TestServiceContext context )
+    {
+        this.context = context;
+    }
+
+
+    /**
+     * Action where an attempt is made to create the service.  Service
+     * creation in this system is the combined instantiation and
+     * configuration which takes place when the factory is used to get
+     * a new instance of the service.
+     *
+     * @param settings The inherited settings
+     * @throws NamingException if we can't create the service
+     */
+    public void create( InheritableSettings settings ) throws NamingException
+    {
+    }
+
+
+    /**
+     * Action where an attempt is made to destroy the service. This
+     * entails nulling out reference to it and triggering garbage
+     * collection.
+     */
+    public void destroy()
+    {
+        LOG.error( DESTROY_ERR );
+        throw new IllegalStateException( DESTROY_ERR );
+    }
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    public void cleanup() throws  IOException
+    {
+        LOG.error( CLEANUP_ERROR );
+        throw new IllegalStateException( CLEANUP_ERROR );
+    }
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    public void startup() throws NamingException
+    {
+        LOG.error( STARTUP_ERR );
+        throw new IllegalStateException( STARTUP_ERR );
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws NamingException on failures to stop the core directory service
+     */
+    public void shutdown() throws NamingException
+    {
+        LOG.error( SHUTDOWN_ERR );
+        throw new IllegalStateException( SHUTDOWN_ERR );
+    }
+
+
+    /**
+     * Action where an attempt is made to run a test against the service.
+     *
+     * All annotations should have already been processed for
+     * InheritableSettings yet they and others can be processed since we have
+     * access to the method annotations below
+     *
+     * @param testClass the class whose test method is to be run
+     * @param testMethod the test method which is to be run
+     * @param notifier a notifier to report failures to
+     * @param settings the inherited settings and annotations associated with
+     * the test method
+     */
+    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
+    {
+    }
+
+
+    /**
+     * Action where an attempt is made to revert the service to it's
+     * initial start up state by using a previous snapshot.
+     *
+     * @throws NamingException on failures to revert the state of the core
+     * directory service
+     */
+    public void revert() throws NamingException
+    {
+        LOG.error( REVERT_ERROR );
+        throw new IllegalStateException( REVERT_ERROR );
+    }
+}

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java Tue Jun  3 06:30:16 2008
@@ -1,160 +1,213 @@
-/*
- * 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.state;
-
-import javax.naming.NamingException;
-
-import org.apache.directory.server.core.integ.DirectoryServiceFactory;
-import org.apache.directory.server.core.integ.InheritableSettings;
-import org.apache.directory.server.core.integ.SetupMode;
-import org.junit.internal.runners.TestClass;
-import org.junit.internal.runners.TestMethod;
-import org.junit.runner.notification.RunNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * The state of a test service when it has not yet been created.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class NonExistentState implements TestServiceState
-{
-    private static final Logger LOG = LoggerFactory.getLogger( NonExistentState.class );
-    private final TestServiceContext context;
-    private static final String DESTROY_ERR = "Cannot destroy when service is in NonExistant state";
-    private static final String CLEANUP_ERROR = "Cannot cleanup when service is in NonExistant state";
-    private static final String STARTUP_ERR = "Cannot startup when service is in NonExistant state";
-    private static final String SHUTDOWN_ERR = "Cannot shutdown service in NonExistant state.";
-    private static final String REVERT_ERROR = "Cannot revert when service is in NonExistant state";
-
-
-    public NonExistentState( TestServiceContext context )
-    {
-        this.context = context;
-    }
-
-
-    public void create( DirectoryServiceFactory factory ) throws NamingException
-    {
-        LOG.debug( "calling create()" );
-        context.setService( factory.newInstance() );
-        context.setState( context.getStoppedDirtyState() );
-    }
-
-
-    public void destroy()
-    {
-        LOG.error( DESTROY_ERR );
-        throw new IllegalStateException( DESTROY_ERR );
-    }
-
-
-    public void cleanup()
-    {
-        LOG.error( CLEANUP_ERROR );
-        throw new IllegalStateException( CLEANUP_ERROR );
-    }
-
-
-    public void startup()
-    {
-        LOG.error( STARTUP_ERR );
-        throw new IllegalStateException( STARTUP_ERR );
-    }
-
-
-    public void shutdown()
-    {
-        LOG.error( SHUTDOWN_ERR );
-        throw new IllegalStateException( SHUTDOWN_ERR );
-    }
-
-
-    /**
-     * This method is a bit different.  Consider this method to hold the logic
-     * which is needed to shift the context state from the present state to a
-     * started state so we can call test on the current state of the context.
-     *
-     * Basically if the service is not needed or the test is ignored, then we
-     * just invoke the test: if ignored the test is not dealt with by the
-     * MethodRoadie run method.
-     *
-     * In tests not ignored requiring setup modes RESTART and CUMULATIVE we
-     * simply create the service and start it up without a cleanup.  In the
-     * PRISTINE and ROLLBACK modes we do the same but cleanup() before a
-     * restart.
-     *
-     * @see TestServiceState#test(TestClass, TestMethod, RunNotifier, InheritableSettings) 
-     */
-    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
-    {
-        LOG.debug( "calling test(): {}", settings.getDescription().getDisplayName() );
-
-        if ( settings.getMode() == SetupMode.NOSERVICE || testMethod.isIgnored() )
-        {
-            // no state change here
-            TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
-            return;
-        }
-
-        if ( settings.getMode() == SetupMode.RESTART || settings.getMode() == SetupMode.CUMULATIVE )
-        {
-            try
-            {
-                context.getState().create( settings.getFactory() );
-                context.getState().startup();
-            }
-            catch ( Exception e )
-            {
-                LOG.error( "Failed to create and start new server instance: " + e );
-                notifier.testAborted( settings.getDescription(), e );
-                return;
-            }
-        }
-
-        if ( settings.getMode() == SetupMode.PRISTINE || settings.getMode() == SetupMode.ROLLBACK )
-        {
-            try
-            {
-                context.getState().create( settings.getFactory() );
-                context.getState().cleanup();
-                context.getState().startup();
-            }
-            catch ( Exception e )
-            {
-                LOG.error( "Failed to create, cleanup and start new server instance: " + e );
-                notifier.testAborted( settings.getDescription(), e );
-                return;
-            }
-        }
-
-        // state object what ever it is will change state so we just return
-        context.getState().test( testClass, testMethod, notifier, settings );
-    }
-
-
-    public void revert()
-    {
-        LOG.error( REVERT_ERROR );
-        throw new IllegalStateException( REVERT_ERROR );
-    }
-}
+/*
+ * 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.state;
+
+
+import java.io.IOException;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.integ.DirectoryServiceFactory;
+import org.apache.directory.server.core.integ.InheritableSettings;
+import static org.apache.directory.server.core.integ.IntegrationUtils.doDelete;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The state of a test service when it has not yet been created.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NonExistentState extends AbstractState
+{
+    private static final Logger LOG = LoggerFactory.getLogger( NonExistentState.class );
+
+
+    /**
+     * Creates a new instance of NonExistentState.
+     *
+     * @param context the test context
+     */
+    public NonExistentState( TestServiceContext context )
+    {
+        super( context );
+    }
+
+
+    /**
+     * Action where an attempt is made to create the service.  Service
+     * creation in this system is the combined instantiation and
+     * configuration which takes place when the factory is used to get
+     * a new instance of the service.
+     *
+     * @param settings The inherited settings
+     * @throws NamingException if we can't create the service
+     */
+    public void create( InheritableSettings settings  ) throws NamingException
+    {
+        LOG.debug( "calling create()" );
+
+        try
+        {
+            DirectoryServiceFactory factory = settings.getFactory();
+            context.setService( factory.newInstance() );
+        }
+        catch ( InstantiationException ie )
+        {
+            throw new NamingException( ie.getMessage() );
+        }
+        catch ( IllegalAccessException iae )
+        {
+            throw new NamingException( iae.getMessage() );
+        }
+    }
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    public void cleanup() throws IOException
+    {
+        LOG.debug( "calling cleanup()" );
+        doDelete( context.getService().getWorkingDirectory() );
+    }
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    public void startup() throws NamingException
+    {
+        LOG.debug( "calling startup()" );
+        context.getService().startup();
+    }
+
+
+    /**
+     * This method is a bit different.  Consider this method to hold the logic
+     * which is needed to shift the context state from the present state to a
+     * started state so we can call test on the current state of the context.
+     *
+     * Basically if the service is not needed or the test is ignored, then we
+     * just invoke the test: if ignored the test is not dealt with by the
+     * MethodRoadie run method.
+     *
+     * In tests not ignored requiring setup modes RESTART and CUMULATIVE we
+     * simply create the service and start it up without a cleanup.  In the
+     * PRISTINE and ROLLBACK modes we do the same but cleanup() before a
+     * restart.
+     *
+     * @see TestServiceState#test(TestClass, TestMethod, RunNotifier, InheritableSettings) 
+     */
+    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
+    {
+        LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
+
+        if ( testMethod.isIgnored() )
+        {
+            // The test is ignored
+            return;
+        }
+
+        switch ( settings.getMode() )
+        {
+            case CUMULATIVE:
+            case RESTART:
+                try
+                {
+                    create( settings );
+                }
+                catch ( NamingException ne )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ne );
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+
+                try
+                {
+                    startup();
+                }
+                catch ( NamingException ne )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ne );
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+
+                context.setState( context.getStartedNormalState() );
+                context.getState().test( testClass, testMethod, notifier, settings );
+                return;
+
+
+            case PRISTINE:
+            case ROLLBACK:
+                try
+                {
+                    create( settings );
+                }
+                catch ( NamingException ne )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ne );
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+
+                try
+                {
+                    cleanup();
+                }
+                catch ( IOException ioe )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ioe );
+                    notifier.testAborted( settings.getDescription(), ioe );
+                    return;
+                }
+
+                try
+                {
+                    startup();
+                }
+                catch ( NamingException ne )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ne );
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+
+                context.setState( context.getStartedPristineState() );
+                context.getState().test( testClass, testMethod, notifier, settings );
+                return;
+
+            default:
+                return;
+        }
+    }
+}

Added: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java?rev=662788&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java (added)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java Tue Jun  3 06:30:16 2008
@@ -0,0 +1,218 @@
+/*
+ * 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.state;
+
+
+import java.io.IOException;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.integ.InheritableSettings;
+import static org.apache.directory.server.core.integ.IntegrationUtils.doDelete;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+/**
+ * The state of a running test service which has been used for running
+ * integration tests and has been reverted to contain the same content as it
+ * did when created and started.  It is not really pristine however for all
+ * practical purposes of integration testing it appears to be the same as
+ * when first started.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StartedNormalState extends AbstractState
+{
+    private static final Logger LOG = LoggerFactory.getLogger( StartedNormalState.class );
+
+
+    /**
+     * 
+     * Creates a new instance of StartedNormalState.
+     *
+     * @param context the test's context
+     */
+    public StartedNormalState( TestServiceContext context )
+    {
+        super( context );
+    }
+
+
+    /**
+     * Action where an attempt is made to destroy the service. This
+     * entails nulling out reference to it and triggering garbage
+     * collection.
+     */
+    public void destroy()
+    {
+        LOG.debug( "calling destroy()" );
+        context.setService( null );
+        context.setState( context.getNonExistentState() );
+        System.gc();
+    }
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    public void cleanup() throws IOException
+    {
+        LOG.debug( "calling cleanup()" );
+        doDelete( context.getService().getWorkingDirectory() );
+    }
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    public void startup() throws NamingException
+    {
+        LOG.debug( "calling startup()" );
+        context.getService().startup();
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws NamingException on failures to stop the core directory service
+     */
+    public void shutdown() throws NamingException
+    {
+        LOG.debug( "calling shutdown()" );
+        context.getService().shutdown();
+    }
+
+
+    /**
+     * Action where an attempt is made to revert the service to it's
+     * initial start up state by using a previous snapshot.
+     *
+     * @throws NamingException on failures to revert the state of the core
+     * directory service
+     */
+    public void revert() throws NamingException
+    {
+        LOG.debug( "calling revert()" );
+        context.getService().revert();
+    }
+
+
+    /**
+     * Action where an attempt is made to run a test against the service.
+     *
+     * All annotations should have already been processed for
+     * InheritableSettings yet they and others can be processed since we have
+     * access to the method annotations below
+     *
+     * @param testClass the class whose test method is to be run
+     * @param testMethod the test method which is to be run
+     * @param notifier a notifier to report failures to
+     * @param settings the inherited settings and annotations associated with
+     * the test method
+     */
+    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
+    {
+        LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
+
+        if ( testMethod.isIgnored() )
+        {
+            // The test is ignored
+            return;
+        }
+
+        switch ( settings.getMode() )
+        {
+            case ROLLBACK:
+                try
+                {
+                    context.getService().getChangeLog().tag();
+                }
+                catch ( NamingException e )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), e );
+                    return;
+                }
+
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                
+                try
+                {
+                    revert();
+                }
+                catch ( NamingException ne )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+                
+                return;
+                
+            case RESTART :
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+
+                try
+                {
+                    shutdown();
+                }
+                catch ( NamingException ne )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+                
+                try
+                {
+                    startup();
+                }
+                catch ( NamingException ne )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + ne );
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+
+                return;
+                
+            default:
+                return;
+        }
+    }
+}
\ No newline at end of file

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java Tue Jun  3 06:30:16 2008
@@ -1,124 +1,188 @@
-/*
- * 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.state;
-
-
-import org.apache.directory.server.core.integ.DirectoryServiceFactory;
-import org.apache.directory.server.core.integ.InheritableSettings;
-import org.apache.directory.server.core.integ.SetupMode;
-import org.junit.internal.runners.TestClass;
-import org.junit.internal.runners.TestMethod;
-import org.junit.runner.notification.RunNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.naming.NamingException;
-
-
-/**
- * A test service state where the server is running and has not been used for
- * any integration test since it was created.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class StartedPristineState implements TestServiceState
-{
-    private static final Logger LOG = LoggerFactory.getLogger( StartedPristineState.class );
-    private final TestServiceContext context;
-
-
-    public StartedPristineState( TestServiceContext context )
-    {
-        this.context = context;
-    }
-
-
-    public void create( DirectoryServiceFactory factory )
-    {
-        throw new IllegalStateException( "Cannot create new instance while service is running." );
-    }
-
-
-    public void destroy()
-    {
-        throw new IllegalStateException( "Cannot destroy started service." );
-    }
-
-
-    public void cleanup()
-    {
-        throw new IllegalStateException( "Cannot cleanup started service." );
-    }
-
-
-    public void startup()
-    {
-        throw new IllegalStateException( "Cannot startup started service." );
-    }
-
-
-    public void shutdown() throws NamingException
-    {
-        LOG.debug( "calling shutdown()" );
-        context.getService().shutdown();
-        context.setState( context.getStoppedPristineState() );
-    }
-
-
-    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
-    {
-        LOG.debug( "calling test(): {}", settings.getDescription().getDisplayName() );
-
-        if ( settings.getMode() == SetupMode.NOSERVICE || testMethod.isIgnored() )
-        {
-            // no state change here
-            TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
-            return;
-        }
-
-        try
-        {
-            context.getService().getChangeLog().tag();
-        }
-        catch ( NamingException e )
-        {
-            // @TODO - we might want to check the revision of the service before
-            // we presume that it has been soiled.  Some tests may simply peform
-            // some read operations or checks on the service and may not alter it
-            context.setState( context.getStartedDirtyState() );
-
-            notifier.testAborted( settings.getDescription(), e );
-            return;
-        }
-
-        TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
-
-        // @TODO - we might want to check the revision of the service before
-        // we presume that it has been soiled.  Some tests may simply peform
-        // some read operations or checks on the service and may not alter it
-        context.setState( context.getStartedDirtyState() );
-    }
-
-
-    public void revert() throws NamingException
-    {
-        throw new IllegalStateException( "Cannot revert already pristine service." );
-    }
+/*
+ * 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.state;
+
+
+import java.io.IOException;
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.integ.InheritableSettings;
+import static org.apache.directory.server.core.integ.IntegrationUtils.doDelete;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+/**
+ * A test service state where the server is running and has not been used for
+ * any integration test since it was created.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StartedPristineState extends AbstractState
+{
+    private static final Logger LOG = LoggerFactory.getLogger( StartedPristineState.class );
+
+
+    /**
+     * 
+     * Creates a new instance of StartedPristineState.
+     *
+     * @param context the test's context
+     */
+    public StartedPristineState( TestServiceContext context )
+    {
+        super( context );
+    }
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    public void cleanup() throws IOException
+    {
+        LOG.debug( "calling cleanup()" );
+        doDelete( context.getService().getWorkingDirectory() );
+    }
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    public void startup() throws NamingException
+    {
+        LOG.debug( "calling startup()" );
+        context.getService().startup();
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws NamingException on failures to stop the core directory service
+     */
+    public void shutdown() throws NamingException
+    {
+        LOG.debug( "calling shutdown()" );
+        context.getService().shutdown();
+    }
+
+
+    /**
+     * Action where an attempt is made to run a test against the service.
+     *
+     * All annotations should have already been processed for
+     * InheritableSettings yet they and others can be processed since we have
+     * access to the method annotations below
+     *
+     * @param testClass the class whose test method is to be run
+     * @param testMethod the test method which is to be run
+     * @param notifier a notifier to report failures to
+     * @param settings the inherited settings and annotations associated with
+     * the test method
+     */
+    public void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings )
+    {
+        LOG.debug( "calling test(): {}, mode {}", settings.getDescription().getDisplayName(), settings.getMode() );
+
+        if ( testMethod.isIgnored() )
+        {
+            // The test is ignored
+            return;
+        }
+
+        switch ( settings.getMode() )
+        {
+            case PRISTINE:
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                
+                try
+                {
+                    shutdown();
+                }
+                catch ( NamingException ne )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+                
+                try
+                {
+                    cleanup();
+                }
+                catch ( IOException ioe )
+                {
+                    LOG.error( "Failed to cleanup new server instance: " + ioe );
+                    notifier.testAborted( settings.getDescription(), ioe );
+                    return;
+                }
+
+                destroy();
+                context.setState( context.getNonExistentState() );
+                return;
+                
+            case ROLLBACK:
+                try
+                {
+                    context.getService().getChangeLog().tag();
+                }
+                catch ( NamingException e )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), e );
+                    return;
+                }
+
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                context.setState( context.getStartedNormalState() );
+
+                try
+                {
+                    context.getState().revert();
+                }
+                catch ( NamingException ne )
+                {
+                    // @TODO - we might want to check the revision of the service before
+                    // we presume that it has been soiled.  Some tests may simply perform
+                    // some read operations or checks on the service and may not alter it
+                    notifier.testAborted( settings.getDescription(), ne );
+                    return;
+                }
+                return;
+
+            default:
+                return;
+        }
+    }
 }
\ No newline at end of file

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceContext.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceContext.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceContext.java Tue Jun  3 06:30:16 2008
@@ -1,278 +1,290 @@
-/*
- * 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.state;
-
-
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.integ.DirectoryServiceFactory;
-import org.apache.directory.server.core.integ.InheritableSettings;
-import org.junit.internal.runners.MethodRoadie;
-import org.junit.internal.runners.TestClass;
-import org.junit.internal.runners.TestMethod;
-import org.junit.runner.Description;
-import org.junit.runner.notification.RunNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-
-
-/**
- * The context for managing the state of an integration test service.
- * Each thread of execution driving tests manages it's own service context.
- * Hence parallelism can be achieved while running integration tests.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class TestServiceContext
-{
-    private static final Logger LOG = LoggerFactory.getLogger( TestServiceContext.class );
-    private static final ThreadLocal<TestServiceContext> CONTEXTS = new ThreadLocal<TestServiceContext>();
-
-    private final TestServiceState nonExistentState = new NonExistentState( this );
-    private final TestServiceState startedDirtyState = new StartedDirtyState( this );
-    private final TestServiceState startedPristineState = new StartedPristineState( this );
-    private final TestServiceState startedRevertedState = new StartedRevertedState( this );
-    private final TestServiceState stoppedDirtyState = new StoppedDirtyState( this );
-    private final TestServiceState stoppedPristineState = new StoppedPristineState( this );
-
-
-    /** current service state with respect to the testing life cycle */
-    private TestServiceState state = nonExistentState;
-
-    /** the core directory service managed by this context */
-    private DirectoryService service;
-
-
-    /**
-     * Gets the TestServiceContext associated with the current thread of
-     * execution.  If one does not yet exist it will be created.
-     *
-     * @return the context associated with the calling thread
-     */
-    public static TestServiceContext get()
-    {
-        TestServiceContext context = CONTEXTS.get();
-
-        if ( context == null )
-        {
-            context = new TestServiceContext();
-            CONTEXTS.set( context );
-        }
-
-        return context;
-    }
-    
-
-    /**
-     * Sets the TestServiceContext for this current thread
-     *
-     * @param context the context associated with the calling thread
-     */
-    public static void set( TestServiceContext context )
-    {
-        CONTEXTS.set( context );
-    }
-
-
-    /**
-     * Action where an attempt is made to create the service.  Service
-     * creation in this system is the combined instantiation and
-     * configuration which takes place when the factory is used to get
-     * a new instance of the service.
-     *
-     * @param factory the factory to use for creating a configured service
-     */
-    public static void create( DirectoryServiceFactory factory ) throws NamingException
-    {
-        get().state.create( factory );
-    }
-
-
-    /**
-     * Action where an attempt is made to destroy the service.  This
-     * entails nulling out reference to it and triggering garbage
-     * collection.
-     */
-    public static void destroy()
-    {
-        get().state.destroy();
-    }
-
-
-    /**
-     * Action where an attempt is made to erase the contents of the
-     * working directory used by the service for various files including
-     * partition database files.
-     *
-     * @throws IOException on errors while deleting the working directory
-     */
-    public static void cleanup() throws IOException
-    {
-        get().state.cleanup();
-    }
-
-
-    /**
-     * Action where an attempt is made to start up the service.
-     *
-     * @throws NamingException on failures to start the core directory service
-     */
-    public static void startup() throws NamingException
-    {
-        get().state.startup();
-    }
-
-
-    /**
-     * Action where an attempt is made to shutdown the service.
-     *
-     * @throws NamingException on failures to stop the core directory service
-     */
-    public static void shutdown() throws NamingException
-    {
-        get().state.shutdown();
-    }
-
-
-    /**
-     * Action where an attempt is made to run a test against the service.
-     *
-     * @param testClass the class whose test method is to be run
-     * @param testMethod the test method which is to be run
-     * @param notifier a notifier to report failures to
-     * @param settings the inherited settings and annotations associated with
-     * the test method
-     */
-    public static void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier,
-                             InheritableSettings settings )
-    {
-        LOG.debug( "calling test(): {}", settings.getDescription().getDisplayName() );
-        get().getState().test( testClass, testMethod, notifier, settings );
-    }
-
-
-    /**
-     * Action where an attempt is made to revert the service to it's
-     * initial start up state by using a previous snapshot.
-     *
-     * @throws NamingException on failures to revert the state of the core
-     * directory service
-     */
-    public static void revert() throws NamingException
-    {
-        get().state.revert();
-    }
-
-
-    static void invokeTest( TestClass testClass, TestMethod testMethod, RunNotifier notifier, Description description )
-    {
-        Object test;
-        
-        try
-        {
-            test = testClass.getConstructor().newInstance();
-            Field field = testClass.getJavaClass().getDeclaredField( "service" );
-            field.set( testClass.getJavaClass(), get().getService() );
-        }
-        catch ( InvocationTargetException e )
-        {
-            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), e.getCause() );
-            notifier.testAborted( description, e.getCause() );
-            return;
-        }
-        catch ( Exception e )
-        {
-            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), e );
-            notifier.testAborted( description, e );
-            return;
-        }
-
-        new MethodRoadie( test, testMethod, notifier, description ).run();
-    }
-
-
-    // -----------------------------------------------------------------------
-    // Package Friendly Instance Methods
-    // -----------------------------------------------------------------------
-
-
-    void setState( TestServiceState state )
-    {
-        this.state = state;
-    }
-
-
-    TestServiceState getState()
-    {
-        return state;
-    }
-
-
-    TestServiceState getNonExistentState()
-    {
-        return nonExistentState;
-    }
-
-
-    TestServiceState getStartedDirtyState()
-    {
-        return startedDirtyState;
-    }
-
-
-    TestServiceState getStartedPristineState()
-    {
-        return startedPristineState;
-    }
-
-
-    TestServiceState getStartedRevertedState()
-    {
-        return startedRevertedState;
-    }
-
-
-    TestServiceState getStoppedDirtyState()
-    {
-        return stoppedDirtyState;
-    }
-
-
-    TestServiceState getStoppedPristineState()
-    {
-        return stoppedPristineState;
-    }
-
-
-    DirectoryService getService()
-    {
-        return service;
-    }
-
-
-    void setService( DirectoryService service )
-    {
-        this.service = service;
-    }
-}
+/*
+ * 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.state;
+
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.InheritableSettings;
+import org.junit.internal.runners.MethodRoadie;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The context for managing the state of an integration test service.
+ * Each thread of execution driving tests manages it's own service context.
+ * Hence parallelism can be achieved while running integration tests.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class TestServiceContext
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( TestServiceContext.class );
+    
+    /** The ThreadLocal containing the contexts */
+    private static final ThreadLocal<TestServiceContext> CONTEXTS = new ThreadLocal<TestServiceContext>();
+
+    /** The NonExistant state instance */
+    private final TestServiceState nonExistentState = new NonExistentState( this );
+
+    /** The StartedPristine state instance */
+    private final TestServiceState startedPristineState = new StartedPristineState( this );
+    
+    /** The StartedNormal state instance */
+    private final TestServiceState startedNormalState = new StartedNormalState( this );
+
+
+    /** current service state with respect to the testing life cycle */
+    private TestServiceState state = nonExistentState;
+
+    /** the core directory service managed by this context */
+    private DirectoryService service;
+
+
+    /**
+     * A private constructor, the clas contains only static methods, 
+     * no need to construct an instance.
+     */
+    private TestServiceContext()
+    {
+        
+    }
+
+
+    /**
+     * Gets the TestServiceContext associated with the current thread of
+     * execution.  If one does not yet exist it will be created.
+     *
+     * @return the context associated with the calling thread
+     */
+    public static TestServiceContext get()
+    {
+        TestServiceContext context = CONTEXTS.get();
+
+        if ( context == null )
+        {
+            context = new TestServiceContext();
+            CONTEXTS.set( context );
+        }
+
+        return context;
+    }
+    
+
+    /**
+     * Sets the TestServiceContext for this current thread
+     *
+     * @param context the context associated with the calling thread
+     */
+    public static void set( TestServiceContext context )
+    {
+        CONTEXTS.set( context );
+    }
+
+
+    /**
+     * Action where an attempt is made to create the service.  Service
+     * creation in this system is the combined instantiation and
+     * configuration which takes place when the factory is used to get
+     * a new instance of the service.
+     *
+     * @param settings the settings for this test
+     * @throws NamingException if we can't create the service
+     */
+    public static void create( InheritableSettings settings ) throws NamingException
+    {
+        get().state.create( settings );
+    }
+
+
+    /**
+     * Action where an attempt is made to destroy the service.  This
+     * entails nulling out reference to it and triggering garbage
+     * collection.
+     */
+    public static void destroy()
+    {
+        get().state.destroy();
+    }
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    public static void cleanup() throws IOException
+    {
+        get().state.cleanup();
+    }
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    public static void startup() throws NamingException
+    {
+        get().state.startup();
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws NamingException on failures to stop the core directory service
+     */
+    public static void shutdown() throws NamingException
+    {
+        get().state.shutdown();
+    }
+
+
+    /**
+     * Action where an attempt is made to run a test against the service.
+     *
+     * @param testClass the class whose test method is to be run
+     * @param testMethod the test method which is to be run
+     * @param notifier a notifier to report failures to
+     * @param settings the inherited settings and annotations associated with
+     * the test method
+     */
+    public static void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier,
+                             InheritableSettings settings )
+    {
+        LOG.debug( "calling test(): {}", settings.getDescription().getDisplayName() );
+        get().getState().test( testClass, testMethod, notifier, settings );
+    }
+
+
+    /**
+     * Action where an attempt is made to revert the service to it's
+     * initial start up state by using a previous snapshot.
+     *
+     * @throws NamingException on failures to revert the state of the core
+     * directory service
+     */
+    public static void revert() throws NamingException
+    {
+        get().state.revert();
+    }
+
+
+    static void invokeTest( TestClass testClass, TestMethod testMethod, RunNotifier notifier, Description description )
+    {
+        try
+        {
+            Object test = testClass.getConstructor().newInstance();
+            Field field = testClass.getJavaClass().getDeclaredField( "service" );
+            field.set( testClass.getJavaClass(), get().getService() );
+            new MethodRoadie( test, testMethod, notifier, description ).run();
+        }
+        catch ( InvocationTargetException e )
+        {
+            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), e.getCause() );
+            notifier.testAborted( description, e.getCause() );
+            return;
+        }
+        catch ( InstantiationException ie )
+        {
+            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), ie );
+            notifier.testAborted( description, ie );
+            return;
+        }
+        catch ( IllegalAccessException iae )
+        {
+            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), iae );
+            notifier.testAborted( description, iae );
+            return;
+        }
+        catch ( NoSuchMethodException nsme )
+        {
+            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), nsme );
+            notifier.testAborted( description, nsme );
+            return;
+        }
+        catch ( NoSuchFieldException nsfe )
+        {
+            LOG.error( "Failed to invoke test method: " + description.getDisplayName(), nsfe );
+            notifier.testAborted( description, nsfe );
+            return;
+        }
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Package Friendly Instance Methods
+    // -----------------------------------------------------------------------
+
+
+    void setState( TestServiceState state )
+    {
+        this.state = state;
+    }
+
+
+    TestServiceState getState()
+    {
+        return state;
+    }
+
+
+    TestServiceState getNonExistentState()
+    {
+        return nonExistentState;
+    }
+
+
+    TestServiceState getStartedPristineState()
+    {
+        return startedPristineState;
+    }
+
+
+    TestServiceState getStartedNormalState()
+    {
+        return startedNormalState;
+    }
+
+
+    DirectoryService getService()
+    {
+        return service;
+    }
+
+
+    void setService( DirectoryService service )
+    {
+        this.service = service;
+    }
+}

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceState.java?rev=662788&r1=662787&r2=662788&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceState.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/TestServiceState.java Tue Jun  3 06:30:16 2008
@@ -1,109 +1,109 @@
-/*
- * 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.state;
-
-import org.apache.directory.server.core.integ.DirectoryServiceFactory;
-import org.apache.directory.server.core.integ.InheritableSettings;
-import org.junit.internal.runners.TestClass;
-import org.junit.internal.runners.TestMethod;
-import org.junit.runner.notification.RunNotifier;
-
-import javax.naming.NamingException;
-import java.io.IOException;
-
-
-/**
- * The interface representing a state in the lifecycle of a service
- * during integration testing.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public interface TestServiceState
-{
-    /**
-     * Action where an attempt is made to create the service.  Service
-     * creation in this system is the combined instantiation and
-     * configuration which takes place when the factory is used to get
-     * a new instance of the service.
-     *
-     * @param factory the factory to use for creating a configured service
-     */
-    void create( DirectoryServiceFactory factory ) throws NamingException;
-
-
-    /**
-     * Action where an attempt is made to destroy the service.  This
-     * entails nulling out reference to it and triggering garbage
-     * collection.
-     */
-    void destroy();
-
-
-    /**
-     * Action where an attempt is made to erase the contents of the
-     * working directory used by the service for various files including
-     * partition database files.
-     *
-     * @throws IOException on errors while deleting the working directory
-     */
-    void cleanup() throws IOException;
-
-
-    /**
-     * Action where an attempt is made to start up the service.
-     *
-     * @throws NamingException on failures to start the core directory service
-     */
-    void startup() throws NamingException;
-
-
-    /**
-     * Action where an attempt is made to shutdown the service.
-     *
-     * @throws NamingException on failures to stop the core directory service
-     */
-    void shutdown() throws NamingException;
-
-
-    /**
-     * Action where an attempt is made to run a test against the service.
-     *
-     * All annotations should have already been processed for
-     * InheritableSettings yet they and others can be processed since we have
-     * access to the method annotations below
-     *
-     * @param testClass the class whose test method is to be run
-     * @param testMethod the test method which is to be run
-     * @param notifier a notifier to report failures to
-     * @param settings the inherited settings and annotations associated with
-     * the test method
-     */
-    void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings );
-
-
-    /**
-     * Action where an attempt is made to revert the service to it's
-     * initial start up state by using a previous snapshot.
-     *
-     * @throws NamingException on failures to revert the state of the core
-     * directory service
-     */
-    void revert() throws NamingException;
-}
+/*
+ * 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.state;
+
+import java.io.IOException;
+import javax.naming.NamingException;
+
+import org.apache.directory.server.core.integ.InheritableSettings;
+import org.junit.internal.runners.TestClass;
+import org.junit.internal.runners.TestMethod;
+import org.junit.runner.notification.RunNotifier;
+
+
+/**
+ * The interface representing a state in the lifecycle of a service
+ * during integration testing.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface TestServiceState
+{
+    /**
+     * Action where an attempt is made to create the service.  Service
+     * creation in this system is the combined instantiation and
+     * configuration which takes place when the factory is used to get
+     * a new instance of the service.
+     *
+     * @param settings The inherited settings
+     * @throws NamingException if we can't create the service
+     */
+    void create( InheritableSettings settings ) throws NamingException;
+
+
+    /**
+     * Action where an attempt is made to destroy the service. This
+     * entails nulling out reference to it and triggering garbage
+     * collection.
+     */
+    void destroy();
+
+
+    /**
+     * Action where an attempt is made to erase the contents of the
+     * working directory used by the service for various files including
+     * partition database files.
+     *
+     * @throws IOException on errors while deleting the working directory
+     */
+    void cleanup() throws IOException;
+
+
+    /**
+     * Action where an attempt is made to start up the service.
+     *
+     * @throws NamingException on failures to start the core directory service
+     */
+    void startup() throws NamingException;
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws NamingException on failures to stop the core directory service
+     */
+    void shutdown() throws NamingException;
+
+
+    /**
+     * Action where an attempt is made to run a test against the service.
+     *
+     * All annotations should have already been processed for
+     * InheritableSettings yet they and others can be processed since we have
+     * access to the method annotations below
+     *
+     * @param testClass the class whose test method is to be run
+     * @param testMethod the test method which is to be run
+     * @param notifier a notifier to report failures to
+     * @param settings the inherited settings and annotations associated with
+     * the test method
+     */
+    void test( TestClass testClass, TestMethod testMethod, RunNotifier notifier, InheritableSettings settings );
+
+
+    /**
+     * Action where an attempt is made to revert the service to it's
+     * initial start up state by using a previous snapshot.
+     *
+     * @throws NamingException on failures to revert the state of the core
+     * directory service
+     */
+    void revert() throws NamingException;
+}



Mime
View raw message