From 313c7ce226afaa79e811d6fa0f5ad8b8a59f0fd5 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Mon, 13 Aug 2007 14:48:19 +0000
Subject: [PATCH] Provide a new org.opends.server.util.EmbeddedUtils class that can be used to simplify the process of running the server as an embedded application. There are methods to start, stop, and restart the server, as well as to determine whether the server is running. Also, provide a new org.opends.server.types.DirectoryEnvironmentConfig class that can be used to define a number of "environment" properties that provide information about the way in which the server should run.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java | 62 +++++++++---------------------
1 files changed, 19 insertions(+), 43 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 9f3942d..4b4fd6c 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -69,12 +69,14 @@
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.dsconfig.DSConfig;
-import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.types.DirectoryException;
+import org.opends.server.types.DN;
import org.opends.server.types.FilePermission;
import org.opends.server.types.InitializationException;
import org.opends.server.types.OperatingSystem;
import org.opends.server.types.ResultCode;
+import org.opends.server.util.EmbeddedUtils;
import static org.testng.Assert.*;
@@ -304,53 +306,27 @@
serverJmxSocket.close();
serverLdapsSocket.close();
- // Actually start the server and set a variable that will prevent us from
- // needing to do it again.
- System.setProperty(PROPERTY_SERVER_ROOT, testRoot.getAbsolutePath());
- System.setProperty(PROPERTY_FORCE_DAEMON_THREADS, "true");
- String configClass = ConfigFileHandler.class.getName();
- String configFile = testConfigDir.getAbsolutePath() + File.separator +
- "config.ldif";
+ // Create a configuration for the server.
+ DirectoryEnvironmentConfig config = new DirectoryEnvironmentConfig();
+ config.setServerRoot(testRoot);
+ config.setForceDaemonThreads(true);
+ config.setConfigClass(ConfigFileHandler.class);
+ config.setConfigFile(new File(testConfigDir, "config.ldif"));
- DirectoryServer directoryServer = DirectoryServer.getInstance();
- directoryServer.bootstrapServer();
- directoryServer.initializeConfiguration(configClass, configFile);
+ config.addAccessLogger(
+ TextAccessLogPublisher.getStartupTextAccessPublisher(
+ TestListener.ACCESS_TEXT_WRITER, false));
- String debugTarget = System.getProperty("org.opends.test.debug.target");
- if(debugTarget != null)
- {
- System.setProperty("org.opends.server.debug.enabled", "true");
- System.setProperty("org.opends.server.debug.target.1", debugTarget);
- }
+ config.addErrorLogger(
+ TextErrorLogPublisher.getStartupTextErrorPublisher(
+ TestListener.ERROR_TEXT_WRITER));
- try
- {
- TextDebugLogPublisher startupDebugPublisher =
- TextDebugLogPublisher.getStartupTextDebugPublisher(
- TestListener.DEBUG_TEXT_WRITER);
- DebugLogger.removeAllDebugLogPublishers();
- DebugLogger.addDebugLogPublisher(startupDebugPublisher);
+ config.addDebugLogger(
+ TextDebugLogPublisher.getStartupTextDebugPublisher(
+ TestListener.DEBUG_TEXT_WRITER));
- TextErrorLogPublisher startupErrorPublisher =
- TextErrorLogPublisher.getStartupTextErrorPublisher(
- TestListener.ERROR_TEXT_WRITER);
- ErrorLogger.removeAllErrorLogPublishers();
- ErrorLogger.addErrorLogPublisher(startupErrorPublisher);
-
- TextAccessLogPublisher startupAccessPublisher =
- TextAccessLogPublisher.getStartupTextAccessPublisher(
- TestListener.ACCESS_TEXT_WRITER, false);
- AccessLogger.removeAllAccessLogPublishers();
- AccessLogger.addAccessLogPublisher(startupAccessPublisher);
- }
- catch(Exception e)
- {
- System.out.println("Error installing test log publishers: " +
- e.toString());
- }
-
- directoryServer.startServer();
+ EmbeddedUtils.startServer(config);
assertTrue(InvocationCounterPlugin.startupCalled());
--
Gitblit v1.10.0