mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

boli
13.12.2006 b9af8f181b7495cb343c280db4ce8979a04bfc91
This commit changes several aspects of the unit test infrastructure:

- Created config-changes.ldif file in tests/unit-tests-testng/resource/. This file is applied when the test environment Directory Server starts.

- The test environment Directory Server started with TestCaseUtils.startServer() now uses non privileged ports. LDAP uses 32389 and JMX uses 33689.

- Added method getLdapPort() and getJmxPort() to retrieve the ports the test environment Directory Server is using.

- Modified current test cases to use the new ports.

- Added method getTestResource(String filename) to retrieve files the test resources folder.

- Deprecated the fixture structure for establishing a test environment Directory Server instance.

- Modified schema test cases to use TestCaseUtils.startServer() instead of the fixture framework.
10 files modified
122 ■■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/ConfigurationFixture.java 7 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/FixtureFactory.java 3 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/InitialDirectoryServerFixture.java 5 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/SchemaFixture.java 6 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/SingletonFixtureFactory.java 4 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java 43 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java 6 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java 15 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java 14 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationTestCase.java 19 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/ConfigurationFixture.java
@@ -37,6 +37,7 @@
import org.opends.server.core.DirectoryServer;
/**
 *
 * This fixture makes sure that a directory server instance is available
 * with a configuration environment loaded from the source tree's
 * resource directory.
@@ -49,6 +50,7 @@
  /**
   * A factory used to obtain the configuration fixture instance.
   */
  @Deprecated
  public static final FixtureFactory<ConfigurationFixture> FACTORY;
  static {
@@ -62,6 +64,7 @@
  /**
   * Internal factory implementation.
   */
  @Deprecated
  private static final class Factory implements
      FixtureFactory<ConfigurationFixture> {
@@ -71,6 +74,7 @@
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public ConfigurationFixture setUp() throws Exception {
      // This fixture requires the initial directory server fixture.
      InitialDirectoryServerFixture.FACTORY.setUp();
@@ -100,6 +104,7 @@
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public void tearDown() throws Exception {
      // Clean up configuration directories.
      try {
@@ -123,6 +128,7 @@
   * @param instanceRoot
   *          The name of the temporary instance root.
   */
  @Deprecated
  private ConfigurationFixture(File instanceRoot) {
    this.instanceRoot = instanceRoot;
  }
@@ -132,6 +138,7 @@
   *
   * @return The temporary instance root.
   */
  @Deprecated
  public File getInstanceRoot() {
    return instanceRoot;
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/FixtureFactory.java
@@ -28,6 +28,7 @@
package org.opends.server;
/**
 *
 * A factory interface for controlling construction and finalization of
 * fixtures.
 *
@@ -43,6 +44,7 @@
   *           If the fixture instance could not be initialized
   *           successfully.
   */
  @Deprecated
  public T setUp() throws Exception;
  /**
@@ -52,5 +54,6 @@
   * @throws Exception
   *           If the fixture instance could not be finalized.
   */
  @Deprecated
  public void tearDown() throws Exception;
}
opends/tests/unit-tests-testng/src/server/org/opends/server/InitialDirectoryServerFixture.java
@@ -32,6 +32,7 @@
import org.opends.server.core.DirectoryServer;
/**
 *
 * This fixture makes sure that a minimal directory server instance is
 * available. Only one initialization task is performed: the directory
 * server instance is created and has its
@@ -44,6 +45,7 @@
   * A factory used to obtain the initial directory server fixture
   * instance.
   */
  @Deprecated
  public static final FixtureFactory<InitialDirectoryServerFixture> FACTORY;
  static {
@@ -54,11 +56,13 @@
  /**
   * Internal factory implementation.
   */
  @Deprecated
  private static final class Factory implements
      FixtureFactory<InitialDirectoryServerFixture> {
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public InitialDirectoryServerFixture setUp() throws Exception {
      // Make sure a new instance is created.
      //
@@ -83,6 +87,7 @@
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public void tearDown() throws Exception {
      // No implementation required - no way to finalize the directory
      // server instance.
opends/tests/unit-tests-testng/src/server/org/opends/server/SchemaFixture.java
@@ -33,6 +33,7 @@
import org.opends.server.core.DirectoryServer;
/**
 *
 * This fixture makes sure that a directory server instance is available
 * with the core schema files loaded from the source tree's resource
 * directory.
@@ -45,6 +46,7 @@
  /**
   * A factory used to obtain the schema fixture instance.
   */
  @Deprecated
  public static final FixtureFactory<SchemaFixture> FACTORY;
  static {
@@ -54,12 +56,14 @@
  /**
   * Internal factory implementation.
   */
  @Deprecated
  private static final class Factory implements
      FixtureFactory<SchemaFixture> {
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public SchemaFixture setUp() throws Exception {
      // This fixture requires the configuration fixture.
      ConfigurationFixture fixture = ConfigurationFixture.FACTORY.setUp();
@@ -80,6 +84,7 @@
    /**
     * {@inheritDoc}
     */
    @Deprecated
    public void tearDown() throws Exception {
      // TODO: clean up the schema?
@@ -93,6 +98,7 @@
  /**
   * Create a schema fixture.
   */
  @Deprecated
  private SchemaFixture() {
    // No implementation required.
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/SingletonFixtureFactory.java
@@ -28,6 +28,7 @@
package org.opends.server;
/**
 *
 * A fixture factory that guarantees that at most only one instance of a
 * fixture is instantiated. The singleton factory uses reference
 * counting to guarantee that the fixture instance is torn down at the
@@ -51,6 +52,7 @@
   * @param pimpl
   *          The underlying fixture factory.
   */
  //@Deprecated
  public SingletonFixtureFactory(FixtureFactory<T> pimpl) {
    this.pimpl = pimpl;
    this.instance = null;
@@ -60,6 +62,7 @@
  /**
   * {@inheritDoc}
   */
  @Deprecated
  public T setUp() throws Exception {
    if (refCount == 0) {
      instance = pimpl.setUp();
@@ -72,6 +75,7 @@
  /**
   * {@inheritDoc}
   */
  @Deprecated
  public void tearDown() throws Exception {
    if (refCount <= 0) {
      throw new IllegalStateException("SingletonFixtureFactory tearDown "
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -86,6 +86,8 @@
    File   testRoot  = new File(buildRoot + File.separator + "build" +
                                File.separator + "unit-tests" + File.separator +
                                "package");
    File   testSrcRoot = new File(buildRoot + File.separator + "tests" +
                                  File.separator + "unit-tests-testng");
    if (testRoot.exists())
    {
@@ -104,6 +106,7 @@
    // Copy the configuration, schema, and MakeLDIF resources into the
    // appropriate place under the test package.
    File resourceDir   = new File(buildRoot, "resource");
    File testResourceDir = new File(testSrcRoot, "resource");
    File testConfigDir = new File(testRoot, "config");
    copyDirectory(new File(resourceDir, "config"), testConfigDir);
@@ -111,7 +114,8 @@
                  new File(testConfigDir, "schema"));
    copyDirectory(new File(resourceDir, "MakeLDIF"),
                  new File(testConfigDir, "MakeLDIF"));
    // FIXME -- Copy the config-changes.ldif file into place when we have one.
    copyFile     (new File(testResourceDir, "config-changes.ldif"),
                  new File(testConfigDir, "config-changes.ldif"));
    // Actually start the server and set a variable that will prevent us from
@@ -228,6 +232,43 @@
  }
  /**
   * Get the LDAP port the test environment Directory Server instance is
   * running on.
   *
   * @return The port number.
   */
  public static long getServerLdapPort()
  {
    return 32389;
  }
  /**
   * Get the JMX port the test environment Directory Server instance is
   * running on.
   *
   * @return The port number.
   */
  public static long getServerJmxPort()
  {
    return 33689;
  }
  /**
   * Method for getting a file from the test resources directory.
   *
   * @return The directory as a File
   */
  public static File getTestResource(String filename)
  {
    String buildRoot = System.getProperty(PROPERTY_BUILD_ROOT);
    File   testResourceDir = new File(buildRoot + File.separator + "tests" +
                                      File.separator + "unit-tests-testng" +
                                      File.separator + "resource");
    return new File(testResourceDir, filename);
  }
  /**
   * Prevent instantiation.
   */
  private TestCaseUtils() {
opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java
@@ -108,7 +108,7 @@
  {
    return new Object[][] {
        {"cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
            "ds-cfg-listen-port", new Long(1689)},
            "ds-cfg-listen-port", TestCaseUtils.getServerJmxPort()},
        {"cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
              "objectclass", null},
        {"cn=JMX Connection Handler,cn=Connection Handlers,cn=config",
@@ -178,6 +178,7 @@
           throws MalformedURLException, IOException
  {
    HashMap<String, String[]> env = new HashMap<String, String[]>();
    long jmxPort = TestCaseUtils.getServerJmxPort();
    // Provide the credentials required by the server to successfully
    // perform user authentication
@@ -196,7 +197,8 @@
    //
    JMXServiceURL url = new JMXServiceURL(
      "service:jmx:rmi:///jndi/rmi://localhost:1689/org.opends.server.protocols.jmx.client-unknown");
      "service:jmx:rmi:///jndi/rmi://localhost:"+ jmxPort +
          "/org.opends.server.protocols.jmx.client-unknown");
    JMXConnector jmxc = null;
    try
opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
@@ -28,7 +28,7 @@
import static org.testng.Assert.assertEquals;
import org.opends.server.SchemaFixture;
import org.opends.server.TestCaseUtils;
import org.opends.server.api.ApproximateMatchingRule;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.ByteString;
@@ -166,17 +166,6 @@
  @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();
    TestCaseUtils.startServer();
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java
@@ -26,7 +26,7 @@
 */
package org.opends.server.schema;
import org.opends.server.SchemaFixture;
import org.opends.server.TestCaseUtils;
import org.opends.server.api.EqualityMatchingRule;
import org.opends.server.core.DirectoryException;
import org.opends.server.protocols.asn1.ASN1OctetString;
@@ -216,17 +216,7 @@
  @BeforeClass
  public void setUp() throws Exception {
    // This test suite depends on having the schema available.
    SchemaFixture.FACTORY.setUp();
    TestCaseUtils.startServer();
  }
  /**
   * 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();
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/synchronization/SynchronizationTestCase.java
@@ -27,10 +27,9 @@
package org.opends.server.synchronization;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.SchemaFixture;
import org.opends.server.TestCaseUtils;
import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
/**
@@ -39,20 +38,6 @@
@Test(groups = { "precommit", "synchronization" })
public abstract class SynchronizationTestCase extends DirectoryServerTestCase
{
  /**
   * 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();
  }
  /**
   * Set up the environment for performing the tests in this suite.
@@ -64,7 +49,7 @@
  public void setUp() throws Exception
  {
    // This test suite depends on having the schema available.
    SchemaFixture.FACTORY.setUp();
    TestCaseUtils.startServer();
  }
}