directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r664015 [1/2] - in /directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ: ./ state/
Date Fri, 06 Jun 2008 16:21:35 GMT
Author: elecharny
Date: Fri Jun  6 09:21:35 2008
New Revision: 664015

URL: http://svn.apache.org/viewvc?rev=664015&view=rev
Log:
o Merged with Alex's changes
o Changed the states to have less of those guys
o Added the @ApplyLdifs mechanism
o Added Javadoc

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

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiRunner.java Fri Jun  6 09:21:35 2008
@@ -1,133 +1,134 @@
-/*
- * 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;
-
-
-//port static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
-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 org.junit.internal.runners.InitializationError;
-import org.junit.internal.runners.JUnit4ClassRunner;
-import org.junit.runner.Description;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.Method;
-
-
-/**
- * A test runner for ApacheDS Core integration tests.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class CiRunner extends JUnit4ClassRunner
-{
-    private static final Logger LOG = LoggerFactory.getLogger( CiRunner.class );
-    private CiSuite suite;
-    private InheritableSettings settings;
-
-
-    public CiRunner( Class<?> clazz ) throws InitializationError
-    {
-        super( clazz );
-    }
-
-
-    protected InheritableSettings getSettings()
-    {
-        if ( settings != null )
-        {
-            return settings;
-        }
-
-        if ( suite == null )
-        {
-            settings = new InheritableSettings( getDescription(), null );
-        }
-
-        return settings;
-    }
-
-
-    @Override
-    public void run( final RunNotifier notifier )
-    {
-        super.run( notifier );
-        Level cleanupLevel = getSettings().getCleanupLevel();
-        if ( cleanupLevel == Level.CLASS )
-        {
-            try
-            {
-                shutdown();
-                cleanup();
-                destroy();
-            }
-            catch ( Exception e )
-            {
-                LOG.error( "Encountered exception while trying to cleanup after test class: "
-                        + this.getDescription().getDisplayName(), e );
-                notifier.fireTestFailure( new Failure( getDescription(), e ) );
-            }
-        }
-    }
-
-
-    @Override
-    protected void invokeTestMethod( Method method, final RunNotifier notifier )
-    {
-        LOG.debug( "About to invoke test method {}", method.getName() );
-        Description description = methodDescription( method );
-        test( getTestClass(), wrapMethod( method ), notifier, new InheritableSettings( description, getSettings() ) );
-
-        Level cleanupLevel = getSettings().getCleanupLevel();
-        if ( cleanupLevel == Level.METHOD )
-        {
-            try
-            {
-                shutdown();
-                cleanup();
-                destroy();
-            }
-            catch ( Exception e )
-            {
-                LOG.error( "Encountered exception while trying to cleanup after test class: "
-                        + this.getDescription().getDisplayName(), e );
-                notifier.fireTestFailure( new Failure( getDescription(), e ) );
-            }
-        }
-    }
-
-
-    public void setSuite( CiSuite suite )
-    {
-        this.suite = suite;
-        this.settings = new InheritableSettings( getDescription(), suite.getSettings() );
-    }
-
-
-    public CiSuite getSuite()
-    {
-        return suite;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.integ;
+
+
+import java.lang.reflect.Method;
+
+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 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;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunNotifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A test runner for ApacheDS Core integration tests.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CiRunner extends JUnit4ClassRunner
+{
+    private static final Logger LOG = LoggerFactory.getLogger( CiRunner.class );
+    private CiSuite suite;
+    private InheritableSettings settings;
+
+
+    public CiRunner( Class<?> clazz ) throws InitializationError
+    {
+        super( clazz );
+    }
+
+
+    protected InheritableSettings getSettings()
+    {
+        if ( settings != null )
+        {
+            return settings;
+        }
+
+        if ( suite == null )
+        {
+            settings = new InheritableSettings( getDescription(), null );
+        }
+
+        return settings;
+    }
+
+
+    @Override
+    public void run( final RunNotifier notifier )
+    {
+        super.run( notifier );
+        Level cleanupLevel = getSettings().getCleanupLevel();
+        
+        if ( cleanupLevel == Level.CLASS )
+        {
+            try
+            {
+                shutdown();
+                cleanup();
+                destroy();
+            }
+            catch ( Exception e )
+            {
+                LOG.error( "Encountered exception while trying to cleanup after test class: "
+                        + this.getDescription().getDisplayName(), e );
+                notifier.fireTestFailure( new Failure( getDescription(), e ) );
+            }
+        }
+    }
+
+
+    @Override
+    protected void invokeTestMethod( Method method, final RunNotifier notifier )
+    {
+        LOG.debug( "About to invoke test method {}", method.getName() );
+        Description description = methodDescription( method );
+        test( getTestClass(), wrapMethod( method ), notifier, new InheritableSettings( description, getSettings() ) );
+
+        Level cleanupLevel = getSettings().getCleanupLevel();
+        
+        if ( cleanupLevel == Level.METHOD )
+        {
+            try
+            {
+                shutdown();
+                cleanup();
+                destroy();
+            }
+            catch ( Exception e )
+            {
+                LOG.error( "Encountered exception while trying to cleanup after test class: "
+                        + this.getDescription().getDisplayName(), e );
+                notifier.fireTestFailure( new Failure( getDescription(), e ) );
+            }
+        }
+    }
+
+
+    public void setSuite( CiSuite suite )
+    {
+        this.suite = suite;
+        this.settings = new InheritableSettings( getDescription(), suite.getSettings() );
+    }
+
+
+    public CiSuite getSuite()
+    {
+        return suite;
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/CiSuite.java Fri Jun  6 09:21:35 2008
@@ -1,135 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.core.integ;
-
-
-import static org.apache.directory.server.core.integ.state.TestServiceContext.shutdown;
-import static org.apache.directory.server.core.integ.state.TestServiceContext.cleanup;
-import static org.apache.directory.server.core.integ.state.TestServiceContext.destroy;
-import org.junit.internal.requests.IgnoredClassRunner;
-import org.junit.internal.runners.InitializationError;
-import org.junit.runner.Runner;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.Suite;
-
-import java.util.List;
-
-
-/**
- * A replacement for standard JUnit 4 suites. Note that this test suite
- * will not startup an DirectoryService instance but will clean it up if
- * one remains.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class CiSuite extends Suite
-{
-    private InheritableSettings settings;
-
-
-    public CiSuite( Class<?> clazz ) throws InitializationError
-    {
-        super( clazz );
-        settings = new InheritableSettings( getDescription() );
-    }
-
-
-    public void addAll( List<? extends Runner> runners )
-    {
-        for ( Runner runner : getRunners() )
-        {
-            if ( runner instanceof CiRunner )
-            {
-                CiRunner cir = ( CiRunner) runner;
-                cir.setSuite( this );
-            }
-            else if ( runner instanceof IgnoredClassRunner )
-            {
-                // allow this one
-            }
-            else
-            {
-                throw new IllegalArgumentException( String.format( "Unexpected runner type \"%s\".  " +
-                        "Test classes within CiSuites must use CiRunners.", runner ) );
-            }
-        }
-
-        super.addAll( runners );
-    }
-
-
-    public void add( Runner runner )
-    {
-        if ( runner instanceof CiRunner )
-        {
-            CiRunner cir = ( CiRunner) runner;
-            cir.setSuite( this );
-            super.add( runner );
-        }
-        else if ( runner instanceof IgnoredClassRunner )
-        {
-            // allow this one
-        }
-        else
-        {
-            throw new IllegalArgumentException( String.format( "Unexpected runner type \"%s\".  " +
-                    "Test classes within CiSuites must use CiRunners.", runner ) );
-        }
-    }
-
-
-    @Override
-    public void run( final RunNotifier notifier )
-    {
-        super.run( notifier );
-
-        /*
-         * For any service scope other than test system scope, we must have to
-         * shutdown the sevice and cleanup the working directory.  Failures to
-         * do this without exception shows that something is wrong with the
-         * server and so the entire test should be marked as failed.  So we
-         * presume that tests have failed in the suite if the fixture is in an
-         * inconsistent state.  Who knows if this inconsistent state of the
-         * service could have made it so false results were acquired while
-         * running tests.
-         */
-
-        if ( settings.getCleanupLevel() != Level.SYSTEM )
-        {
-            try
-            {
-                shutdown();
-                cleanup();
-                destroy();
-            }
-            catch ( Exception e )
-            {
-                notifier.fireTestFailure( new Failure( getDescription(), e ) );
-            }
-        }
-    }
-
-
-    public InheritableSettings getSettings()
-    {
-        return settings;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.integ;
+
+
+import java.util.List;
+
+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;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.Suite;
+
+
+/**
+ * A replacement for standard JUnit 4 suites. Note that this test suite
+ * will not startup an DirectoryService instance but will clean it up if
+ * one remains.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CiSuite extends Suite
+{
+    private InheritableSettings settings;
+
+
+    public CiSuite( Class<?> clazz ) throws InitializationError
+    {
+        super( clazz );
+        settings = new InheritableSettings( getDescription() );
+    }
+
+
+    public void addAll( List<? extends Runner> runners )
+    {
+        for ( Runner runner : getRunners() )
+        {
+            if ( runner instanceof CiRunner )
+            {
+                CiRunner cir = ( CiRunner) runner;
+                cir.setSuite( this );
+            }
+            else if ( runner instanceof IgnoredClassRunner )
+            {
+                // allow this one
+            }
+            else
+            {
+                throw new IllegalArgumentException( String.format( "Unexpected runner type \"%s\".  " +
+                        "Test classes within CiSuites must use CiRunners.", runner ) );
+            }
+        }
+
+        super.addAll( runners );
+    }
+
+
+    public void add( Runner runner )
+    {
+        if ( runner instanceof CiRunner )
+        {
+            CiRunner cir = ( CiRunner) runner;
+            cir.setSuite( this );
+            super.add( runner );
+        }
+        else if ( runner instanceof IgnoredClassRunner )
+        {
+            // allow this one
+        }
+        else
+        {
+            throw new IllegalArgumentException( String.format( "Unexpected runner type \"%s\".  " +
+                    "Test classes within CiSuites must use CiRunners.", runner ) );
+        }
+    }
+
+
+    @Override
+    public void run( final RunNotifier notifier )
+    {
+        super.run( notifier );
+
+        /*
+         * For any service scope other than test system scope, we must have to
+         * shutdown the sevice and cleanup the working directory.  Failures to
+         * do this without exception shows that something is wrong with the
+         * server and so the entire test should be marked as failed.  So we
+         * presume that tests have failed in the suite if the fixture is in an
+         * inconsistent state.  Who knows if this inconsistent state of the
+         * service could have made it so false results were acquired while
+         * running tests.
+         */
+
+        if ( settings.getCleanupLevel() != Level.SYSTEM )
+        {
+            try
+            {
+                shutdown();
+                cleanup();
+                destroy();
+            }
+            catch ( Exception e )
+            {
+                notifier.fireTestFailure( new Failure( getDescription(), e ) );
+            }
+        }
+    }
+
+
+    public InheritableSettings getSettings()
+    {
+        return settings;
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/InheritableSettings.java Fri Jun  6 09:21:35 2008
@@ -1,215 +1,271 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.directory.server.core.integ;
-
-
-import org.apache.directory.server.core.integ.annotations.*;
-import org.junit.runner.Description;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-
-/**
- * Inheritable settings of a test suite, test class, or test method.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$, $Date$
- */
-public class InheritableSettings
-{
-    /** the default setup mode to use if inheritence leads to null value */
-    public static final SetupMode DEFAULT_MODE = SetupMode.ROLLBACK;
-    /** the default factory to use if inheritence 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 */
-    private final Description description;
-    /** default level at which a service is cleaned up */
-    private static final Level DEFAULT_CLEANUP_LEVEL = Level.SUITE;
-
-
-    /**
-     * Creates a new InheritableSettings instance for test suites description.
-     *
-     * @param description junit description for the suite
-     */
-    public InheritableSettings( Description description )
-    {
-        this.description = description;
-        this.parent = null;
-    }
-
-
-    /**
-     * 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 parent the parent settings or null if the test entity is a suite
-     */
-    public InheritableSettings( Description description, InheritableSettings parent )
-    {
-        this.description = description;
-        this.parent = parent;
-
-        if ( description.isSuite() && ! isSuiteLevel() )
-        {
-            throw new IllegalStateException( String.format( "The parent must be null for %s suite",
-                    description.getDisplayName() ) );
-        }
-    }
-
-
-    public Description getDescription()
-    {
-        return description;
-    }
-
-
-    public InheritableSettings getParent()
-    {
-        return parent;
-    }
-
-
-    public boolean isSuiteLevel()
-    {
-        return parent == null;
-    }
-
-
-    public boolean isClassLevel()
-    {
-        return parent != null && parent.getParent() == null;
-    }
-
-
-    public boolean isMethodLevel()
-    {
-        return parent != null && parent.getParent() != null;
-    }
-
-
-    public SetupMode getMode()
-    {
-        SetupMode parentMode = DEFAULT_MODE;
-        if ( parent != null )
-        {
-            parentMode = parent.getMode();
-        }
-
-        Mode annotation = description.getAnnotation( Mode.class );
-        if ( annotation == null )
-        {
-            return parentMode;
-        }
-        else
-        {
-            return annotation.value();
-        }
-    }
-
-
-    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;
-        }
-        else
-        {
-            return ( DirectoryServiceFactory ) annotation.value().newInstance();
-        }
-    }
-
-
-    public List<String> getLdifs( List<String> ldifs )
-    {
-        if ( ldifs == null )
-        {
-            ldifs = new ArrayList<String>();
-        }
-
-        if ( parent != null )
-        {
-            parent.getLdifs( ldifs );
-        }
-
-        ApplyLdifs annotation = description.getAnnotation( ApplyLdifs.class );
-        if ( annotation != null && annotation.value() != null )
-        {
-            ldifs.addAll( Arrays.asList( annotation.value() ) );
-        }
-
-        return ldifs;
-    }
-
-
-    public List<String> getLdifFiles( List<String> ldifFiles )
-    {
-        if ( ldifFiles == null )
-        {
-            ldifFiles = new ArrayList<String>();
-        }
-
-        if ( parent != null )
-        {
-            parent.getLdifFiles( ldifFiles );
-        }
-
-        ApplyLdifFiles annotation = description.getAnnotation( ApplyLdifFiles.class );
-        if ( annotation != null && annotation.value() != null )
-        {
-            ldifFiles.addAll( Arrays.asList( annotation.value() ) );
-        }
-
-        return ldifFiles;
-    }
-
-
-    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;
-        }
-        else
-        {
-            return annotation.value();
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directory.server.core.integ;
+
+
+import 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.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InheritableSettings
+{
+    /** 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 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 */
+    private final Description description;
+    
+    /** default level at which a service is cleaned up */
+    private static final Level DEFAULT_CLEANUP_LEVEL = Level.SUITE;
+
+
+    /**
+     * Creates a new InheritableSettings instance for test suites description.
+     *
+     * @param description JUnit description for the suite
+     */
+    public InheritableSettings( Description description )
+    {
+        this.description = description;
+        this.parent = null;
+    }
+
+
+    /**
+     * 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 parent the parent settings or null if the test entity is a suite
+     */
+    public InheritableSettings( Description description, InheritableSettings parent )
+    {
+        this.description = description;
+        this.parent = parent;
+
+        if ( description.isSuite() && ! isSuiteLevel() )
+        {
+            throw new IllegalStateException( String.format( "The parent must be null for %s suite",
+                    description.getDisplayName() ) );
+        }
+    }
+
+
+    /**
+     * @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 <code>true</code> if we are at the method level
+     */
+    public boolean isMethodLevel()
+    {
+        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;
+        }
+        else
+        {
+            return annotation.value();
+        }
+    }
+
+
+    /**
+     * @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;
+        }
+        else
+        {
+            return ( DirectoryServiceFactory ) annotation.value().newInstance();
+        }
+    }
+
+
+    /**
+     * 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 )
+        {
+            ldifs = new ArrayList<String>();
+        }
+
+        if ( parent != null )
+        {
+            parent.getLdifs( ldifs );
+        }
+
+        ApplyLdifs annotation = description.getAnnotation( ApplyLdifs.class );
+        
+        if ( ( annotation != null ) && ( annotation.value() != null ) )
+        {
+            ldifs.addAll( Arrays.asList( annotation.value() ) );
+        }
+
+        return ldifs;
+    }
+
+
+    /**
+     * 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 )
+        {
+            ldifFiles = new ArrayList<String>();
+        }
+
+        if ( parent != null )
+        {
+            parent.getLdifFiles( ldifFiles );
+        }
+
+        ApplyLdifFiles annotation = description.getAnnotation( ApplyLdifFiles.class );
+        
+        if ( annotation != null && annotation.value() != null )
+        {
+            ldifFiles.addAll( Arrays.asList( annotation.value() ) );
+        }
+
+        return ldifFiles;
+    }
+
+
+    /**
+     * @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;
+        }
+        else
+        {
+            return annotation.value();
+        }
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/IntegrationUtils.java Fri Jun  6 09:21:35 2008
@@ -19,27 +19,28 @@
 package org.apache.directory.server.core.integ;
 
 
-import org.apache.commons.io.FileUtils;
-import org.apache.directory.server.constants.ServerDNConstants;
+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;
+import org.apache.directory.server.core.authn.LdapPrincipal;
+import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
+import org.apache.directory.shared.ldap.ldif.ChangeType;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+import org.apache.directory.shared.ldap.message.AttributeImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.directory.server.core.CoreSession;
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.server.core.jndi.ServerLdapContext;
-import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
-import org.apache.directory.shared.ldap.ldif.ChangeType;
-import org.apache.directory.shared.ldap.ldif.LdifEntry;
-import org.apache.directory.shared.ldap.ldif.LdifReader;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.name.LdapDN;
-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;
 
 
 /**
@@ -49,7 +50,8 @@
  * @version $Rev$, $Date$
  */
 public class IntegrationUtils
-{
+{
+    /** The class logger */
     private static final Logger LOG = LoggerFactory.getLogger( IntegrationUtils.class );
 
 
@@ -78,7 +80,7 @@
         }
     }
 
-
+
     /**
      * Inject an ldif String into the server. DN must be relative to the
      * root.
@@ -155,10 +157,12 @@
         {
             case( ChangeType.ADD_ORDINAL ):
                 root.createSubcontext( dn, entry.getAttributes() );
-                break;
+                break;
+                
             case( ChangeType.DELETE_ORDINAL ):
                 root.destroySubcontext( entry.getDn() );
-                break;
+                break;
+                
             case( ChangeType.MODDN_ORDINAL ):
                 LdapDN target = new LdapDN( entry.getNewSuperior() );
                 if ( entry.getNewRdn() != null )
@@ -180,7 +184,8 @@
                 }
 
                 root.rename( dn, target );
-                break;
+                break;
+                
             case( ChangeType.MODRDN_ORDINAL ):
                 target = ( LdapDN ) dn.clone();
                 target.remove( dn.size() - 1 );
@@ -197,6 +202,7 @@
 
                 root.rename( dn, target );
                 break;
+
             case( ChangeType.MODIFY_ORDINAL ):
                 root.modifyAttributes( dn, entry.getModificationItemsArray() );
                 break;

Added: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java?rev=664015&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java (added)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java Fri Jun  6 09:21:35 2008
@@ -0,0 +1,204 @@
+/*
+ * 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.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.integ.InheritableSettings;
+import org.apache.directory.server.core.integ.IntegrationUtils;
+import org.apache.directory.shared.ldap.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.ldif.LdifReader;
+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 Exception on failures to start the core directory service
+     */
+    public void startup() throws Exception
+    {
+        LOG.error( STARTUP_ERR );
+        throw new IllegalStateException( STARTUP_ERR );
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws Exception on failures to stop the core directory service
+     */
+    public void shutdown() throws Exception
+    {
+        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 Exception on failures to revert the state of the core
+     * directory service
+     */
+    public void revert() throws Exception
+    {
+        LOG.error( REVERT_ERROR );
+        throw new IllegalStateException( REVERT_ERROR );
+    }
+
+    
+    /**
+     * Inject the Ldifs if any
+     *
+     * @param service the instantiated directory service
+     * @param settings the settings containing the ldif
+     */
+    protected void injectLdifs( DirectoryService service, InheritableSettings settings )
+    {
+        List<String> ldifs = new ArrayList<String>();
+
+        ldifs =  settings.getLdifs( ldifs );
+        
+        if ( ldifs.size() != 0 )
+        {
+            for ( String ldif:ldifs )
+            {
+                try
+                {
+                    StringReader in = new StringReader( ldif );
+                    LdifReader ldifReader = new LdifReader( in );
+                    LdifEntry entry = ldifReader.next();
+                    
+                    LdapContext root = IntegrationUtils.getRootContext( service );
+                    root.createSubcontext( entry.getDn(), entry.getAttributes() );
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( "Cannot inject the following entry : {}. Error : {}.", ldif, e.getMessage() );
+                }
+            }
+        }
+    }
+}

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/NonExistentState.java Fri Jun  6 09:21:35 2008
@@ -1,160 +1,214 @@
-/*
- * 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 Exception on failures to start the core directory service
+     */
+    public void startup() throws Exception
+    {
+        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 ( Exception e )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + e );
+                    notifier.testAborted( settings.getDescription(), e );
+                    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 ( Exception e )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + e );
+                    notifier.testAborted( settings.getDescription(), e );
+                    return;
+                }
+
+                context.setState( context.getStartedPristineState() );
+                context.getState().test( testClass, testMethod, notifier, settings );
+                return;
+
+            default:
+                return;
+        }
+    }
+}

Copied: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java (from r661995, directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedRevertedState.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java?p2=directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java&p1=directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedRevertedState.java&r1=661995&r2=664015&rev=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedRevertedState.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedNormalState.java Fri Jun  6 09:21:35 2008
@@ -1,154 +1,225 @@
-/*
- * 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;
-
-
-/**
- * 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 StartedRevertedState implements TestServiceState
-{
-    private static final Logger LOG = LoggerFactory.getLogger( StartedRevertedState.class );
-    private final TestServiceContext context;
-
-
-    public StartedRevertedState( 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 Exception
-    {
-        LOG.debug( "calling shutdown()" );
-        context.getService().shutdown();
-        context.setState( context.getStoppedDirtyState() );
-    }
-
-
-    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.PRISTINE )
-        {
-            try
-            {
-                context.getState().shutdown();
-                context.getState().cleanup();
-
-                // @todo check if the factory changed here
-                if ( true ) // change this to check if factory changed since the last run
-                {
-                     context.getState().destroy();
-                     context.getState().create( settings.getFactory() );
-                }
-
-                context.getState().startup();
-            }
-            catch ( Exception e )
-            {
-                notifier.testAborted( settings.getDescription(), e );
-                return;
-            }
-
-            // state object what ever it is will handle tagging before test method
-            // invocation and it will also change the state so we can just return
-            context.getState().test( testClass, testMethod, notifier, settings );
-            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 reverted 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;
+
+
+
+/**
+ * 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 Exception on failures to start the core directory service
+     */
+    public void startup() throws Exception
+    {
+        LOG.debug( "calling startup()" );
+        context.getService().startup();
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws Exception on failures to stop the core directory service
+     */
+    public void shutdown() throws Exception
+    {
+        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 Exception on failures to revert the state of the core
+     * directory service
+     */
+    public void revert() throws Exception
+    {
+        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;
+                }
+
+                // Inject the LDIFs, if any 
+                injectLdifs( context.getService(), settings );
+                
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                
+                try
+                {
+                    revert();
+                }
+                catch ( Exception 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;
+                }
+                
+                return;
+                
+            case RESTART :
+                // Inject the LDIFs, if any 
+                injectLdifs( context.getService(), settings );
+                
+
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+
+                try
+                {
+                    shutdown();
+                }
+                catch ( Exception 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;
+                }
+                
+                try
+                {
+                    startup();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( "Failed to create and start new server instance: " + e );
+                    notifier.testAborted( settings.getDescription(), e );
+                    return;
+                }
+                
+                return;
+                
+            default:
+                return;
+        }
+    }
 }
\ No newline at end of file

Modified: directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java?rev=664015&r1=664014&r2=664015&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java (original)
+++ directory/apacheds/branches/bigbang/core-integ/src/main/java/org/apache/directory/server/core/integ/state/StartedPristineState.java Fri Jun  6 09:21:35 2008
@@ -1,124 +1,194 @@
-/*
- * 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 Exception
-    {
-        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 Exception on failures to start the core directory service
+     */
+    public void startup() throws Exception
+    {
+        LOG.debug( "calling startup()" );
+        context.getService().startup();
+    }
+
+
+    /**
+     * Action where an attempt is made to shutdown the service.
+     *
+     * @throws Exception on failures to stop the core directory service
+     */
+    public void shutdown() throws Exception
+    {
+        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:
+                // Inject the LDIFs, if any 
+                injectLdifs( context.getService(), settings );
+                
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                
+                try
+                {
+                    shutdown();
+                }
+                catch ( Exception 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;
+                }
+                
+                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;
+                }
+
+                // Inject the LDIFs, if any 
+                injectLdifs( context.getService(), settings );
+                
+                TestServiceContext.invokeTest( testClass, testMethod, notifier, settings.getDescription() );
+                context.setState( context.getStartedNormalState() );
+
+                try
+                {
+                    context.getState().revert();
+                }
+                catch ( Exception 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;
+                }
+                return;
+
+            default:
+                return;
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message