From 4c0ec5006ab946100ce1645f9e89e74de2b8e6b7 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 27 May 2016 15:30:47 +0000
Subject: [PATCH] OPENDJ-1238 Address comments post PR

---
 opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java                                      |    2 
 opendj-server-legacy/src/main/java/org/opends/server/backends/ConfigurationBackend.java                             |   12 +
 opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java                                 |    1 
 opendj-server-legacy/src/main/java/org/opends/server/tasks/TaskUtils.java                                           |    2 
 opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java |    2 
 opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java                                      |    2 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java                             |    2 
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java            |    2 
 opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java                                        |    2 
 /dev/null                                                                                                           |  377 -----------------------------------------
 opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java                                         |    2 
 opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java                                    |    2 
 opendj-server-legacy/src/messages/org/opends/messages/config.properties                                             |   12 +
 opendj-server-legacy/src/main/java/org/opends/server/config/ConfigurationHandler.java                               |   96 ++++++----
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java                  |    2 
 15 files changed, 86 insertions(+), 432 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
index 9e27b44..e6fb4e5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteBaseDNAndBackendTask.java
@@ -57,7 +57,7 @@
 import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
 import org.opends.guitools.controlpanel.ui.ProgressDialog;
 import org.opends.guitools.controlpanel.util.Utilities;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.OpenDsException;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
index 93ca6df..7c32f23 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -116,7 +116,7 @@
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.ui.UIFactory;
 import org.opends.quicksetup.util.Utils;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.LockFileManager;
 import org.opends.server.schema.SchemaConstants;
 import org.opends.server.schema.SomeSchemaElement;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/ConfigurationBackend.java
similarity index 96%
rename from opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBackend.java
rename to opendj-server-legacy/src/main/java/org/opends/server/backends/ConfigurationBackend.java
index dc6292c..7bbc315 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/ConfigurationBackend.java
@@ -13,7 +13,7 @@
  *
  * Copyright 2014-2016 ForgeRock AS.
  */
-package org.opends.server.core;
+package org.opends.server.backends;
 
 import static org.opends.messages.ConfigMessages.*;
 import static org.opends.server.config.ConfigConstants.ATTR_DEFAULT_ROOT_PRIVILEGE_NAME;
@@ -45,7 +45,15 @@
 import org.opends.server.api.Backend;
 import org.opends.server.api.Backupable;
 import org.opends.server.api.ClientConnection;
-import org.opends.server.core.ConfigurationBackend.ConfigurationBackendCfg;
+import org.opends.server.backends.ConfigurationBackend.ConfigurationBackendCfg;
+import org.opends.server.config.ConfigurationHandler;
+import org.opends.server.core.AddOperation;
+import org.opends.server.core.DeleteOperation;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ModifyDNOperation;
+import org.opends.server.core.ModifyOperation;
+import org.opends.server.core.SearchOperation;
+import org.opends.server.core.ServerContext;
 import org.opends.server.types.BackupConfig;
 import org.opends.server.types.BackupDirectory;
 import org.opends.server.types.DirectoryException;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigurationHandler.java
similarity index 95%
rename from opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationHandler.java
rename to opendj-server-legacy/src/main/java/org/opends/server/config/ConfigurationHandler.java
index e3d7da4..f091e8f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/ConfigurationHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/config/ConfigurationHandler.java
@@ -13,22 +13,13 @@
  *
  * Copyright 2014-2016 ForgeRock AS.
  */
-package org.opends.server.core;
+package org.opends.server.config;
 
-import static org.opends.messages.ConfigMessages.ERR_CONFIG_FILE_ADD_NO_PARENT;
-import static org.opends.messages.ConfigMessages.ERR_CONFIG_FILE_ADD_NO_PARENT_DN;
 import static org.opends.messages.ConfigMessages.*;
 import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.util.ServerConstants.ALERT_DESCRIPTION_CANNOT_WRITE_CONFIGURATION;
-import static org.opends.server.util.ServerConstants.ALERT_DESCRIPTION_MANUAL_CONFIG_EDIT_HANDLED;
-import static org.opends.server.util.ServerConstants.ALERT_DESCRIPTION_MANUAL_CONFIG_EDIT_LOST;
-import static org.opends.server.util.ServerConstants.ALERT_TYPE_MANUAL_CONFIG_EDIT_HANDLED;
-import static org.opends.server.util.ServerConstants.ALERT_TYPE_MANUAL_CONFIG_EDIT_LOST;
-import static org.opends.server.util.ServerConstants.ALERT_TYPE_CANNOT_WRITE_CONFIGURATION;
-import static org.opends.server.util.StaticUtils.getExceptionMessage;
-import static org.opends.server.util.StaticUtils.renameFile;
-import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
-import static org.opends.server.extensions.ExtensionsConstants.MESSAGE_DIGEST_ALGORITHM_SHA_1;
+import static org.opends.server.extensions.ExtensionsConstants.*;
+import static org.opends.server.util.ServerConstants.*;
+import static org.opends.server.util.StaticUtils.*;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -94,6 +85,9 @@
 import org.forgerock.util.Utils;
 import org.forgerock.util.annotations.VisibleForTesting;
 import org.opends.server.api.AlertGenerator;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.SearchOperation;
+import org.opends.server.core.ServerContext;
 import org.opends.server.schema.GeneralizedTimeSyntax;
 import org.opends.server.tools.LDIFModify;
 import org.opends.server.types.DirectoryEnvironmentConfig;
@@ -174,14 +168,14 @@
    * Bootstraps the server configuration.
    * <p>
    * The returned ConfigurationHandler is initialized with a partial schema and must be later
-   * re-initialized with the full schema by calling {@code reInitializeWithFullSchema()} method
-   * once the schema has been fully loaded.
+   * re-initialized with the full schema by calling {@link #reinitializeWithFullSchema(Schema)}
+   * method once the schema has been fully loaded.
    *
    * @param serverContext
-   *            The server context.
+   *          The server context.
    * @return the configuration handler
    * @throws InitializationException
-   *            If an error occurs during bootstrapping.
+   *           If an error occurs during bootstrapping.
    */
   public static ConfigurationHandler bootstrapConfiguration(ServerContext serverContext)
       throws InitializationException {
@@ -195,8 +189,8 @@
     }
     catch (ConfigException e)
     {
-      // TODO : fix the message
-      throw new InitializationException(LocalizableMessage.raw("Cannot initialize configuration framework"), e);
+      LocalizableMessage msg = ERR_CANNOT_INITIALIZE_CONFIGURATION_FRAMEWORK.get(stackTraceToSingleLineString(e));
+      throw new InitializationException(msg, e);
     }
 
     final ConfigurationHandler configHandler = new ConfigurationHandler(serverContext);
@@ -207,10 +201,13 @@
   /**
    * Initializes the configuration with an incomplete schema.
    * <p>
-   * As configuration contains schema-related items, the initialization of the configuration
-   * can only be performed with an incomplete schema before a complete schema is available.
-   * Once a complete schema is available, the {@link #reinitializeWithFullSchema(Schema)} method
-   * should be called to have a fully validated configuration.
+   * As configuration contains schema-related items, the initialization of the configuration can
+   * only be performed with an incomplete schema before a complete schema is available. Once a
+   * complete schema is available, the {@link #reinitializeWithFullSchema(Schema)} method should be
+   * called to have a fully validated configuration.
+   *
+   * @throws InitializationException
+   *           If an error occurs.
    */
   @VisibleForTesting
   void initializeWithPartialSchema() throws InitializationException
@@ -319,8 +316,7 @@
       }
       return children;
     }
-    // TODO : fix message
-    throw new ConfigException(LocalizableMessage.raw("Unable to retrieve children of configuration entry : %s", dn),
+    throw new ConfigException(ERR_UNABLE_TO_RETRIEVE_CHILDREN_OF_CONFIGURATION_ENTRY.get(dn),
         resultHandler.getResultError());
   }
 
@@ -433,9 +429,8 @@
     {
       return searchHandler.getEntries().size();
     }
-    // TODO : fix the message
-    throw new ConfigException(LocalizableMessage
-        .raw("Unable to retrieve children of configuration entry : %s", entryDN), resultHandler.getResultError());
+    throw new ConfigException(ERR_UNABLE_TO_RETRIEVE_CHILDREN_OF_CONFIGURATION_ENTRY.get(entryDN),
+        resultHandler.getResultError());
   }
 
   /**
@@ -458,7 +453,7 @@
       throw new DirectoryException(ResultCode.ENTRY_ALREADY_EXISTS, ERR_CONFIG_FILE_ADD_ALREADY_EXISTS.get(entryDN));
     }
 
-    final DN parentDN = retrieveParentDN(entryDN);
+    final DN parentDN = retrieveParentDNForAdd(entryDN);
 
     // Iterate through add listeners to make sure the new entry is acceptable.
     final List<ConfigAddListener> addListeners = getAddListeners(parentDN);
@@ -478,7 +473,6 @@
 
     if (!resultHandler.hasCompletedSuccessfully())
     {
-      // TODO fix the message : error when adding config entry
       LdapException ex = resultHandler.getResultError();
       throw new DirectoryException(ex.getResult().getResultCode(),
           ERR_CONFIG_FILE_ADD_FAILED.get(entryDN, parentDN, ex.getLocalizedMessage()), ex);
@@ -532,14 +526,11 @@
     }
     catch (ConfigException e)
     {
-      // TODO : i18n
       throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,
-          LocalizableMessage.raw("Backend config error when trying to delete an entry: %s",
-              stackTraceToSingleLineString(e)), e);
+          ERR_CONFIG_BACKEND_CANNOT_DELETE_ENTRY.get(stackTraceToSingleLineString(e)), e);
     }
 
-    // TODO : pass in the localizable message (2)
-    final DN parentDN = retrieveParentDN(dn);
+    final DN parentDN = retrieveParentDNForDelete(dn);
 
     // Iterate through delete listeners to make sure the deletion is acceptable.
     final List<ConfigDeleteListener> deleteListeners = getDeleteListeners(parentDN);
@@ -1232,8 +1223,8 @@
     }
     catch (Exception e)
     {
-      // TODO : fix message
-      throw new InitializationException(LocalizableMessage.raw("Unable to load config-enabled schema"), e);
+      throw new InitializationException(
+          ERR_UNABLE_TO_LOAD_CONFIGURATION_ENABLED_SCHEMA.get(stackTraceToSingleLineString(e)), e);
     }
   }
 
@@ -1609,14 +1600,11 @@
 
     if (!successful)
     {
-      // FIXME -- Log each error message and throw an exception.
       for (LocalizableMessage s : errorList)
       {
         logger.error(ERR_CONFIG_ERROR_APPLYING_STARTUP_CHANGE, s);
       }
-
-      LocalizableMessage message = ERR_CONFIG_UNABLE_TO_APPLY_CHANGES_FILE.get();
-      throw new LDIFException(message);
+      throw new LDIFException(ERR_CONFIG_UNABLE_TO_APPLY_CHANGES_FILE.get(Utils.joinAsString("; ", errorList)));
     }
 
     // Move the current config file out of the way and replace it with the updated version.
@@ -1725,7 +1713,7 @@
    * @throws DirectoryException
    *           If entry has no parent or parent entry does not exist.
    */
-  private DN retrieveParentDN(final DN entryDN) throws DirectoryException
+  private DN retrieveParentDNForAdd(final DN entryDN) throws DirectoryException
   {
     final DN parentDN = entryDN.parent();
     if (parentDN == null)
@@ -1740,6 +1728,30 @@
     return parentDN;
   }
 
+  /**
+   * Returns the parent DN of the configuration entry corresponding to the provided DN.
+   *
+   * @param entryDN
+   *          DN of entry to retrieve the parent from.
+   * @return the parent DN
+   * @throws DirectoryException
+   *           If entry has no parent or parent entry does not exist.
+   */
+  private DN retrieveParentDNForDelete(final DN entryDN) throws DirectoryException
+  {
+    final DN parentDN = entryDN.parent();
+    if (parentDN == null)
+    {
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, ERR_CONFIG_FILE_DELETE_NO_PARENT_DN.get(entryDN));
+    }
+    if (!backend.contains(parentDN))
+    {
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, ERR_CONFIG_FILE_DELETE_NO_PARENT.get(entryDN),
+          getMatchedDN(parentDN), null);
+    }
+    return parentDN;
+  }
+
   /** Returns the matched DN that is available in the configuration for the provided DN. */
   private DN getMatchedDN(final DN dn)
   {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java b/opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
index 4e9373e..713a629 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
@@ -42,6 +42,7 @@
 import org.forgerock.opendj.server.config.server.RootCfg;
 import org.opends.server.api.Backend;
 import org.opends.server.api.BackendInitializationListener;
+import org.opends.server.backends.ConfigurationBackend;
 import org.opends.server.config.ConfigConstants;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.Entry;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index 1c8b1f9..f51ed8d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -120,8 +120,10 @@
 import org.opends.server.api.plugin.InternalDirectoryServerPlugin;
 import org.opends.server.api.plugin.PluginResult;
 import org.opends.server.api.plugin.PluginType;
+import org.opends.server.backends.ConfigurationBackend;
 import org.opends.server.backends.RootDSEBackend;
 import org.opends.server.config.AdministrationConnector;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.config.JMXMBean;
 import org.opends.server.controls.PasswordPolicyErrorType;
 import org.opends.server.controls.PasswordPolicyResponseControl;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index 3ce9630..bd78f01 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -86,9 +86,9 @@
 import org.opends.server.api.SynchronizationProvider;
 import org.opends.server.backends.task.Task;
 import org.opends.server.config.ConfigConstants;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.controls.PagedResultsControl;
 import org.opends.server.core.AddOperation;
-import org.opends.server.core.ConfigurationHandler;
 import org.opends.server.core.DeleteOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tasks/TaskUtils.java b/opendj-server-legacy/src/main/java/org/opends/server/tasks/TaskUtils.java
index 4cdb9c3..c8ed1f5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tasks/TaskUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tasks/TaskUtils.java
@@ -35,7 +35,7 @@
 import org.opends.server.api.Backend;
 import org.opends.server.tools.BackendToolUtils;
 import org.opends.server.types.Entry;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.ModifyOperation;
 import org.opends.server.types.Attribute;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java
index 1bcfb96..d82522d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java
@@ -26,7 +26,7 @@
 import org.forgerock.opendj.server.config.server.BackendCfg;
 import org.forgerock.opendj.server.config.server.RootCfg;
 import org.opends.server.api.Backend;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.Entry;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
index 994b7ca..0a3690c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
@@ -61,7 +61,7 @@
 import org.forgerock.opendj.server.config.meta.CryptoManagerCfgDefn;
 import org.forgerock.opendj.server.config.server.BackendCfg;
 import org.opends.quicksetup.installer.Installer;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
 import org.opends.server.extensions.SaltedSHA512PasswordStorageScheme;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java
index 33d8cbf..33124ec 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java
@@ -39,7 +39,7 @@
 import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DN;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.loggers.JDKLogging;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
index b64ac7e..7e5eb57 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/workflowelement/localbackend/LocalBackendCompareOperation.java
@@ -29,11 +29,11 @@
 import org.opends.server.api.AccessControlHandler;
 import org.opends.server.api.Backend;
 import org.opends.server.api.ClientConnection;
+import org.opends.server.backends.ConfigurationBackend;
 import org.opends.server.controls.LDAPAssertionRequestControl;
 import org.opends.server.core.AccessControlConfigManager;
 import org.opends.server.core.CompareOperation;
 import org.opends.server.core.CompareOperationWrapper;
-import org.opends.server.core.ConfigurationBackend;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.CanceledOperationException;
diff --git a/opendj-server-legacy/src/messages/org/opends/messages/config.properties b/opendj-server-legacy/src/messages/org/opends/messages/config.properties
index 701ff69..62d6eca 100644
--- a/opendj-server-legacy/src/messages/org/opends/messages/config.properties
+++ b/opendj-server-legacy/src/messages/org/opends/messages/config.properties
@@ -525,7 +525,7 @@
 ERR_CONFIG_ERROR_APPLYING_STARTUP_CHANGE_564=Unable to apply a change \
  at server startup: %s
 ERR_CONFIG_UNABLE_TO_APPLY_CHANGES_FILE_565=One or more errors occurred \
- while applying changes on server startup
+ while applying changes on server startup: %s
 ERR_CONFIG_BACKEND_MODE_INVALID_567=Configuration entry %s does not \
  contain a valid value for configuration attribute ds-cfg-db-directory-permissions (It \
  should be an UNIX permission mode in three-digit octal notation.)
@@ -817,4 +817,12 @@
 ERR_CONFIG_HTTPENDPOINT_INVALID_CONFIGURATION_741=The HTTP endpoint configuration \
  defined in %s is invalid: %s
 ERR_CONFIG_REST2LDAP_MALFORMED_URL_742=Invalid configuration URL in the REST2LDAP endpoint \
- configuration entry %s: %s
\ No newline at end of file
+ configuration entry %s: %s
+ERR_CANNOT_INITIALIZE_CONFIGURATION_FRAMEWORK_743=Cannot initialize the \
+ configuration framework: %s
+ERR_UNABLE_TO_RETRIEVE_CHILDREN_OF_CONFIGURATION_ENTRY_744=Unable to retrieve \
+ children of configuration entry with dn: %s
+ERR_UNABLE_TO_LOAD_CONFIGURATION_ENABLED_SCHEMA_745=Unable to load the \
+ configuration-enabled schema: %s
+ERR_CONFIG_BACKEND_CANNOT_DELETE_ENTRY_746=Backend config error when trying to \
+ delete an entry: %s
\ No newline at end of file
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java b/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
index 876f995..302bd34 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/ServerContextBuilder.java
@@ -20,7 +20,7 @@
 import java.io.File;
 
 import org.forgerock.opendj.config.server.ServerManagementContext;
-import org.opends.server.core.ConfigurationHandler;
+import org.opends.server.config.ConfigurationHandler;
 import org.opends.server.core.ServerContext;
 import org.opends.server.types.DirectoryEnvironmentConfig;
 import org.opends.server.types.InitializationException;
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/core/ConfigurationHandlerTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/core/ConfigurationHandlerTestCase.java
deleted file mode 100644
index 1fc8492..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/core/ConfigurationHandlerTestCase.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2014-2016 ForgeRock AS.
- */
-package org.opends.server.core;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.opends.server.ServerContextBuilder.aServerContext;
-import static org.testng.Assert.*;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.Set;
-
-import org.forgerock.i18n.LocalizableMessageBuilder;
-import org.forgerock.opendj.config.server.ConfigChangeResult;
-import org.forgerock.opendj.config.server.spi.ConfigAddListener;
-import org.forgerock.opendj.config.server.spi.ConfigChangeListener;
-import org.forgerock.opendj.config.server.spi.ConfigDeleteListener;
-import org.forgerock.opendj.ldap.DN;
-import org.forgerock.opendj.ldap.Entry;
-import org.forgerock.opendj.ldap.LinkedHashMapEntry;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.config.ConfigConstants;
-import org.opends.server.types.DirectoryException;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-@SuppressWarnings("javadoc")
-public class ConfigurationHandlerTestCase extends CoreTestCase
-{
-  private static final DN DN_CONFIG = DN.valueOf(ConfigConstants.DN_CONFIG_ROOT);
-  private static final DN DN_SCHEMA_PROVIDERS = DN.valueOf("cn=Schema Providers,cn=config");
-  private static final DN DN_CORE_SCHEMA = DN.valueOf("cn=Core Schema,cn=Schema Providers,cn=config");
-
-  private ConfigurationHandler configHandler;
-
-  @BeforeMethod
-  public void initializeTest() throws Exception
-  {
-    // Use a copy of configuration for tests to avoid updating the original configuration file.
-    File originalConfigFile = TestCaseUtils.getTestResource("configForTests/config-small.ldif");
-    File copyConfigFile = new File(TestCaseUtils.getUnitTestRootPath(), "config-small-copy.ldif");
-    copyConfigFile.deleteOnExit();
-    if (copyConfigFile.exists())
-    {
-      copyConfigFile.delete();
-    }
-    TestCaseUtils.copyFile(originalConfigFile, copyConfigFile);
-    configHandler = getConfigurationHandler(copyConfigFile);
-  }
-
-  @AfterClass
-  public void cleanup()
-  {
-    File copyConfigFile = new File(TestCaseUtils.getUnitTestRootPath(), "config-small-copy.ldif");
-    if (copyConfigFile.exists())
-    {
-      copyConfigFile.delete();
-    }
-  }
-
-  /** Returns the configuration handler fully initialized from configuration file. */
-  private ConfigurationHandler getConfigurationHandler(File configFile) throws Exception
-  {
-    final ServerContext context = aServerContext().
-        schemaDirectory(new File(TestCaseUtils.getBuildRoot(), "resource/schema")).
-        configFile(configFile).
-        build();
-
-    return ConfigurationHandler.bootstrapConfiguration(context);
-  }
-
-  @Test
-    public void testConfigurationBootstrap() throws Exception
-    {
-      assertTrue(configHandler.hasEntry(DN_CONFIG));
-    }
-
-  @Test
-  public void testGetEntry() throws Exception
-  {
-    Entry entry = configHandler.getEntry(DN_SCHEMA_PROVIDERS);
-    assertTrue(entry.containsAttribute("objectclass", "top", "ds-cfg-branch"));
-  }
-
-  @Test
-  public void testGetChildren() throws Exception
-  {
-    Set<DN> dns = configHandler.getChildren(DN_SCHEMA_PROVIDERS);
-    assertTrue(dns.contains(DN_CORE_SCHEMA));
-  }
-
-  @Test
-  public void testNumSubordinates() throws Exception
-  {
-    long numSubordinates = configHandler.numSubordinates(DN_SCHEMA_PROVIDERS, false);
-    assertEquals(numSubordinates, 1);
-
-    numSubordinates = configHandler.numSubordinates(DN_CONFIG, true);
-    assertEquals(numSubordinates, 2);
-  }
-
-  @Test
-  public void testRegisterChangeListener() throws Exception
-  {
-    ConfigChangeListener listener1 = mock(ConfigChangeListener.class);
-    ConfigChangeListener listener2 = mock(ConfigChangeListener.class);
-
-    configHandler.registerChangeListener(DN_SCHEMA_PROVIDERS, listener1);
-    configHandler.registerChangeListener(DN_SCHEMA_PROVIDERS, listener2);
-
-    assertEquals(configHandler.getChangeListeners(DN_SCHEMA_PROVIDERS), Arrays.asList(listener1 ,listener2));
-  }
-
-  @Test
-  public void testRegisterDeregisterChangeListener() throws Exception
-  {
-    ConfigChangeListener listener1 = mock(ConfigChangeListener.class);
-    ConfigChangeListener listener2 = mock(ConfigChangeListener.class);
-
-    configHandler.registerChangeListener(DN_SCHEMA_PROVIDERS, listener1);
-    configHandler.registerChangeListener(DN_SCHEMA_PROVIDERS, listener2);
-    configHandler.deregisterChangeListener(DN_SCHEMA_PROVIDERS, listener1);
-
-    assertEquals(configHandler.getChangeListeners(DN_SCHEMA_PROVIDERS), Arrays.asList(listener2));
-  }
-
-  @Test
-  public void testRegisterAddListener() throws Exception
-  {
-    ConfigAddListener listener1 = mock(ConfigAddListener.class);
-    ConfigAddListener listener2 = mock(ConfigAddListener.class);
-
-    configHandler.registerAddListener(DN_SCHEMA_PROVIDERS, listener1);
-    configHandler.registerAddListener(DN_SCHEMA_PROVIDERS, listener2);
-
-    assertEquals(configHandler.getAddListeners(DN_SCHEMA_PROVIDERS), Arrays.asList(listener1 ,listener2));
-  }
-
-  @Test
-  public void testRegisterDeleteListener() throws Exception
-  {
-    ConfigDeleteListener listener1 = mock(ConfigDeleteListener.class);
-    ConfigDeleteListener listener2 = mock(ConfigDeleteListener.class);
-
-    configHandler.registerDeleteListener(DN_SCHEMA_PROVIDERS, listener1);
-    configHandler.registerDeleteListener(DN_SCHEMA_PROVIDERS, listener2);
-
-    assertEquals(configHandler.getDeleteListeners(DN_SCHEMA_PROVIDERS), Arrays.asList(listener1 ,listener2));
-  }
-
-  @Test
-  public void testAddEntry() throws Exception
-  {
-    String dn = "cn=Another schema provider,cn=Schema Providers,cn=config";
-
-    configHandler.addEntry(new LinkedHashMapEntry(dn));
-
-    assertTrue(configHandler.hasEntry(DN.valueOf(dn)));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testAddEntryExistingEntry() throws Exception
-  {
-    configHandler.addEntry(new LinkedHashMapEntry(DN_CORE_SCHEMA));
-  }
-
-  /** TODO : disabled because fail when converting to server DN. Re-enable once migrated to SDK DN. */
-  @Test(enabled=false, expectedExceptions=DirectoryException.class)
-  public void testAddEntryParentUnknown() throws Exception
-  {
-    configHandler.addEntry(new LinkedHashMapEntry("cn=Core Schema,cn=Schema Providers,cn=Providers,cn=config"));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testAddEntryNoParent() throws Exception
-  {
-    configHandler.addEntry(new LinkedHashMapEntry(DN.rootDN()));
-  }
-
-  @Test
-  public void testAddListenerWithAddEntry() throws Exception
-  {
-    String dn = "cn=Yet another schema provider,cn=Schema Providers,cn=config";
-
-    ConfigAddListener listener = mock(ConfigAddListener.class);
-    configHandler.registerAddListener(DN_SCHEMA_PROVIDERS, listener);
-    when(listener.configAddIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationAdd(any(Entry.class))).thenReturn(new ConfigChangeResult());
-
-    configHandler.addEntry(new LinkedHashMapEntry(dn));
-
-    // ensure apply is called for listener
-    verify(listener).applyConfigurationAdd(configHandler.getEntry(DN.valueOf(dn)));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testAddListenerWithAddEntryWhenConfigNotAcceptable() throws Exception
-  {
-    ConfigAddListener listener = mock(ConfigAddListener.class);
-    configHandler.registerAddListener(DN_SCHEMA_PROVIDERS, listener);
-    when(listener.configAddIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(false);
-
-    configHandler.addEntry(new LinkedHashMapEntry("cn=New schema provider,cn=Schema Providers,cn=config"));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testAddListenerWithAddEntryWhenFailureApplyingConfig() throws Exception
-  {
-    final ConfigChangeResult ccr = new ConfigChangeResult();
-    ccr.setResultCode(ResultCode.OTHER);
-    ConfigAddListener listener = mock(ConfigAddListener.class);
-    configHandler.registerAddListener(DN_SCHEMA_PROVIDERS, listener);
-    when(listener.configAddIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationAdd(any(Entry.class))).thenReturn(ccr);
-
-    configHandler.addEntry(new LinkedHashMapEntry("cn=New schema provider,cn=Schema Providers,cn=config"));
-  }
-
-  @Test
-  public void testDeleteEntry() throws Exception
-  {
-    configHandler.deleteEntry(DN_CORE_SCHEMA);
-
-    assertFalse(configHandler.hasEntry(DN_CORE_SCHEMA));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testDeleteEntryUnexistingEntry() throws Exception
-  {
-    configHandler.deleteEntry(DN.valueOf("cn=Unexisting provider,cn=Schema Providers,cn=config"));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testDeleteEntryWithChildren() throws Exception
-  {
-    configHandler.deleteEntry(DN_SCHEMA_PROVIDERS);
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testDeleteEntryUnknownParent() throws Exception
-  {
-    configHandler.deleteEntry(DN.valueOf("cn=Core Schema,cn=Schema Providers,cn=Providers,cn=config"));
-  }
-
-  @Test
-  public void testDeleteListenerWithDeleteEntry() throws Exception
-  {
-    ConfigDeleteListener listener = mock(ConfigDeleteListener.class);
-    configHandler.registerDeleteListener(DN_SCHEMA_PROVIDERS, listener);
-    Entry entryToDelete = configHandler.getEntry(DN_CORE_SCHEMA);
-    when(listener.configDeleteIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationDelete(any(Entry.class))).thenReturn(new ConfigChangeResult());
-
-    configHandler.deleteEntry(DN_CORE_SCHEMA);
-
-    // ensure apply is called for listener
-    verify(listener).applyConfigurationDelete(entryToDelete);
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testDeleteListenerWithDeleteEntryWhenConfigNotAcceptable() throws Exception
-  {
-    ConfigDeleteListener listener = mock(ConfigDeleteListener.class);
-    configHandler.registerDeleteListener(DN_SCHEMA_PROVIDERS, listener);
-    when(listener.configDeleteIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(false);
-
-    configHandler.deleteEntry(DN_CORE_SCHEMA);
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testDeleteListenerWithDeleteEntryWhenFailureApplyingConfig() throws Exception
-  {
-    final ConfigChangeResult ccr = new ConfigChangeResult();
-    ccr.setResultCode(ResultCode.OTHER);
-
-    ConfigDeleteListener listener = mock(ConfigDeleteListener.class);
-    configHandler.registerDeleteListener(DN_SCHEMA_PROVIDERS, listener);
-    when(listener.configDeleteIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationDelete(any(Entry.class))).thenReturn(ccr);
-
-    configHandler.deleteEntry(DN_CORE_SCHEMA);
-  }
-
-  @Test
-  public void testReplaceEntry() throws Exception
-  {
-    String dn = DN_CORE_SCHEMA.toString();
-
-    configHandler.replaceEntry(
-        new LinkedHashMapEntry("dn: " + dn, "objectclass: ds-cfg-schema-provider", "ds-cfg-enabled: true"),
-        new LinkedHashMapEntry("dn: " + dn, "objectclass: ds-cfg-schema-provider", "ds-cfg-enabled: false"));
-
-    assertTrue(configHandler.hasEntry(DN_CORE_SCHEMA));
-    assertEquals(configHandler.getEntry(DN_CORE_SCHEMA).getAttribute("ds-cfg-enabled").firstValueAsString(), "false");
-  }
-
-  @Test
-  public void testChangeListenerIsDeletedWhenConfigEntryIsDeleted() throws Exception
-  {
-    ConfigChangeListener listener = mock(ConfigChangeListener.class);
-    configHandler.registerChangeListener(DN_CORE_SCHEMA, listener);
-    when(listener.configChangeIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationChange(any(Entry.class))).thenReturn(new ConfigChangeResult());
-
-    configHandler.deleteEntry(DN_CORE_SCHEMA);
-
-    assertThat(configHandler.getChangeListeners(DN_CORE_SCHEMA)).isEmpty();
-  }
-
-  @Test
-  public void testChangeListenerWithReplaceEntry() throws Exception
-  {
-    ConfigChangeListener listener = mock(ConfigChangeListener.class);
-    configHandler.registerChangeListener(DN_CORE_SCHEMA, listener);
-    when(listener.configChangeIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationChange(any(Entry.class))).thenReturn(new ConfigChangeResult());
-    Entry oldEntry = configHandler.getEntry(DN_CORE_SCHEMA);
-
-    configHandler.replaceEntry(oldEntry,
-        new LinkedHashMapEntry("dn: " + DN_CORE_SCHEMA,
-            "objectclass: ds-cfg-schema-provider",
-            "ds-cfg-enabled: false"));
-
-    // ensure apply is called for listener
-    verify(listener).applyConfigurationChange(configHandler.getEntry(DN_CORE_SCHEMA));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testChangeListenerWithReplaceEntryWhenConfigNotAcceptable() throws Exception
-  {
-    ConfigChangeListener listener = mock(ConfigChangeListener.class);
-    configHandler.registerChangeListener(DN_CORE_SCHEMA, listener);
-    when(listener.configChangeIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(false);
-    Entry oldEntry = configHandler.getEntry(DN_CORE_SCHEMA);
-
-    configHandler.replaceEntry(oldEntry,
-        new LinkedHashMapEntry("dn: " + DN_CORE_SCHEMA,
-            "objectclass: ds-cfg-schema-provider",
-            "ds-cfg-enabled: false"));
-  }
-
-  @Test(expectedExceptions=DirectoryException.class)
-  public void testChangeListenerWithReplaceEntryWhenFailureApplyingConfig() throws Exception
-  {
-    final ConfigChangeResult ccr = new ConfigChangeResult();
-    ccr.setResultCode(ResultCode.OTHER);
-
-    ConfigChangeListener listener = mock(ConfigChangeListener.class);
-    configHandler.registerChangeListener(DN_CORE_SCHEMA, listener);
-    when(listener.configChangeIsAcceptable(any(Entry.class), any(LocalizableMessageBuilder.class))).thenReturn(true);
-    when(listener.applyConfigurationChange(any(Entry.class))).thenReturn(ccr);
-    Entry oldEntry = configHandler.getEntry(DN_CORE_SCHEMA);
-
-    configHandler.replaceEntry(oldEntry,
-        new LinkedHashMapEntry("dn: " + DN_CORE_SCHEMA,
-            "objectclass: ds-cfg-schema-provider",
-            "ds-cfg-enabled: false"));
-  }
-
-}

--
Gitblit v1.10.0