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

Nicolas Capponi
14.22.2016 5360b07bd36e6b3479c1bb3f911bb34f8d661b1f
OPENDJ-2413 Apply PR comments: remove builders in parameters classes, simplify configuration retrieval
Include also other minor changes and renaming
1 files deleted
21 files modified
1578 ■■■■■ changed files
opendj-embedded-server-examples/README 31 ●●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/license/THIRD-PARTY.properties 20 ●●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/main/assembly/examples.xml 2 ●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/ConfigureServer.java 63 ●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/SetupServer.java 17 ●●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/StartStopServer.java 10 ●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/src/site/xdoc/index.xml.vm 29 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/StaticUtils.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java 142 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConnectionParameters.java 243 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java 376 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServerException.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ImportParameters.java 81 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/RebuildIndexParameters.java 53 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ReplicationParameters.java 179 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/SetupParameters.java 124 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/UpgradeParameters.java 57 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/package-info.java 4 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/messages/org/opends/messages/utility.properties 36 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java 28 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/util/EmbeddedDirectoryServerTestCase.java 71 ●●●●● patch | view | raw | blame | history
opendj-embedded-server-examples/README
old mode 100644 new mode 100755
@@ -1,22 +1,33 @@
To run the examples in this module:
#! /bin/sh
# Build the whole opendj project
> maven clean install
# To run the examples in this module, you can either type the following instructions
# in a terminal or run this file
# Go to the opendj-embedded-server-examples directory
> cd opendj-embedded-server-examples
# Build the whole opendj project and then start from the opendj-embedded-server-examples directory
echo ">>> Building OpenDJ project"
#cd ..
#mvn clean install
#cd opendj-embedded-server-examples
# define the class patch to use
# Define the class path to use
export CLASSPATH=target/opendj-embedded-server-examples-4.0.0-SNAPSHOT.jar:../opendj-server-legacy/target/package/opendj/lib/opendj-slf4j-adapter.jar
echo ">>> classpath set to: $CLASSPATH"
# Choose a location for the root directory (where the directory server will be installed)
export EXAMPLE_ROOT_DIR=`pwd`/target/examples/opendj
echo ">>> root directory set to: $EXAMPLE_ROOT_DIR"
# Setup a server from the OpenDJ archive resulting from the build
# /path/to/opendj will be the root directory
java -cp $CLASSPATH org.forgerock.opendj.examples.SetupServer ../opendj-server-legacy/target/package/opendj-4.0.0-SNAPSHOT.zip /path/to/opendj
echo ">>> Example 1: setup a server"
java -cp $CLASSPATH org.forgerock.opendj.examples.SetupServer \
 ../opendj-server-legacy/target/package/opendj-4.0.0-SNAPSHOT.zip $EXAMPLE_ROOT_DIR
# Then you can run any of the example using the installed server
# Start and stop the server
java -cp $CLASSPATH /path/to/opendj
echo ">>> Example 2: start and stop the server"
java -cp $CLASSPATH org.forgerock.opendj.examples.StartStopServer $EXAMPLE_ROOT_DIR
# Read and update the configuration of the server
java -cp $CLASSPATH /path/to/opendj "dc=example,dc=com"
echo ">>> Example 3: read and update configuration of the server"
java -cp $CLASSPATH org.forgerock.opendj.examples.ConfigureServer $EXAMPLE_ROOT_DIR "dc=example,dc=com"
opendj-embedded-server-examples/src/license/THIRD-PARTY.properties
File was deleted
opendj-embedded-server-examples/src/main/assembly/examples.xml
@@ -18,7 +18,7 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
                              http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>examples</id>
  <id>opendj-embedded-server-examples</id>
  <includeBaseDirectory>false</includeBaseDirectory>
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/ConfigureServer.java
@@ -19,17 +19,26 @@
import static java.util.Arrays.asList;
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.util.embedded.ConnectionParameters.connectionParams;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServer;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServer;
import java.io.File;
import java.io.IOException;
import java.util.ConcurrentModificationException;
import java.util.SortedSet;
import org.forgerock.opendj.config.AdminException;
import org.forgerock.opendj.config.DefinitionDecodingException;
import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
import org.forgerock.opendj.config.ManagedObjectNotFoundException;
import org.forgerock.opendj.config.client.ManagedObjectDecodingException;
import org.forgerock.opendj.config.client.ManagementContext;
import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
import org.forgerock.opendj.config.client.OperationRejectedException;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.server.config.client.BackendCfgClient;
import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.opends.server.util.embedded.EmbeddedDirectoryServer;
import org.opends.server.util.embedded.EmbeddedDirectoryServer.DirectoryConfigReader;
import org.opends.server.util.embedded.EmbeddedDirectoryServer.DirectoryConfigUpdater;
import org.opends.server.util.embedded.EmbeddedDirectoryServerException;
/**
@@ -50,8 +59,15 @@
     *            The command line arguments: serverRootDir newBaseDn [ldapPort]
     * @throws EmbeddedDirectoryServerException
     *          If an error occurs
     * @throws org.forgerock.opendj.config.client.ConcurrentModificationException
     * @throws ManagedObjectNotFoundException
     * @throws ManagedObjectDecodingException
     * @throws DefinitionDecodingException
     * @throws OperationRejectedException
     * @throws MissingMandatoryPropertiesException
     * @throws ManagedObjectAlreadyExistsException
     */
    public static void main(final String[] args) throws EmbeddedDirectoryServerException {
    public static void main(final String[] args) {
        if (args.length != 2 && args.length != 3) {
            System.err.println("Usage: serverRootDir newBaseDn [ldapPort]");
            System.exit(1);
@@ -61,41 +77,28 @@
        final int ldapPort = args.length > 2 ? Integer.parseInt(args[2]) : 1500;
        EmbeddedDirectoryServer server =
                defineServer(
                manageEmbeddedDirectoryServer(
                        configParams()
                            .serverRootDirectory(serverRootDir)
                            .configurationFile(serverRootDir + File.separator + "config/config.ldif")
                            .build(),
                            .configurationFile(serverRootDir + File.separator + "config/config.ldif"),
                        connectionParams()
                            .hostName("localhost")
                            .ldapPort(ldapPort)
                            .bindDn("cn=Directory Manager")
                            .bindPassword("password")
                            .build(),
                            .bindPassword("password"),
                        System.out,
                        System.err);
        // read the current base DN(s) of user backend
        SortedSet<DN> baseDns = server.readConfiguration(new DirectoryConfigReader<SortedSet<DN>>() {
            @Override
            public SortedSet<DN> read(RootCfgClient rootConfig) throws Exception {
                BackendCfgClient userRoot = rootConfig.getBackend("userRoot");
                return userRoot.getBaseDN();
            }
        });
        System.out.println("The current base Dn(s) of the user backend are: " + baseDns);
        // modify the base DN of the user backend
        server.updateConfiguration(new DirectoryConfigUpdater() {
            @Override
            public void update(RootCfgClient rootConfig) throws Exception {
                BackendCfgClient userRoot = rootConfig.getBackend("userRoot");
                userRoot.setBaseDN(asList(DN.valueOf(newBaseDn)));
                userRoot.commit();
            }
        });
        System.out.println("The base Dn of the user backend has been set to: " + newBaseDn);
        // read the current base DN(s) of user backend and update it
        try (ManagementContext config = server.getConfiguration()) {
            BackendCfgClient userRoot = config.getRootConfiguration().getBackend("userRoot");
            System.out.println("The current base Dn(s) of the user backend are: " + userRoot.getBaseDN());
            userRoot.setBaseDN(asList(DN.valueOf(newBaseDn)));
            userRoot.commit();
            System.out.println("The base Dn of the user backend has been set to: " + newBaseDn);
        } catch (AdminException | IOException | EmbeddedDirectoryServerException e) {
            System.err.println("A problem occured when reading/updating configuration: " + e.toString());
        }
    }
    private ConfigureServer() {
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/SetupServer.java
@@ -18,7 +18,7 @@
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.util.embedded.ConnectionParameters.connectionParams;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServer;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServer;
import static org.opends.server.util.embedded.SetupParameters.setupParams;
import java.io.File;
@@ -73,28 +73,25 @@
            final String backendType, final int ldapPort, final int adminPort, final int jmxPort)
            throws EmbeddedDirectoryServerException {
        EmbeddedDirectoryServer server =
                defineServer(
                manageEmbeddedDirectoryServer(
                        configParams()
                            .serverRootDirectory(serverRootDir)
                            .configurationFile(serverRootDir + File.separator + "config/config.ldif")
                            .build(),
                            .configurationFile(serverRootDir + File.separator + "config/config.ldif"),
                        connectionParams()
                            .hostName("localhost")
                            .ldapPort(ldapPort)
                            .bindDn("cn=Directory Manager")
                            .bindPassword("password")
                            .adminPort(adminPort)
                            .build(),
                            .adminPort(adminPort),
                        System.out,
                        System.err);
        server.setupFromArchive(
                new File(openDJArchive),
        server.extractArchiveForSetup(new File(openDJArchive));
        server.setup(
                setupParams()
                    .baseDn(baseDn)
                    .backendType(backendType)
                    .jmxPort(jmxPort)
                    .build());
                    .jmxPort(jmxPort));
    }
    private SetupServer() {
opendj-embedded-server-examples/src/main/java/org/forgerock/opendj/examples/StartStopServer.java
@@ -17,9 +17,10 @@
package org.forgerock.opendj.examples;
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServerForStartStopOperations;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServerForStartStop;
import java.io.File;
import java.nio.file.Paths;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.util.embedded.EmbeddedDirectoryServer;
import org.opends.server.util.embedded.EmbeddedDirectoryServerException;
@@ -47,11 +48,10 @@
        final String serverRootDir = args[0];
        final EmbeddedDirectoryServer server =
                defineServerForStartStopOperations(
                manageEmbeddedDirectoryServerForStartStop(
                        configParams()
                            .serverRootDirectory(serverRootDir)
                            .configurationFile(serverRootDir + File.separator + "config/config.ldif")
                            .build(),
                            .configurationFile(Paths.get(serverRootDir, "config", "config.ldif").toString()),
                            System.out,
                            System.err);
opendj-embedded-server-examples/src/site/xdoc/index.xml.vm
@@ -43,34 +43,5 @@
      </ul>
    </section>
<!--
    <section name="Documentation for ${project.name}">
      <p>
        Javadoc for this module can be found <a href="apidocs/index.html">here</a>.
      </p>
    </section>
    <section name="Get ${project.name}">
      <p>
        You can get ${project.name} using any of the following methods:
      </p>
      <subsection name="Download">
        <p>
          Pre-built binaries can be downloaded directly from the ForgeRock Maven
          repository:
        </p>
        <ul>
          <li><a href="${mavenRepoReleases}/org/forgerock/opendj/${project.artifactId}">Stable releases</a></li>
          <li><a href="${mavenRepoSnapshots}/org/forgerock/opendj/${project.artifactId}/${project.version}">Latest development snapshot</a></li>
        </ul>
      </subsection>
      <subsection name="Build">
        <p>
          For the DIY enthusiasts you can build it yourself by checking out the
          latest code using <a href="source-repository.html">Subversion</a> and
          building it with Maven 3.
        </p>
      </subsection>
    </section>
-->
  </body>
</document>
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java
@@ -17,7 +17,7 @@
package org.opends.server.tools.dsreplication;
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServerForStartStopOperations;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServerForStartStop;
import static org.opends.messages.AdminToolMessages.*;
import org.forgerock.i18n.LocalizableMessage;
@@ -89,11 +89,10 @@
    try
    {
      EmbeddedDirectoryServer server = defineServerForStartStopOperations(
      EmbeddedDirectoryServer server = manageEmbeddedDirectoryServerForStartStop(
          configParams()
            .configurationFile(configFile)
            .disableConnectionHandlers(true)
            .build());
            .disableConnectionHandlers(true));
      server.start();
    }
    catch (OpenDsException ode)
opendj-server-legacy/src/main/java/org/opends/server/util/StaticUtils.java
@@ -2503,7 +2503,7 @@
      ZipEntry fileEntry;
      while ((fileEntry = zipStream.getNextEntry()) != null)
      {
        File targetFile = new File(targetDirectory.getPath() + File.separator +  fileEntry.getName());
        File targetFile = new File(targetDirectory.getPath(), fileEntry.getName());
        if (fileEntry.isDirectory())
        {
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java
@@ -15,11 +15,7 @@
 */
package org.opends.server.util.embedded;
import org.forgerock.util.Reject;
/**
 * Parameters to configure a directory server.
 */
/** Parameters to configure a directory server. */
public final class ConfigParameters
{
  private String serverRootDirectory;
@@ -29,17 +25,17 @@
  private ConfigParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
   * Creates a builder for the configuration parameters.
   * Creates configuration parameters.
   *
   * @return a builder
   * @return the parameters
   */
  public static Builder configParams()
  public static ConfigParameters configParams()
  {
    return new Builder();
    return new ConfigParameters();
  }
  String getServerRootDirectory()
@@ -47,7 +43,7 @@
    return serverRootDirectory;
  }
  /** This value may be {@code null}, it must always  be checked. */
  /** This value may be {@code null}, it must always be checked. */
  String getServerInstanceDirectory()
  {
    return serverInstanceDirectory;
@@ -64,86 +60,58 @@
  }
  /**
   * Builder for this class.
   * Sets the server root directory of the directory server.
   * <p>
   * The server root is the location where the binaries and default configuration is stored.
   *
   * @param dir
   *          the server root directory
   * @return this builder
   */
  public static final class Builder
  public ConfigParameters serverRootDirectory(String dir)
  {
    private ConfigParameters params;
    serverRootDirectory = dir;
    return this;
  }
    private Builder()
    {
      params = new ConfigParameters();
    }
  /**
   * Sets the install root directory of the directory server.
   * <p>
   * The install root is the location where the data and live configuration is stored.
   *
   * @param dir
   *          the install root directory
   * @return this builder
   */
  public ConfigParameters serverInstanceDirectory(String dir)
  {
    serverInstanceDirectory = dir;
    return this;
  }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the replication parameters
     */
    public ConfigParameters toParams()
    {
      ConfigParameters p = params;
      Reject.ifNull(p.serverRootDirectory, p.configurationFile);
      this.params = new ConfigParameters();
      return p;
    }
  /**
   * Sets the path of the configuration file of the directory server.
   *
   * @param file
   *          the configuration file
   * @return this builder
   */
  public ConfigParameters configurationFile(String file)
  {
    configurationFile = file;
    return this;
  }
    /**
     * Sets the server root directory of the directory server.
     * <p>
     * The server root is the location where the binaries and default configuration is stored.
     *
     * @param dir
     *          the server root directory
     * @return this builder
     */
    public Builder serverRootDirectory(String dir)
    {
      params.serverRootDirectory = dir;
      return this;
    }
    /**
     * Sets the install root directory of the directory server.
     * <p>
     * The install root is the location where the data and live configuration is stored.
     *
     * @param dir
     *          the install root directory
     * @return this builder
     */
    public Builder serverInstanceDirectory(String dir)
    {
      params.serverInstanceDirectory = dir;
      return this;
    }
    /**
     * Sets the path of the configuration file of the directory server.
     *
     * @param file
     *          the configuration file
     * @return this builder
     */
    public Builder configurationFile(String file)
    {
      params.configurationFile = file;
      return this;
    }
    /**
     * Sets the indicator allowing to disable the connection handlers.
     *
     * @param disable
     *          {@code true} to disable the connection handlers
     * @return this builder
     */
    public Builder disableConnectionHandlers(boolean disable)
    {
      params.disableConnectionHandlers = disable;
      return this;
    }
  /**
   * Sets the indicator allowing to disable the connection handlers.
   *
   * @param disable
   *          {@code true} to disable the connection handlers
   * @return this builder
   */
  public ConfigParameters disableConnectionHandlers(boolean disable)
  {
    disableConnectionHandlers = disable;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConnectionParameters.java
@@ -15,9 +15,7 @@
 */
package org.opends.server.util.embedded;
/**
 * Parameters to establish connections to a directory server.
 */
/** Parameters to establish connections to a directory server. */
public final class ConnectionParameters
{
  private String adminPassword;
@@ -25,22 +23,24 @@
  private String adminUid;
  private String bindDn;
  private String bindPassword;
  private String hostname;
  private String hostName;
  private Integer ldapPort;
  private Integer ldapsPort;
  private boolean enableStartTLS;
  private ConnectionParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
   * Creates a builder for the connection parameters.
   * Creates connection parameters.
   *
   * @return a builder
   * @return the parameters
   */
  public static Builder connectionParams()
  public static ConnectionParameters connectionParams()
  {
    return new Builder();
    return new ConnectionParameters();
  }
  String getAdminPassword()
@@ -68,9 +68,9 @@
    return bindPassword;
  }
  String getHostname()
  String getHostName()
  {
    return hostname;
    return hostName;
  }
  Integer getLdapPort()
@@ -78,121 +78,130 @@
    return ldapPort;
  }
  /**
   * Builder for the ConnectionParameters class.
   */
  public static final class Builder
  Integer getLdapSecurePort()
  {
    private ConnectionParameters params;
    return ldapsPort;
  }
    private Builder()
    {
      params = new ConnectionParameters();
    }
  boolean isStartTLSEnabled()
  {
    return enableStartTLS;
  }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the replication parameters
     */
    public ConnectionParameters toParams()
    {
      ConnectionParameters p = params;
      this.params = new ConnectionParameters();
      return p;
    }
  /**
   * Sets the password of the Global Administrator to use to bind to the server.
   *
   * @param password
   *          the password
   * @return this builder
   */
  public ConnectionParameters adminPassword(String password)
  {
    adminPassword = password;
    return this;
  }
    /**
     * Sets the password of the Global Administrator to use to bind to the server.
     *
     * @param password
     *          the password
     * @return this builder
     */
    public Builder adminPassword(String password)
    {
      params.adminPassword = password;
      return this;
    }
  /**
   * Sets the port for directory server administration.
   *
   * @param port
   *          the admin port
   * @return this builder
   */
  public ConnectionParameters adminPort(int port)
  {
    adminPort = port;
    return this;
  }
    /**
     * Sets the port for directory server administration.
     *
     *  @param port
     *          the admin port
     * @return this builder
     */
    public Builder adminPort(int port)
    {
      params.adminPort = port;
      return this;
    }
  /**
   * Sets the user id of the Global Administrator to use to bind to the server.
   *
   * @param uid
   *          the user id
   * @return this builder
   */
  public ConnectionParameters adminUid(String uid)
  {
    adminUid = uid;
    return this;
  }
    /**
     * Sets the user id of the Global Administrator to use to bind to the server.
     *
     * @param uid
     *          the user id
     * @return this builder
     */
    public Builder adminUid(String uid)
    {
      params.adminUid = uid;
      return this;
    }
  /**
   * Sets the Dn to use to bind to the directory server.
   *
   * @param dn
   *          the bind Dn
   * @return this builder
   */
  public ConnectionParameters bindDn(String dn)
  {
    bindDn = dn;
    return this;
  }
    /**
     * Sets the Dn to use to bind to the directory server.
     *
     * @param dn
     *          the bind Dn
     * @return this builder
     */
    public Builder bindDn(String dn)
    {
      params.bindDn = dn;
      return this;
    }
  /**
   * Sets the password to use to bind to the directory server.
   *
   * @param password
   *          the bind password
   * @return this builder
   */
  public ConnectionParameters bindPassword(String password)
  {
    bindPassword = password;
    return this;
  }
    /**
     * Sets the password to use to bind to the directory server.
     *
     * @param password
     *          the bind password
     * @return this builder
     */
    public Builder bindPassword(String password)
    {
      params.bindPassword = password;
      return this;
    }
  /**
   * Sets the start TLS indicator.
   *
   * @param startTLS
   *          the indicator which should be {@code true} to enable StartTLS, {@code false} otherwise
   * @return this builder
   */
  public ConnectionParameters enableStartTLS(boolean startTLS)
  {
    enableStartTLS = startTLS;
    return this;
  }
    /**
     * Sets the the fully-qualified directory server host name.
     *
     * @param hostname
     *          the hostname of the server
     * @return this builder
     */
    public Builder hostname(String hostname)
    {
      params.hostname = hostname;
      return this;
    }
  /**
   * Sets the the fully-qualified directory server host name.
   *
   * @param hostName
   *          the hostName of the server
   * @return this builder
   */
  public ConnectionParameters hostName(String hostName)
  {
    this.hostName = hostName;
    return this;
  }
    /**
     * Sets the port on which the directory server listen for LDAP communication.
     *
     * @param port
     *          the LDAP port
     * @return this builder
     */
    public Builder ldapPort(int port)
    {
      params.ldapPort = port;
      return this;
    }
  /**
   * Sets the port on which the directory server listens for LDAP communication.
   *
   * @param port
   *          the LDAP port
   * @return this builder
   */
  public ConnectionParameters ldapPort(int port)
  {
    ldapPort = port;
    return this;
  }
  /**
   * Sets the port on which the directory server listens for LDAPS (secure) communication.
   *
   * @param port
   *          the LDAPS port
   * @return this builder
   */
  public ConnectionParameters ldapSecurePort(int port)
  {
    ldapsPort = port;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java
@@ -15,6 +15,7 @@
 */
package org.opends.server.util.embedded;
import static org.opends.messages.UtilityMessages.ERR_EMBEDDED_SERVER_LDIF_MANAGEMENT_CONTEXT;
import static org.opends.server.util.ServerConstants.*;
import static org.forgerock.opendj.config.client.ldap.LDAPManagementContext.newManagementContext;
import static org.forgerock.opendj.config.client.ldap.LDAPManagementContext.newLDIFManagementContext;
@@ -23,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Paths;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.adapter.server3x.Adapters;
@@ -34,10 +36,10 @@
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SimpleBindRequest;
import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.forgerock.util.Options;
import org.forgerock.util.Pair;
import org.forgerock.util.Reject;
import org.opends.quicksetup.TempLogFile;
import org.opends.server.config.ConfigConstants;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.ImportLDIF;
@@ -48,6 +50,7 @@
import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.util.DynamicConstants;
import org.opends.server.util.StaticUtils;
/**
@@ -57,9 +60,9 @@
public class EmbeddedDirectoryServer
{
  private static final String EMBEDDED_OPEN_DJ_PREFIX = "embeddedOpenDJ";
  private static final String ARCHIVE_ROOT_DIRECTORY = DynamicConstants.SHORT_NAME.toLowerCase();
  private static final String QUICKSETUP_ROOT_PROPERTY = "org.opends.quicksetup.Root";
  private static final String QUICKSETUP_INSTANCE_PROPERTY = "org.opends.quicksetup.Root";
  private static final String QUICKSETUP_INSTANCE_PROPERTY = "org.opends.quicksetup.instance";
  /** The parameters for install and instance directories, and configuration file of the server. */
  private final ConfigParameters configParams;
@@ -76,22 +79,23 @@
  /** The error stream used for feedback during operations on server. */
  private final OutputStream errStream;
  /**
   * Defines an embedded directory server, providing the output and error streams used for
   * giving feedback during operations on the server.
   *
   * @param configParams
   *          The basic configuration parameters for the server.
   * @param connParams
   *          The connection parameters for the server.
   * @param out
   *          Output stream used for feedback during operations on server
   * @param err
   *          Error stream used for feedback during operations on server
   */
  private EmbeddedDirectoryServer(ConfigParameters configParams, ConnectionParameters connParams,
      OutputStream out, OutputStream err)
  {
    Reject.ifNull(configParams.getServerRootDirectory());
    if (connParams != null)
    {
      Reject.ifNull(
        connParams.getHostName(),
        connParams.getLdapPort(),
        connParams.getBindDn(),
        connParams.getBindPassword());
    }
    if (configParams.getConfigurationFile() == null)
    {
      // use the default path if configuration file is not provided
      configParams.configurationFile(getDefaultConfigurationFilePath(configParams.getServerRootDirectory()));
    }
    this.configParams = configParams;
    this.connectionParams = connParams;
    this.outStream = out;
@@ -101,7 +105,7 @@
      SimpleBindRequest authRequest = Requests.newSimpleBindRequest(
          connectionParams.getBindDn(), connectionParams.getBindPassword().toCharArray());
      ldapConnectionFactory = new LDAPConnectionFactory(
          connectionParams.getHostname(),
          connectionParams.getHostName(),
          connectionParams.getLdapPort(),
          Options.defaultOptions().set(LDAPConnectionFactory.AUTHN_BIND_REQUEST, authRequest));
    }
@@ -111,23 +115,21 @@
    }
  }
  /**
   * Defines an embedded directory server.
   * <p>
   * Output/error streams used for giving feedback during operations are default system ones.
   *
   * @param configParams
   *          The basic configuration parameters for the server.
   * @param connParams
   *          The connection parameters for the server.
   */
  private EmbeddedDirectoryServer(ConfigParameters configParams, ConnectionParameters connParams)
  {
    this(configParams, connParams, System.out, System.err);
  }
  private static String getDefaultConfigurationFilePath(String serverRootDirectory)
  {
    return Paths.get(serverRootDirectory)
        .resolve(ConfigConstants.CONFIG_DIR_NAME)
        .resolve(ConfigConstants.CONFIG_FILE_NAME)
        .toString();
  }
  /**
   * Defines an embedded directory server for any operation.
   * Creates an instance of an embedded directory server for any operation.
   *
   * @param configParams
   *          The basic configuration parameters for the server.
@@ -137,16 +139,16 @@
   *          Output stream used for feedback during operations on server
   * @param err
   *          Error stream used for feedback during operations on server
   * @return the directory server
   * @return the embedded directory server
   */
  public static EmbeddedDirectoryServer defineServer(ConfigParameters configParams,
  public static EmbeddedDirectoryServer manageEmbeddedDirectoryServer(ConfigParameters configParams,
      ConnectionParameters connParams, OutputStream out, OutputStream err)
  {
    return new EmbeddedDirectoryServer(configParams, connParams, out, err);
  }
  /**
   * Defines an embedded directory server for start/stop operation.
   * Creates an instance of an embedded directory server for start/stop operation.
   * <p>
   * To be able to perform any operation on the server, use the alternative {@code defineServer()}
   * method.
@@ -159,14 +161,14 @@
   *          Error stream used for feedback during operations on server
   * @return the directory server
   */
  public static EmbeddedDirectoryServer defineServerForStartStopOperations(ConfigParameters configParams,
  public static EmbeddedDirectoryServer manageEmbeddedDirectoryServerForStartStop(ConfigParameters configParams,
      OutputStream out, OutputStream err)
  {
    return new EmbeddedDirectoryServer(configParams, null, out, err);
  }
  /**
   * Defines an embedded directory server for start/stop operation.
   * Creates an instance of an embedded directory server for start/stop operation.
   * <p>
   * To be able to perform any operation on the server, use the alternative {@code defineServer()}
   * method.
@@ -175,41 +177,17 @@
   *          The basic configuration parameters for the server.
   * @return the directory server
   */
  public static EmbeddedDirectoryServer defineServerForStartStopOperations(ConfigParameters configParams)
  public static EmbeddedDirectoryServer manageEmbeddedDirectoryServerForStartStop(
      ConfigParameters configParams)
  {
    return new EmbeddedDirectoryServer(configParams, null, System.out, System.err);
  }
  /**
   * Displays the replication status on the output stream defined for this server.
   * <p>
   * Displays a list with the basic replication configuration of all base DNs of
   * the servers defined in the registration information.
   *
   * @param parameters
   *            The parameters for the replication.
   * @throws EmbeddedDirectoryServerException
   *            If a problem occurs.
   */
  public void displayReplicationStatus(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    int returnCode = ReplicationCliMain.mainCLI(
        parameters.toCommandLineArgumentsStatus(configParams.getConfigurationFile(), connectionParams),
        !isRunning(), outStream, errStream);
    if (returnCode != 0)
    {
      throw new EmbeddedDirectoryServerException(
          ERR_EMBEDDED_SERVER_DISPLAY_REPLICATION_STATUS.get(configParams.getServerRootDirectory(), returnCode));
    }
  }
  /**
   * Enables replication between this directory server (first server) and another server
   * Configures replication between this directory server (first server) and another server
   * (second server).
   * <p>
   * Updates the configuration of the servers to replicate the data under the
   * This method updates the configuration of the servers to replicate the data under the
   * base DN specified in the parameters.
   *
   * @param parameters
@@ -217,18 +195,70 @@
   * @throws EmbeddedDirectoryServerException
   *            If a problem occurs.
   */
  public void enableReplication(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
  public void configureReplication(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Reject.checkNotNull(connectionParams);
    int returnCode = ReplicationCliMain.mainCLI(
        parameters.toCommandLineArgumentsEnable(configParams.getConfigurationFile(), connectionParams),
        parameters.toCommandLineArgumentsConfiguration(configParams.getConfigurationFile(), connectionParams),
        !isRunning(), outStream, errStream);
    if (returnCode != 0)
    {
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_ENABLE_REPLICATION.get(
          configParams.getServerRootDirectory(), parameters.getReplicationPort1(), parameters.getHostname2(),
          parameters.getReplicationPort2(), returnCode));
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_CONFIGURE_REPLICATION.get(
          configParams.getServerRootDirectory(), parameters.getReplicationPortSource(),
          parameters.getHostnameDestination(), parameters.getReplicationPortDestination(), returnCode));
    }
  }
  /**
   * Returns the configuration of this server, which can be read or updated.
   * <p>
   * The returned object is an instance of {@code ManagementContext} class, which allow access to the
   * root configuration object using its {@code getRootConfiguration()} method.
   * Starting from the root configuration, it is possible to access any configuration object, in order
   * to perform read or update operations.
   * <p>
   * Note that {@code ManagementContext} instance must be closed after usage. It is recommended to use
   * it inside a try-with-resource statement.
   * <p>
   * Example reading configuration:
   * <pre>
   *   try(ManagementContext config = server.getConfiguration()) {
   *      List<String> syncProviders = config.getRootConfiguration().listSynchronizationProviders();
   *      System.out.println("sync providers=" + syncProviders);
   *   }
   * </pre>
   * <p>
   * Example updating configuration:
   * <pre>
   *   try(ManagementContext config = server.getConfiguration()) {
   *      JEBackendCfgClient userRoot = (JEBackendCfgClient) config.getRootConfiguration().getBackend("userRoot");
   *      userRoot.setBaseDN(Arrays.asList(DN.valueOf("dc=example,dc=com")));
   *      userRoot.setDBCachePercent(70);
   *      // changes must be committed to be effective
   *      userRoot.commit();
   *   }
   * </pre>
   * @return the management context object which gives direct access to the root configuration of the server
   * @throws EmbeddedDirectoryServerException
   *            If the retrieval of the configuration fails
   */
  @SuppressWarnings("resource")
  public ManagementContext getConfiguration() throws EmbeddedDirectoryServerException
  {
    try
    {
      if (isRunning())
      {
        Connection ldapConnection = ldapConnectionFactory.getConnection();
        return newManagementContext(ldapConnection, LDAPProfile.getInstance());
      }
      return newLDIFManagementContext(new File(configParams.getConfigurationFile()));
    }
    catch (IOException e)
    {
      throw new EmbeddedDirectoryServerException(
          ERR_EMBEDDED_SERVER_LDIF_MANAGEMENT_CONTEXT.get(configParams.getConfigurationFile()));
    }
  }
@@ -263,11 +293,10 @@
   * @throws EmbeddedDirectoryServerException
   *            If the import fails
   */
  public void importData(ImportParameters parameters) throws EmbeddedDirectoryServerException
  public void importLDIF(ImportParameters parameters) throws EmbeddedDirectoryServerException
  {
    checkServerIsRunning();
    checkConnectionParameters();
    int returnCode = ImportLDIF.mainImportLDIF(
    Reject.checkNotNull(connectionParams);    int returnCode = ImportLDIF.mainImportLDIF(
        parameters.toCommandLineArguments(configParams.getConfigurationFile(), connectionParams),
        !isRunning(), outStream, errStream);
@@ -288,7 +317,7 @@
   */
  public void initializeReplication(ReplicationParameters parameters) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Reject.checkNotNull(connectionParams);
    int returnCode = ReplicationCliMain.mainCLI(
        parameters.toCommandLineArgumentsInitialize(configParams.getConfigurationFile(), connectionParams),
        !isRunning(), outStream, errStream);
@@ -296,12 +325,28 @@
    if (returnCode != 0)
    {
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_INITIALIZE_REPLICATION.get(
          configParams.getServerRootDirectory(), connectionParams.getAdminPort(), parameters.getHostname2(),
          parameters.getAdminPort2(), returnCode));
          configParams.getServerRootDirectory(), connectionParams.getAdminPort(), parameters.getHostnameDestination(),
          parameters.getAdminPortDestination(), returnCode));
    }
  }
  /**
   * Indicates whether replication is currently running for the embedded server.
   *
   * @param parameters
   *            The parameters for the replication.
   * @return {@code true} if replication is running, {@code false} otherwise
   */
  public boolean isReplicationRunning(ReplicationParameters parameters)
  {
    Reject.checkNotNull(connectionParams);
    int returnCode = ReplicationCliMain.mainCLI(
        parameters.toCommandLineArgumentsStatus(configParams.getConfigurationFile(), connectionParams),
        !isRunning(), outStream, errStream);
    return returnCode == 0;
  }
  /**
   * Indicates whether this server is currently running.
   *
   * @return {@code true} if the server is currently running, or {@code false} if not.
@@ -312,50 +357,7 @@
  }
  /**
   * Reads the configuration of this server with the provided configuration reader.
   * <p>
   * The configuration reader provides access to the root configuration of the directory,
   * which can then be used to read any configuration object and return the result as an
   * arbitrary object.
   * <p>
   * Example:
   * <pre>
   * server.readConfiguration(new DirectoryConfigReader<List<String>>() {
   *   public List<String> read(RootCfgClient rootConfig) {
   *    return Arrays.asList(rootConfig.listSynchronizationProviders());
   *   }
   * });
   * </pre>
   * @param <R>
   *          the type of the returned result
   * @param configReader
   *          the reader of the configuration
   * @return the result of the read
   * @throws EmbeddedDirectoryServerException
   *            If the read fails
   */
  public <R> R readConfiguration(DirectoryConfigReader<R> configReader) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Pair<ManagementContext, Connection> contextAndConnection = getManagementContext();
    try
    {
      RootCfgClient rootConfig = contextAndConnection.getFirst().getRootConfiguration();
      return configReader.read(rootConfig);
    }
    catch (Exception e)
    {
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_READ_CONFIG.get(
          configParams.getServerRootDirectory(), StaticUtils.stackTraceToSingleLineString(e)));
    }
    finally
    {
      StaticUtils.close(contextAndConnection.getFirst(), contextAndConnection.getSecond());
    }
  }
  /**
   * Setups this server from the root directory.
   * Set this server up from the root directory.
   * <p>
   * As a pre-requisite, the OpenDJ archive must have been previously extracted to some
   * directory. To perform a setup directly from an archive, see {@code setupFromArchive()}.
@@ -367,8 +369,7 @@
   */
  public void setup(SetupParameters parameters) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Reject.checkNotNull(connectionParams);
    System.setProperty(PROPERTY_SERVER_ROOT, configParams.getServerRootDirectory());
    System.setProperty(QUICKSETUP_ROOT_PROPERTY, configParams.getServerRootDirectory());
    String instanceDir = configParams.getServerInstanceDirectory() != null ?
@@ -388,27 +389,26 @@
  }
  /**
   * Setups this server from the provided archive.
   * Extracts the provided archive to the appropriate root directory of the server.
   * <p>
   * As the DJ archive includes the "opendj" directory, it is mandatory to have
   * the root directory named "opendj" when using this method.
   * the root directory named after it when using this method.
   *
   * @param openDJZipFile
   *            The OpenDJ server archive.
   * @param parameters
   *            The installation parameters.
   * @throws EmbeddedDirectoryServerException
   *            If the setup fails for any reason.
   *            If the extraction of the archive fails.
   */
  public void setupFromArchive(File openDJZipFile, SetupParameters parameters) throws EmbeddedDirectoryServerException
  public void extractArchiveForSetup(File openDJZipFile) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Reject.checkNotNull(connectionParams);
    try
    {
      File serverRoot = new File(configParams.getServerRootDirectory());
      if (!serverRoot.getName().equals("opendj"))
      if (!ARCHIVE_ROOT_DIRECTORY.equals(serverRoot.getName()))
      {
        throw new EmbeddedDirectoryServerException(LocalizableMessage.raw("Wrong server root directory" + serverRoot));
        throw new EmbeddedDirectoryServerException(
            ERR_EMBEDDED_SERVER_ARCHIVE_SETUP_WRONG_ROOT_DIRECTORY.get(ARCHIVE_ROOT_DIRECTORY, serverRoot));
      }
      // the directory where the zip file is extracted should be one level up from the server root.
      File deployDirectory = serverRoot.getParentFile();
@@ -419,7 +419,6 @@
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_SETUP_EXTRACT_ARCHIVE.get(
          openDJZipFile, configParams.getServerRootDirectory(), StaticUtils.stackTraceToSingleLineString(e)));
    }
    setup(parameters);
  }
  /**
@@ -522,47 +521,6 @@
  }
  /**
   * Configures this server with the provided configuration updater.
   * <p>
   * The configuration updater provides access to the root configuration of the directory server,
   * which can then be used to perform one or more modifications on any configuration object.
   * <p>
   * Example:
   * <pre>
   * server.configure(new DirectoryConfigUpdater() {
   *
   *   public void update(RootCfgClient rootConfig) {
   *     JEBackendCfgClient userRoot = (JEBackendCfgClient) rootConfig.getBackend("userRoot");
   *     userRoot.setBaseDN(Arrays.asList(DN.valueOf("dc=example,dc=com")));
   *     userRoot.setDBCachePercent(70);
   *     userRoot.commit();
   *   }
   * });
   * </pre>
   *
   * @param configUpdater
   *            updates the configuration
   * @throws EmbeddedDirectoryServerException
   *            If an error occurs.
   */
  public void updateConfiguration(DirectoryConfigUpdater configUpdater) throws EmbeddedDirectoryServerException
  {
    checkConnectionParameters();
    Pair<ManagementContext, Connection> contextAndConnection = getManagementContext();
    try {
      RootCfgClient rootConfig = contextAndConnection.getFirst().getRootConfiguration();
      configUpdater.update(rootConfig);
    } catch (Exception e) {
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_UPDATE_CONFIG.get(
          configParams.getServerRootDirectory(), StaticUtils.stackTraceToSingleLineString(e)));
    }
    finally
    {
      StaticUtils.close(contextAndConnection.getFirst(), contextAndConnection.getSecond());
    }
  }
  /**
   * Upgrades this server.
   * <p>
   * Upgrades the server configuration and application data so that it is compatible
@@ -585,56 +543,11 @@
    }
  }
  /**
   * Interface to update the configuration of the directory server.
   */
  public interface DirectoryConfigUpdater
  {
    /**
     * Updates the configuration, provided the root configuration object of the directory server.
     *
     * @param rootConfig
     *          The root configuration of the server.
     * @throws Exception
     *          If an error occurs.
     */
    public void update(RootCfgClient rootConfig) throws Exception;
  }
  /**
   * Interface to read the configuration of the directory server.
   *
   * @param <R>
   *            The type of the result returned by the read operation.
   */
  public interface DirectoryConfigReader<R>
  {
    /**
     * Reads the configuration, provided the root configuration object of the directory server.
     *
     * @param rootConfig
     *          The root configuration of the server.
     * @return the result of the read operation
     * @throws Exception
     *          If an error occurs.
     */
    public R read(RootCfgClient rootConfig) throws Exception;
  }
  private void checkConnectionParameters() throws EmbeddedDirectoryServerException
  {
    if (connectionParams == null)
    {
      throw new EmbeddedDirectoryServerException(LocalizableMessage.raw("Operation is not permitted"));
    }
  }
  private void checkServerIsRunning() throws EmbeddedDirectoryServerException
  {
    if (!isRunning())
    {
      throw new EmbeddedDirectoryServerException(LocalizableMessage.raw(
          "This operation is only available when server is online"));
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_IMPORT_DATA_SERVER_IS_NOT_RUNNING.get());
    }
  }
@@ -642,35 +555,8 @@
  {
    if (isRunning())
    {
      throw new EmbeddedDirectoryServerException(LocalizableMessage.raw(
          "This operation is only available when server is offline"));
    }
  }
      throw new EmbeddedDirectoryServerException(ERR_EMBEDDED_SERVER_REBUILD_INDEX_SERVER_IS_RUNNING.get());
  /**
   * Retrieves the management context, and optionally a connection if the server is running, in order to
   * give access to the configuration of the server.
   */
  private Pair<ManagementContext, Connection> getManagementContext() throws EmbeddedDirectoryServerException
  {
    Connection ldapConnection = null;
    ManagementContext ctx = null;
    try
    {
      if (isRunning())
      {
        ldapConnection = ldapConnectionFactory.getConnection();
        ctx = newManagementContext(ldapConnection, LDAPProfile.getInstance());
      }
      else
      {
        ctx = newLDIFManagementContext(new File(configParams.getConfigurationFile()));
      }
      return Pair.of(ctx, ldapConnection);
    }
    catch (IOException e)
    {
      throw new EmbeddedDirectoryServerException(LocalizableMessage.raw("Error when initialising LDIF mgt ctx"));
    }
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServerException.java
@@ -22,11 +22,10 @@
 * Exception that may be thrown by an embedded directory server if a problem occurs while
 * performing an operation on the server.
 */
@SuppressWarnings("serial")
public final class EmbeddedDirectoryServerException extends OpenDsException
{
  private static final long serialVersionUID = 1L;
  /**
   * Creates a new exception with the provided message.
   *
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ImportParameters.java
@@ -15,9 +15,7 @@
 */
package org.opends.server.util.embedded;
/**
 * Parameters to import LDIF data to a directory server.
 */
/** Parameters to import LDIF data to a directory server. */
public final class ImportParameters
{
  private String backendID;
@@ -25,17 +23,17 @@
  private ImportParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
   * Creates a builder for the import parameters.
   * Creates the import parameters.
   *
   * @return a builder
   * @return parameters
   */
  public static Builder importParams()
  public static ImportParameters importParams()
  {
    return new Builder();
    return new ImportParameters();
  }
  /**
@@ -62,55 +60,28 @@
  }
  /**
   * Builder for this class.
   * Sets the backend id of the backend to import.
   *
   * @param id
   *          the backend id
   * @return this builder
   */
  public static final class Builder
  public ImportParameters backendId(String id)
  {
    private ImportParameters params;
    backendID = id;
    return this;
  }
    private Builder()
    {
      params = new ImportParameters();
    }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the replication parameters
     */
    public ImportParameters toParams()
    {
      ImportParameters p = params;
      this.params = new ImportParameters();
      return p;
    }
    /**
     * Sets the backend id of the backend to import.
     *
     * @param id
     *          the backend id
     * @return this builder
     */
    public Builder backendId(String id)
    {
      params.backendID = id;
      return this;
    }
    /**
     * Sets the path to the LDIF file to be imported.
     *
     * @param ldifFile
     *          The path to the LDIF file
     * @return this builder
     */
    public Builder ldifFile(String ldifFile)
    {
      params.ldifFile = ldifFile;
      return this;
    }
  /**
   * Sets the path to the LDIF file to be imported.
   *
   * @param ldifFile
   *          The path to the LDIF file
   * @return this builder
   */
  public ImportParameters ldifFile(String ldifFile)
  {
    this.ldifFile = ldifFile;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/RebuildIndexParameters.java
@@ -15,16 +15,14 @@
 */
package org.opends.server.util.embedded;
/**
 * Parameters to rebuild the indexes of a directory server.
 */
/** Parameters to rebuild the indexes of a directory server. */
public final class RebuildIndexParameters
{
  private String baseDN;
  private RebuildIndexParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
@@ -32,9 +30,9 @@
   *
   * @return a builder
   */
  public static Builder rebuildIndexParams()
  public static RebuildIndexParameters rebuildIndexParams()
  {
    return new Builder();
    return new RebuildIndexParameters();
  }
  /**
@@ -53,42 +51,15 @@
  }
  /**
   * Builder for this class.
   * Sets the base Dn for user information in the directory server.
   *
   * @param baseDN
   *          the baseDN
   * @return this builder
   */
  public static final class Builder
  public RebuildIndexParameters baseDN(String baseDN)
  {
    private RebuildIndexParameters params;
    private Builder()
    {
      params = new RebuildIndexParameters();
    }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the rebuild index parameters
     */
    public RebuildIndexParameters toParams()
    {
      RebuildIndexParameters p = params;
      this.params = new RebuildIndexParameters();
      return p;
    }
    /**
     * Sets the base Dn for user information in the directory server.
     *
     * @param baseDN
     *          the baseDN
     * @return this builder
     */
    public Builder baseDN(String baseDN)
    {
      params.baseDN = baseDN;
      return this;
    }
    this.baseDN = baseDN;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ReplicationParameters.java
@@ -15,19 +15,17 @@
 */
package org.opends.server.util.embedded;
/**
 * Parameters for replication operations on a directory server.
 */
/** Parameters for replication operations on a directory server. */
public final class ReplicationParameters
{
  private String baseDn;
  private Integer replicationPort1;
  private Integer replicationPort2;
  private ConnectionParameters connParamsForHost2;
  private Integer replicationPortSource;
  private Integer replicationPortDestination;
  private ConnectionParameters connParamsForDestination;
  private ReplicationParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
@@ -35,32 +33,32 @@
   *
   * @return a builder
   */
  public static Builder replicationParams()
  public static ReplicationParameters replicationParams()
  {
    return new Builder();
    return new ReplicationParameters();
  }
  /**
   * Generates the command-line arguments for enabling replication, from the parameters.
   * Generates the command-line arguments for configuring replication, from the parameters.
   *
   * @return command-line arguments
   */
  String[] toCommandLineArgumentsEnable(String configurationFile, ConnectionParameters connParams)
  String[] toCommandLineArgumentsConfiguration(String configurationFile, ConnectionParameters connParams)
  {
    return new String[] {
      "enable",
      "--no-prompt",
      "--configFile", configurationFile,
      "--host1", connParams.getHostname(),
      "--host1", connParams.getHostName(),
      "--port1", s(connParams.getAdminPort()),
      "--bindDN1", connParams.getBindDn(),
      "--bindPassword1", connParams.getBindPassword(),
      "--replicationPort1", s(replicationPort1),
      "--host2", connParamsForHost2.getHostname(),
      "--port2", s(connParamsForHost2.getAdminPort()),
      "--bindDN2", connParamsForHost2.getBindDn(),
      "--bindPassword2", connParamsForHost2.getBindPassword(),
      "--replicationPort2", s(replicationPort2),
      "--replicationPort1", s(replicationPortSource),
      "--host2", connParamsForDestination.getHostName(),
      "--port2", s(connParamsForDestination.getAdminPort()),
      "--bindDN2", connParamsForDestination.getBindDn(),
      "--bindPassword2", connParamsForDestination.getBindPassword(),
      "--replicationPort2", s(replicationPortDestination),
      "--adminUID", connParams.getAdminUid(),
      "--adminPassword", connParams.getAdminPassword(),
      "--baseDN", baseDn,
@@ -79,10 +77,10 @@
      "initialize",
      "--no-prompt",
      "--configFile", configurationFile,
      "--hostSource", connParams.getHostname(),
      "--hostSource", connParams.getHostName(),
      "--portSource", s(connParams.getAdminPort()),
      "--hostDestination", connParamsForHost2.getHostname(),
      "--portDestination", s(connParamsForHost2.getAdminPort()),
      "--hostDestination", connParamsForDestination.getHostName(),
      "--portDestination", s(connParamsForDestination.getAdminPort()),
      "--adminUID", connParams.getAdminUid(),
      "--adminPassword", connParams.getAdminPassword(),
      "--baseDN", baseDn,
@@ -101,7 +99,7 @@
      "status",
      "--no-prompt",
      "--configFile", configurationFile,
      "--hostname", connParams.getHostname(),
      "--hostname", connParams.getHostName(),
      "--port", s(connParams.getAdminPort()),
      "--adminUID", connParams.getAdminUid(),
      "--adminPassword", connParams.getAdminPassword(),
@@ -109,24 +107,24 @@
      "--noPropertiesFile" };
  }
  int getReplicationPort1()
  int getReplicationPortSource()
  {
    return replicationPort1;
    return replicationPortSource;
  }
  int getReplicationPort2()
  int getReplicationPortDestination()
  {
    return replicationPort2;
    return replicationPortDestination;
  }
  String getHostname2()
  String getHostnameDestination()
  {
    return connParamsForHost2.getHostname();
    return connParamsForDestination.getHostName();
  }
  int getAdminPort2()
  int getAdminPortDestination()
  {
    return connParamsForHost2.getAdminPort();
    return connParamsForDestination.getAdminPort();
  }
  /** Convert an integer to a String. */
@@ -136,84 +134,57 @@
  }
  /**
   * Builder for this class.
   * Sets the base Dn of the data to be replicated.
   *
   * @param baseDn
   *          the base Dn
   * @return this builder
   */
  public static final class Builder
  public ReplicationParameters baseDn(String baseDn)
  {
    private ReplicationParameters params;
    this.baseDn = baseDn;
    return this;
  }
    private Builder()
    {
      params = new ReplicationParameters();
    }
  /**
   * Sets the replication port of the first server (source) whose contents will be replicated.
   * <p>
   * The source server should correspond to the embedded server on which the replication operation is
   * applied.
   *
   * @param port
   *          the replication port
   * @return this builder
   */
  public ReplicationParameters replicationPortSource(int port)
  {
    this.replicationPortSource = port;
    return this;
  }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the replication parameters
     */
    public ReplicationParameters toParams()
    {
      ReplicationParameters p = params;
      this.params = new ReplicationParameters();
      return p;
    }
  /**
   * Sets the replication port of the second server (destination) whose contents will be replicated.
   *
   * @param port
   *          the replication port
   * @return this builder
   */
  public ReplicationParameters replicationPortDestination(int port)
  {
    this.replicationPortDestination = port;
    return this;
  }
    /**
     * Sets the base Dn of the data to be replicated.
     *
     * @param baseDn
     *          the base Dn
     * @return this builder
     */
    public Builder baseDn(String baseDn)
    {
      params.baseDn = baseDn;
      return this;
    }
    /**
     * Sets the replication port of the first server whose contents will be replicated.
     * <p>
     * The first server should correspond to the embedded server on which the replication
     * operation is applied.
     *
     * @param port
     *          the replication port
     * @return this builder
     */
    public Builder replicationPort1(int port)
    {
      params.replicationPort1 = port;
      return this;
    }
    /**
     * Sets the replication port of the second server whose contents will be replicated.
     *
     * @param port
     *          the replication port
     * @return this builder
     */
    public Builder replicationPort2(int port)
    {
      params.replicationPort2 = port;
      return this;
    }
    /**
     * Sets the connection parameters of the second server whose contents will be replicated.
     *
     * @param host2Params
     *          The connection parameters
     * @return this builder
     */
    public Builder connectionParamsForHost2(ConnectionParameters.Builder host2Params)
    {
      params.connParamsForHost2 = host2Params.toParams();
      return this;
    }
  /**
   * Sets the connection parameters of the second server (destination) whose contents will be replicated.
   *
   * @param destinationParams
   *          The connection parameters for destination server
   * @return this builder
   */
  public ReplicationParameters connectionParamsForDestination(ConnectionParameters destinationParams)
  {
    this.connParamsForDestination = destinationParams;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/SetupParameters.java
@@ -15,9 +15,11 @@
 */
package org.opends.server.util.embedded;
/**
 * Parameters to setup a directory server.
 */
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** Parameters to setup a directory server. */
public final class SetupParameters
{
  private String baseDn;
@@ -26,7 +28,7 @@
  private SetupParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
@@ -34,9 +36,9 @@
   *
   * @return a builder
   */
  public static Builder setupParams()
  public static SetupParameters setupParams()
  {
    return new Builder();
    return new SetupParameters();
  }
  /**
@@ -46,14 +48,14 @@
   */
  String[] toCommandLineArguments(ConnectionParameters connParams)
  {
    return new String[] {
    String[] baseArgs = new String[] {
      "--cli",
      "--noPropertiesFile",
      "--no-prompt",
      "--doNotStart",
      "--skipPortCheck",
      "--baseDN", baseDn,
      "--hostname", connParams.getHostname(),
      "--hostname", connParams.getHostName(),
      "--rootUserDN", connParams.getBindDn(),
      "--rootUserPassword", connParams.getBindPassword(),
      "--ldapPort", s(connParams.getLdapPort()),
@@ -61,6 +63,21 @@
      "--jmxPort", s(jmxPort),
      "--backendType", backendType
    };
    List<String> args = new ArrayList<>(Arrays.asList(baseArgs));
    if (connParams.getLdapSecurePort() != null)
    {
      args.add("--ldapsPort");
      args.add(s(connParams.getLdapSecurePort()));
    }
    if (connParams.isStartTLSEnabled())
    {
      args.add("--enableStartTLS");
    }
    if (connParams.getLdapSecurePort() != null || connParams.isStartTLSEnabled())
    {
      args.add("--generateSelfSignedCertificate");
    }
    return args.toArray(new String[args.size()]);
  }
  String getBaseDn()
@@ -80,68 +97,41 @@
  }
  /**
   * Builder for this class.
   * Sets the base Dn for user information in the directory server.
   *
   * @param baseDn
   *          the base Dn
   * @return this builder
   */
  public static final class Builder
  public SetupParameters baseDn(String baseDn)
  {
    private SetupParameters params;
    this.baseDn = baseDn;
    return this;
  }
    private Builder()
    {
      params = new SetupParameters();
    }
  /**
   * Sets the port on which the directory server should listen for JMX communication.
   *
   * @param jmxPort
   *          the JMX port
   * @return this builder
   */
  public SetupParameters jmxPort(int jmxPort)
  {
    this.jmxPort = jmxPort;
    return this;
  }
    /**
     * Generates the parameters from this builder.
     * <p>
     * After this call, the builder is reset and can be used to generate other parameters.
     *
     * @return the replication parameters
     */
    public SetupParameters toParams()
    {
      SetupParameters p = params;
      this.params = new SetupParameters();
      return p;
    }
    /**
     * Sets the base Dn for user information in the directory server.
     *
     * @param baseDn
     *          the base Dn
     * @return this builder
     */
    public Builder baseDn(String baseDn)
    {
      params.baseDn = baseDn;
      return this;
    }
    /**
     * Sets the port on which the directory server should listen for JMX communication.
     *
     * @param jmxPort
     *          the JMX port
     * @return this builder
     */
    public Builder jmxPort(int jmxPort)
    {
      params.jmxPort = jmxPort;
      return this;
    }
    /**
     * Sets the type of the backend containing user information.
     *
     * @param backendType
     *          the backend type (e.g. je, pdb)
     * @return this builder
     */
    public Builder backendType(String backendType)
    {
      params.backendType = backendType;
      return this;
    }
  /**
   * Sets the type of the backend containing user information.
   *
   * @param backendType
   *          the backend type (e.g. je, pdb)
   * @return this builder
   */
  public SetupParameters backendType(String backendType)
  {
    this.backendType = backendType;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/UpgradeParameters.java
@@ -18,16 +18,14 @@
import java.util.ArrayList;
import java.util.List;
/**
 * Parameters to upgrade a Directory Server.
 */
/** Parameters to upgrade a Directory Server. */
public final class UpgradeParameters
{
  private boolean ignoreErrors;
  private UpgradeParameters()
  {
    // private constructor to force usage of the associated Builder
    // prefer usage of static method for creation
  }
  /**
@@ -35,9 +33,9 @@
   *
   * @return this builder
   */
  public static Builder upgradeParams()
  public static UpgradeParameters upgradeParams()
  {
    return new Builder();
    return new UpgradeParameters();
  }
  /**
@@ -60,43 +58,18 @@
  }
  /**
   * Builder for the UpgradeParameters class.
   * Indicates whether errors should be ignored during the upgrade.
   * <p>
   * This option should be used with caution and may be useful in automated deployments where
   * potential errors are known in advance and resolved after the upgrade has completed
   *
   * @param ignore
   *          indicates whether errors should be ignored
   * @return this builder
   */
  public static final class Builder
  public UpgradeParameters isIgnoreErrors(boolean ignore)
  {
    private UpgradeParameters params;
    private Builder()
    {
      params = new UpgradeParameters();
    }
    /**
     * Returns the fully initialized parameters.
     *
     * @return the parameters
     */
    public UpgradeParameters toParams()
    {
      UpgradeParameters p = params;
      this.params = new UpgradeParameters();
      return p;
    }
    /**
     * Indicates whether errors should be ignored during the upgrade.
     * <p>
     * This option should be used with caution and may be useful in automated deployments where
     * potential errors are known in advance and resolved after the upgrade has completed
     *
     * @param ignore
     *          indicates whether errors should be ignored
     * @return this builder
     */
    public Builder isIgnoreErrors(boolean ignore)
    {
      params.ignoreErrors = ignore;
      return this;
    }
    ignoreErrors = ignore;
    return this;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/util/embedded/package-info.java
@@ -13,7 +13,5 @@
 *
 * Copyright 2016 ForgeRock AS.
 */
/**
 * Provides support for an embedded directory server.
 */
/** Provides support for an embedded directory server. */
package org.opends.server.util.embedded;
opendj-server-legacy/src/messages/org/opends/messages/utility.properties
@@ -406,34 +406,36 @@
ERR_BACKUP_CANNOT_CREATE_SAVE_DIRECTORY_326=An error occurred while \
 attempting to create a save directory with base path %s before restore of \
 backup of %s: %s
ERR_EMBEDDED_SERVER_DISPLAY_REPLICATION_STATUS_327=An error occurred while attempting \
 to display replication status of embedded server with server root '%s'. Error code \
 is: %s
ERR_EMBEDDED_SERVER_ENABLE_REPLICATION_328=An error occurred while attempting \
 to enable replication between embedded server with server root '%s' and replication \
 port1 '%s' and second server with hostname '%s' and replication port2 '%s'. Error code \
 is: %s
ERR_EMBEDDED_SERVER_CONFIGURE_REPLICATION_328=An error occurred while attempting \
 to configure replication between embedded server with server root '%s' and source replication \
 port '%s' and destination server with hostname '%s' and destination replication port '%s'. Error code \
 is: %d
ERR_EMBEDDED_SERVER_IMPORT_DATA_329=An error occurred while attempting \
 to import LDIF file '%s' into embedded server with server root '%s'. Error code \
 is: %s
 is: %d
ERR_EMBEDDED_SERVER_INITIALIZE_REPLICATION_330=An error occurred while attempting \
 to initialize replication between embedded server with server root '%s' and admin \
 port1 '%s' and second server with hostname '%s' and admin port2 '%s'. Error code \
 is: %s
ERR_EMBEDDED_SERVER_READ_CONFIG_331=An error occurred while attempting \
 to read configuration of embedded server with server root '%s' : %s
 source port '%s' and destination server with hostname '%s' and destination admin port '%s'. Error code \
 is: %d
ERR_EMBEDDED_SERVER_SETUP_332=An error occurred while attempting \
 to setup the embedded server with server root '%s', base DN '%s' and backend type '%s'. \
 Error code is: %s
 Error code is: %d
ERR_EMBEDDED_SERVER_SETUP_EXTRACT_ARCHIVE_333=An error occurred while attempting \
 to extract server archive '%s' before setup of embedded server with server root '%s': %s
ERR_EMBEDDED_SERVER_REBUILD_INDEX_334=An error occurred while attempting \
 to rebuild index of embedded server with server root '%s'. Error code is: %s
ERR_EMBEDDED_SERVER_UPDATE_CONFIG_335=An error occurred while attempting \
 to update configuration of embedded server with server root '%s' : %s
 to rebuild index of embedded server with server root '%s'. Error code is: %d
ERR_EMBEDDED_SERVER_START_336=An error occurred while attempting \
 to start the embedded server with server root '%s' : %s
ERR_EMBEDDED_SERVER_UPGRADE_337=An error occurred while attempting \
 to upgrade the embedded server with server root '%s' : %s
ERR_EMBEDDED_SERVER_INTERNAL_CONNECTION=An error occurred while attempting to retrieve \
 an internal connection to the server with the user DN '%s'
 an internal connection to the server with the user DN '%s'
ERR_EMBEDDED_SERVER_ARCHIVE_SETUP_WRONG_ROOT_DIRECTORY=The setup from an archive \
 can only be done with a server root directory named after the root directory contained \
 in the archive: '%s'. The provided server root was: '%s'
ERR_EMBEDDED_SERVER_IMPORT_DATA_SERVER_IS_NOT_RUNNING=The import data operation could \
 not be performed on the embedded server because it is not running
ERR_EMBEDDED_SERVER_REBUILD_INDEX_SERVER_IS_RUNNING=The rebuild index operation could \
 not be performed on the embedded server because it is running
ERR_EMBEDDED_SERVER_LDIF_MANAGEMENT_CONTEXT=An error occurred while attempting to \
 read the configuration file '%s'
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -17,7 +17,7 @@
 */
package org.opends.server;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServer;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServer;
import static org.opends.server.util.embedded.ConnectionParameters.connectionParams;
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.loggers.TextAccessLogPublisher.getStartupTextAccessPublisher;
@@ -266,10 +266,13 @@
      String buildDirStr = System.getProperty(PROPERTY_BUILD_DIR, buildRoot + File.separator + "target");
      buildDir = new File(buildDirStr);
      unitRoot  = new File(buildDir, "unit-tests");
      if (installedRoot == null) {
      if (installedRoot == null)
      {
         testInstallRoot = new File(unitRoot, "package-install");
         testInstanceRoot = new File(unitRoot, "package-instance");
      } else {
      }
      else
      {
         testInstallRoot = new File(unitRoot, "package");
         testInstanceRoot = testInstallRoot;
      }
@@ -309,24 +312,15 @@
        return;
      }
      InvocationCounterPlugin.resetStartupCalled();
      initializePortsAndServer();
      deployDirectoryDirsAndFiles();
      setupLoggers();
      writeBuildInfoFile();
      server.start();
      assertTrue(InvocationCounterPlugin.startupCalled());
      // Save config.ldif for when we restart the server
      backupServerConfigLdif();
      SERVER_STARTED = true;
      initializeTestBackend(true);
    }
    catch (Exception e)
@@ -340,19 +334,17 @@
  {
    ports = new TestPorts();
    hostname = InetAddress.getLocalHost().getHostName();
    server = defineServer(
    server = manageEmbeddedDirectoryServer(
        configParams()
          .serverRootDirectory(paths.testInstallRoot.getPath())
          .serverInstanceDirectory(paths.testInstanceRoot.getPath())
          .configurationFile(paths.configFile.getPath())
          .toParams(),
          .configurationFile(paths.configFile.getPath()),
        connectionParams()
          .bindDn("cn=Directory Manager")
          .bindPassword("password")
          .hostname(hostname)
          .hostName(hostname)
          .ldapPort(ports.serverLdapPort)
          .adminPort(ports.serverAdminPort)
          .toParams(),
          .adminPort(ports.serverAdminPort),
         System.out,
         System.err);
  }
opendj-server-legacy/src/test/java/org/opends/server/util/EmbeddedDirectoryServerTestCase.java
@@ -15,9 +15,10 @@
 */
package org.opends.server.util;
import static org.opends.server.util.embedded.SetupParameters.setupParams;
import static org.opends.server.util.embedded.ConfigParameters.configParams;
import static org.opends.server.util.embedded.ConnectionParameters.connectionParams;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.defineServer;
import static org.opends.server.util.embedded.EmbeddedDirectoryServer.manageEmbeddedDirectoryServer;
import static org.opends.server.util.embedded.ImportParameters.importParams;
import static org.opends.server.util.embedded.UpgradeParameters.upgradeParams;
import static org.opends.server.util.embedded.RebuildIndexParameters.rebuildIndexParams;
@@ -29,17 +30,14 @@
import java.util.SortedSet;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.client.ManagementContext;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.server.config.client.BackendCfgClient;
import org.forgerock.opendj.server.config.client.RootCfgClient;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.util.embedded.EmbeddedDirectoryServer;
import org.opends.server.util.embedded.EmbeddedDirectoryServer.DirectoryConfigReader;
import org.opends.server.util.embedded.EmbeddedDirectoryServer.DirectoryConfigUpdater;
import org.opends.server.util.embedded.EmbeddedDirectoryServerException;
import org.opends.server.util.embedded.SetupParameters;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -116,16 +114,13 @@
    }
  }
  private void readConfiguration(EmbeddedDirectoryServer server) throws EmbeddedDirectoryServerException
  private void readConfiguration(EmbeddedDirectoryServer server) throws Exception
  {
    SortedSet<DN> dns = server.readConfiguration(new DirectoryConfigReader<SortedSet<DN>>() {
          @Override
          public SortedSet<DN> read(RootCfgClient rootConfig) throws Exception
          {
            return rootConfig.getBackend(USER_ROOT).getBaseDN();
          }
        });
    assertThat(dns).containsExactly(DN.valueOf("dc=example,dc=com"));
    try (ManagementContext config = server.getConfiguration())
    {
      SortedSet<DN> dns = config.getRootConfiguration().getBackend(USER_ROOT).getBaseDN();
      assertThat(dns).containsExactly(DN.valueOf("dc=example,dc=com"));
    }
  }
  public void testReadConfigurationOnline() throws Exception
@@ -148,16 +143,12 @@
  private void toggleBackendActivation(EmbeddedDirectoryServer server, final boolean enabled) throws Exception
  {
    server.updateConfiguration(new DirectoryConfigUpdater()
    try (ManagementContext config = server.getConfiguration())
    {
      @Override
      public void update(RootCfgClient rootConfig) throws Exception
      {
        BackendCfgClient backend = rootConfig.getBackend(USER_ROOT);
        backend.setEnabled(enabled);
        backend.commit();
      }
    });
      BackendCfgClient backend = config.getRootConfiguration().getBackend(USER_ROOT);
      backend.setEnabled(enabled);
      backend.commit();
    }
  }
  /**
@@ -170,7 +161,7 @@
    server.stop(getClass().getSimpleName(), LocalizableMessage.raw("stopping for rebuild index test"));
    try
    {
      server.rebuildIndex(rebuildIndexParams().baseDN("dc=example,dc=com").build());
      server.rebuildIndex(rebuildIndexParams().baseDN("dc=example,dc=com"));
    }
    finally
    {
@@ -182,7 +173,7 @@
  @Test(expectedExceptions = EmbeddedDirectoryServerException.class)
  public void testRebuildIndexOnline() throws Exception
  {
    getServer().rebuildIndex(rebuildIndexParams().baseDN("dc=example,dc=com").build());
    getServer().rebuildIndex(rebuildIndexParams().baseDN("dc=example,dc=com"));
  }
  /**
@@ -195,7 +186,7 @@
    server.stop(getClass().getSimpleName(), LocalizableMessage.raw("stopping for upgrade test"));
    try
    {
      server.upgrade(upgradeParams().isIgnoreErrors(false).build());
      server.upgrade(upgradeParams().isIgnoreErrors(false));
    }
    finally
    {
@@ -209,16 +200,15 @@
   */
  public void testUpgradeOnline() throws Exception
  {
    getServer().upgrade(upgradeParams().isIgnoreErrors(false).build());
    getServer().upgrade(upgradeParams().isIgnoreErrors(false));
  }
  public void testImportDataOnline() throws Exception
  {
    EmbeddedDirectoryServer server = getServer();
    server.importData(importParams()
    server.importLDIF(importParams()
        .backendId("userRoot")
        .ldifFile(TestCaseUtils.getTestResource("test-import-file.ldif").getPath())
        .build());
        .ldifFile(TestCaseUtils.getTestResource("test-import-file.ldif").getPath()));
  }
  /** Import data is not implemented for offline use in EmbeddedDirectoryServer.*/
@@ -229,10 +219,9 @@
    server.stop(getClass().getSimpleName(), LocalizableMessage.raw("stopping for import data test"));
    try
    {
      server.importData(importParams()
      server.importLDIF(importParams()
          .backendId("userRoot")
          .ldifFile(TestCaseUtils.getTestResource("test-import-file.ldif").getPath())
          .build());
          .ldifFile(TestCaseUtils.getTestResource("test-import-file.ldif").getPath()));
    }
    finally
    {
@@ -251,27 +240,25 @@
      StaticUtils.recursiveDelete(rootDir);
      final int[] ports = TestCaseUtils.findFreePorts(3);
      EmbeddedDirectoryServer tempServer = defineServer(
      EmbeddedDirectoryServer tempServer = manageEmbeddedDirectoryServer(
        configParams()
          .serverRootDirectory(rootDir.getPath())
          .configurationFile(rootDir.toPath().resolve("config").resolve("config.ldif").toString())
          .build(),
          .configurationFile(rootDir.toPath().resolve("config").resolve("config.ldif").toString()),
        connectionParams()
          .bindDn("cn=Directory Manager")
          .bindPassword("password")
          .hostName("localhost")
          .ldapPort(ports[0])
          .adminPort(ports[1])
          .build(),
          .adminPort(ports[1]),
         System.out,
         System.err);
      tempServer.setupFromArchive(TestCaseUtils.getOpenDJArchivePath(),
          SetupParameters.setupParams()
      tempServer.extractArchiveForSetup(TestCaseUtils.getOpenDJArchivePath());
      tempServer.setup(
          setupParams()
            .backendType("pdb")
            .baseDn("dc=example,dc=com")
            .jmxPort(ports[2])
            .build());
            .jmxPort(ports[2]));
      tempServer.start();
      tempServer.stop(getClass().getSimpleName(), LocalizableMessage.raw("stopping temp server for setup test"));
    }