opends/build.xml
@@ -53,6 +53,8 @@ <property name="unittest.classes.dir" location="${build.dir}/unit-tests/classes" /> <property name="unittest.package.dir" location="${build.dir}/unit-tests/package" /> <property name="unittest.report.dir" location="${build.dir}/unit-tests/report"/> @@ -577,9 +579,54 @@ <!-- Create a minimal install suitable for running unit tests. --> <target name="testpackage" depends="testinit"> <mkdir dir="${unittest.package.dir}" /> <mkdir dir="${unittest.package.dir}/bak" /> <mkdir dir="${unittest.package.dir}/classes" /> <mkdir dir="${unittest.package.dir}/config" /> <mkdir dir="${unittest.package.dir}/config/schema" /> <mkdir dir="${unittest.package.dir}/config/messages" /> <mkdir dir="${unittest.package.dir}/config/MakeLDIF" /> <mkdir dir="${unittest.package.dir}/db" /> <mkdir dir="${unittest.package.dir}/changelogDb" /> <mkdir dir="${unittest.package.dir}/ldif" /> <mkdir dir="${unittest.package.dir}/lib" /> <mkdir dir="${unittest.package.dir}/locks" /> <mkdir dir="${unittest.package.dir}/logs" /> <jar jarfile="${unittest.package.dir}/lib/OpenDS.jar" basedir="${classes.dir}" compress="true" index="true" /> <jar jarfile="${unittest.package.dir}/lib/OpenDS-tests.jar" basedir="${unittest.classes.dir}" compress="true" index="true" /> <copy todir="${unittest.package.dir}/lib"> <fileset file="${lib.dir}/*.jar" /> </copy> <copy todir="${unittest.package.dir}/config"> <fileset file="${config.dir}/*" /> </copy> <copy todir="${unittest.package.dir}/config/schema"> <fileset dir="${resource.dir}/schema" /> </copy> <copy todir="${unittest.package.dir}/config/messages"> <fileset dir="${resource.dir}/messages" /> </copy> <copy todir="${unittest.package.dir}/config/MakeLDIF"> <fileset dir="${resource.dir}/MakeLDIF" /> </copy> </target> <!-- Execute the Directory Server TestNG unit tests in text mode. --> <target name="test" depends="testinit,runtests" depends="testinit,testpackage,runtests" description="Execute the Directory Server TestNG unit tests in text mode."> </target> @@ -609,18 +656,20 @@ <path refid="run.classpath" /> <path refid="emma.lib" /> <fileset dir="${lib.dir}"> <fileset dir="${unittest.package.dir}/lib"> <include name="*.jar" /> </fileset> <fileset dir="${testng.lib.dir}"> <include name="*.jar" /> </fileset> <pathelement location="${unittest.classes.dir}" /> </classpath> <jvmarg value="-Demma.coverage.out.file=${coverage.data.dir}/coverage.emma" /> <jvmarg value="-Demma.coverage.out.merge=false" /> <jvmarg value="-Dorg.opends.server.ForceDaemonThreads=true" /> <jvmarg value="-Dorg.opends.server.ServerRoot=${unittest.package.dir}" /> <jvmarg value="-Dorg.opends.server.ConfigClass=org.opends.server.config.ConfigFileHandler" /> <jvmarg value="-Dorg.opends.server.ConfigFile=${unittest.package.dir}/config/config.ldif" /> <xmlfileset dir="${testng.dir}" includes="testng.xml" /> </testng> opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -33,11 +33,67 @@ import java.io.InputStream; import java.io.OutputStream; import org.opends.server.config.ConfigException; import org.opends.server.core.DirectoryServer; import org.opends.server.core.InitializationException; import org.opends.server.loggers.Error; import org.opends.server.loggers.Debug; /** * This class defines some utility functions which can be used by test * cases. */ public final class TestCaseUtils { /** * The name of the system property that can be used to set the fully-qualified * name of the Java class to use as the config handler. */ public static final String PROPERTY_CONFIG_CLASS = "org.opends.server.ConfigClass"; /** * The name of the system property that can be used to set the path to the * Directory Server configuration file. */ public static final String PROPERTY_CONFIG_FILE = "org.opends.server.ConfigFile"; /** * Indicates whether the server has already been started. */ private static boolean serverStarted = false; /** * Starts the Directory Server so that it will be available for use while * running the unit tests. This will only actually start the server once, so * subsequent attempts to start it will be ignored because it will already be * available. * * @throws InitializationException If a problem occurs while starting the * server. * * @throws ConfigException If there is a problem with the server * configuration. */ public static void startServer() throws InitializationException, ConfigException { if (serverStarted) { return; } String configClass = System.getProperty(PROPERTY_CONFIG_CLASS); String configFile = System.getProperty(PROPERTY_CONFIG_FILE); DirectoryServer directoryServer = DirectoryServer.getInstance(); directoryServer.bootstrapServer(); directoryServer.initializeConfiguration(configClass, configFile); Error.removeAllErrorLoggers(false); Debug.removeAllDebugLoggers(false); directoryServer.startServer(); serverStarted = true; } /** * Create a temporary directory with the specified prefix. opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestBackendImpl.java
@@ -29,7 +29,6 @@ import java.io.ByteArrayInputStream; import java.io.File; import org.opends.server.InitialDirectoryServerFixture; import org.opends.server.TestCaseUtils; import org.opends.server.api.Backend; import org.opends.server.config.ConfigEntry; @@ -71,7 +70,8 @@ */ @BeforeClass public void setUp() throws Exception { InitialDirectoryServerFixture.FACTORY.setUp(); // Make sure that the server is up and running. TestCaseUtils.startServer(); tempDir = TestCaseUtils.createTemporaryDirectory("jebtest"); homeDirName = tempDir.getAbsolutePath(); @@ -96,8 +96,6 @@ */ @AfterClass public void tearDown() throws Exception { InitialDirectoryServerFixture.FACTORY.tearDown(); TestCaseUtils.deleteDirectory(tempDir); } opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestEntryContainer.java
@@ -34,7 +34,6 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import org.opends.server.SchemaFixture; import org.opends.server.TestCaseUtils; import org.opends.server.types.Entry; import org.opends.server.types.LDIFImportConfig; @@ -131,8 +130,9 @@ */ @BeforeClass public void setUp() throws Exception { // This test suite depends on having the schema available. SchemaFixture.FACTORY.setUp(); // This test suite depends on having the schema available, so we'll make // sure the server is started. TestCaseUtils.startServer(); tempDir = TestCaseUtils.createTemporaryDirectory("jebtest"); homeDirName = tempDir.getAbsolutePath(); @@ -169,8 +169,6 @@ */ @AfterClass public void tearDown() throws Exception { SchemaFixture.FACTORY.tearDown(); TestCaseUtils.deleteDirectory(tempDir); } opends/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestJebFormat.java
@@ -33,7 +33,7 @@ import java.util.Arrays; import java.util.List; import org.opends.server.InitialDirectoryServerFixture; import org.opends.server.TestCaseUtils; import org.opends.server.core.DirectoryServer; import org.opends.server.types.Attribute; import org.opends.server.types.AttributeType; @@ -191,7 +191,8 @@ */ @Test() public void testEntryToAndFromDatabase() throws Exception { InitialDirectoryServerFixture.FACTORY.setUp(); // Make sure that the server is up and running. TestCaseUtils.startServer(); // Convert the test LDIF string to a byte array byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString); @@ -254,7 +255,5 @@ } } reader.close(); InitialDirectoryServerFixture.FACTORY.tearDown(); } } opends/tests/unit-tests-testng/src/server/org/opends/server/core/SubtreeSpecificationTestCase.java
@@ -31,7 +31,7 @@ import java.util.HashSet; import java.util.Set; import org.opends.server.SchemaFixture; import org.opends.server.TestCaseUtils; import org.opends.server.types.DN; import org.opends.server.types.Entry; import org.opends.server.types.ObjectClass; @@ -76,8 +76,9 @@ */ @BeforeClass public final void setUp() throws Exception { // This test suite depends on having the schema available. SchemaFixture.FACTORY.setUp(); // This test suite depends on having the schema available, so we'll start // the server. TestCaseUtils.startServer(); // Retrieve required object classes. objectClasses = new HashSet<ObjectClass>(); @@ -96,17 +97,6 @@ } /** * Tears down the environment for performing the tests in this suite. * * @throws Exception * If the environment could not be finalized. */ @AfterClass public final void tearDown() throws Exception { SchemaFixture.FACTORY.tearDown(); } /** * Get the common object classes. * * @return Returns the object classes. opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestDN.java
@@ -28,7 +28,7 @@ import static org.testng.Assert.*; import org.opends.server.SchemaFixture; import org.opends.server.TestCaseUtils; import org.opends.server.protocols.asn1.ASN1OctetString; import org.opends.server.types.DN; import org.opends.server.types.RDN; @@ -168,19 +168,9 @@ */ @BeforeClass public void setUp() throws Exception { // This test suite depends on having the schema available. SchemaFixture.FACTORY.setUp(); } /** * Tears down the environment for performing the tests in this suite. * * @throws Exception * If the environment could not be finalized. */ @AfterClass public void tearDown() throws Exception { SchemaFixture.FACTORY.tearDown(); // This test suite depends on having the schema available, so we'll start // the server. TestCaseUtils.startServer(); } /** opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestEntry.java
@@ -33,7 +33,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import org.opends.server.SchemaFixture; import org.opends.server.TestCaseUtils; import org.opends.server.api.SubtreeSpecificationSet; import org.opends.server.protocols.asn1.ASN1OctetString; import org.opends.server.schema.AttributeTypeSyntax; @@ -132,19 +132,9 @@ */ @BeforeClass public void setUp() throws Exception { // This test suite depends on having the schema available. SchemaFixture.FACTORY.setUp(); } /** * Tears down the environment for performing the tests in this suite. * * @throws Exception * If the environment could not be finalized. */ @AfterClass public void tearDown() throws Exception { SchemaFixture.FACTORY.tearDown(); // This test suite depends on having the schema available, so we'll start // the server. TestCaseUtils.startServer(); } /**