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

Jean-Noel Rouvignac
11.15.2013 1a5143ec25e64ce012c5bbc9c0a15597c0ffcbc2
Decouple some tests from running the server.

EnumRightTest.java:
Now implements DirectoryServerTestCase instead of the heavyweight AciTestCase.

AciBodyTest.java, EnumRightTest.java:
Now implements DirectoryServerTestCase instead of the heavyweight AciTestCase.
Need to fake the DirectoryServer.

TestCaseUtils.java:
Added startFakeServer() method to fake the DirectoryServer.

AttributeTypeConstants.java: ADDED
1 files added
3 files modified
106 ■■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java 42 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AciBodyTest.java 11 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/EnumRightTest.java 3 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/types/AttributeTypeConstants.java 50 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -103,6 +103,8 @@
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.dsconfig.DSConfig;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeTypeConstants;
import org.opends.server.types.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryEnvironmentConfig;
@@ -113,6 +115,7 @@
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OperatingSystem;
import org.opends.server.types.ResultCode;
import org.opends.server.types.Schema;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.EmbeddedUtils;
import org.opends.server.util.LDIFReader;
@@ -248,6 +251,35 @@
  private static File testConfigDir;
  /**
   * Setup in-memory versions of everything needed to run unit tests with the
   * {@link DirectoryServer} class.
   * <p>
   * This method is trying hard to provide sensible defaults and core data you
   * would expect from a normal install, including AttributeTypes, etc.
   */
  public static void startFakeServer()
  {
    DirectoryServer.setSchema(initializeInMemory(new Schema()));
  }
  private static Schema initializeInMemory(final Schema schema)
  {
    try
    {
      for (AttributeType attributeType : AttributeTypeConstants.ALL)
      {
        schema.registerAttributeType(attributeType, true);
      }
      return schema;
    }
    catch (DirectoryException e)
    {
      // rethrow this to fail the current test
      throw new RuntimeException(e);
    }
  }
  /**
   * 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
@@ -414,8 +446,14 @@
            + "instance.loc");
        installLoc.deleteOnExit();
        FileWriter w = new FileWriter(installLoc);
        w.write(testInstanceRoot.getAbsolutePath());
        w.close();
        try
        {
          w.write(testInstanceRoot.getAbsolutePath());
        }
        finally
        {
          w.close();
        }
        if (opendmkJar.exists())
        {
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/AciBodyTest.java
@@ -28,13 +28,22 @@
import static org.assertj.core.api.Assertions.*;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class AciBodyTest extends AciTestCase
public class AciBodyTest extends DirectoryServerTestCase
{
  @BeforeClass
  public void setUp()
  {
    TestCaseUtils.startFakeServer();
  }
  @DataProvider(name = "validAcis")
  public Object[][] getValidAcis()
  {
opends/tests/unit-tests-testng/src/server/org/opends/server/authorization/dseecompat/EnumRightTest.java
@@ -33,11 +33,12 @@
import java.util.EnumSet;
import java.util.Set;
import org.opends.server.DirectoryServerTestCase;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class EnumRightTest extends AciTestCase
public class EnumRightTest extends DirectoryServerTestCase
{
  private static final int ALL_RIGHTS_MASK = ACI_READ | ACI_WRITE | ACI_ADD
opends/tests/unit-tests-testng/src/server/org/opends/server/types/AttributeTypeConstants.java
New file
@@ -0,0 +1,50 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.server.types;
import java.util.Collections;
import org.opends.server.schema.OIDSyntax;
/**
 * Holds in-memory constants representing the AttributeTypes. This allow not
 * starting the whole server for simple unit tests.
 */
@SuppressWarnings("javadoc")
public interface AttributeTypeConstants
{
  AttributeType OBJECT_CLASS = new AttributeType(
      "( 2.5.4.0 NAME 'objectClass' EQUALITY objectIdentifierMatch "
          + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 X-ORIGIN 'RFC 2256' )",
      "objectClass", Collections.singletonList("objectClass"), "2.5.4.0", null,
      null, new OIDSyntax(), AttributeUsage.USER_APPLICATIONS, false, false,
      false, false);
  AttributeType[] ALL = { OBJECT_CLASS, };
}