001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019 package org.apache.directory.server.integ;
020
021
022 import static org.apache.directory.server.integ.state.TestServerContext.cleanup;
023 import static org.apache.directory.server.integ.state.TestServerContext.destroy;
024 import static org.apache.directory.server.integ.state.TestServerContext.shutdown;
025
026 import org.apache.directory.server.core.integ.Level;
027 import org.junit.runner.notification.Failure;
028 import org.junit.runner.notification.RunNotifier;
029 import org.junit.runners.Suite;
030 import org.junit.runners.model.InitializationError;
031 import org.junit.runners.model.RunnerBuilder;
032
033
034 /**
035 * A replacement for standard JUnit 4 suites. Note that this test suite
036 * will not startup an DirectoryService instance but will clean it up if
037 * one remains.
038 *
039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040 * @version $Rev$, $Date$
041 */
042 public class SiSuite extends Suite
043 {
044 private InheritableServerSettings settings = new InheritableServerSettings( getDescription() );
045
046
047 public SiSuite( Class<?> clazz, RunnerBuilder builder ) throws InitializationError
048 {
049 super( clazz, builder );
050 settings = new InheritableServerSettings( getDescription() );
051 }
052
053
054 @Override
055 public void run( final RunNotifier notifier )
056 {
057 super.run( notifier );
058
059 /*
060 * For any service scope other than test system scope, we must have to
061 * shutdown the sevice and cleanup the working directory. Failures to
062 * do this without exception shows that something is wrong with the
063 * server and so the entire test should be marked as failed. So we
064 * presume that tests have failed in the suite if the fixture is in an
065 * inconsistent state. Who knows if this inconsistent state of the
066 * service could have made it so false results were acquired while
067 * running tests.
068 */
069
070 if ( settings.getCleanupLevel() != Level.SYSTEM )
071 {
072 try
073 {
074 shutdown();
075 cleanup();
076 destroy();
077 }
078 catch ( Exception e )
079 {
080 notifier.fireTestFailure( new Failure( getDescription(), e ) );
081 }
082 }
083 }
084
085
086 public InheritableServerSettings getSettings()
087 {
088 return settings;
089 }
090 }