From 883c4b7810dcabba4ebe2924ca0757485f5312da Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Fri, 15 Jun 2007 21:55:02 +0000
Subject: [PATCH] - Add a few more unit tests for important classes. This also includes some plumbing for getting the quicksetup tests' workspace server configured enough so that it is startable and stoppable for testing.
---
opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java | 77 +++++++++++++++++++++++++++++++++++---
1 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
index 4529be4..cba2d36 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/quicksetup/Utils.java
@@ -28,11 +28,16 @@
package org.opends.quicksetup;
import org.opends.quicksetup.util.ZipExtractor;
+import org.opends.quicksetup.util.ServerController;
+import org.opends.server.TestCaseUtils;
+import org.opends.server.types.OperatingSystem;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.PrintStream;
-import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.List;
+import java.util.ArrayList;
/**
*
@@ -45,10 +50,70 @@
public static final String PROPERTY_BUILD_ROOT =
"org.opends.server.BuildRoot";
- static public void extractServer()
- throws FileNotFoundException, ApplicationException {
- ZipExtractor extractor = new ZipExtractor(getInstallPackageFile());
- extractor.extract(getQuickSetupTestServerRootDir());
+ public static final String DIRECTORY_MANAGER_PASSWORD = "password";
+
+ public static Integer ldapPort;
+
+ public static Integer jmxPort;
+
+ private static boolean initialized;
+
+ static public void initServer()
+ throws IOException, ApplicationException, InterruptedException {
+ File qsServerRoot = getQuickSetupTestServerRootDir();
+ if (!initialized) {
+ if (qsServerRoot.exists()) {
+ stopServer();
+ if (!qsServerRoot.delete()) {
+ throw new IllegalStateException("cannot delete stale installation");
+ }
+ }
+ ZipExtractor extractor = new ZipExtractor(getInstallPackageFile());
+ extractor.extract(qsServerRoot);
+ setupServer();
+ initialized = true;
+ }
+ }
+
+ static public Installation getInstallation() {
+ return new Installation(Utils.getQuickSetupTestServerRootDir());
+ }
+
+ static private void setupServer() throws IOException, InterruptedException {
+ ServerSocket ldapSocket = TestCaseUtils.bindFreePort();
+ ldapPort = ldapSocket.getLocalPort();
+ ldapSocket.close();
+
+ ServerSocket jmxSocket = TestCaseUtils.bindFreePort();
+ jmxPort = jmxSocket.getLocalPort();
+ jmxSocket.close();
+
+ List<String> args = new ArrayList<String>();
+ File root = getQuickSetupTestServerRootDir();
+ if (OperatingSystem.isUNIXBased(
+ OperatingSystem.forName(System.getProperty("os.name")))) {
+ args.add(new File(root, "setup").getPath());
+ } else {
+ args.add(new File(root, "setup.bat").getPath());
+ }
+ args.add("--cli");
+ args.add("-s");
+ args.add("-p");
+ args.add(Integer.toString(ldapPort));
+ args.add("-x");
+ args.add(Integer.toString(jmxPort));
+ args.add("-w");
+ args.add(DIRECTORY_MANAGER_PASSWORD);
+ ProcessBuilder pb = new ProcessBuilder(args);
+ Process p = pb.start();
+ if (p.waitFor() != 0) {
+ throw new IllegalStateException("setup server failed");
+ }
+ }
+
+ static public void stopServer() throws ApplicationException {
+ ServerController controller = new ServerController(getInstallation());
+ controller.stopServer();
}
static public File getInstallPackageFile() throws FileNotFoundException {
--
Gitblit v1.10.0