From 1a5143ec25e64ce012c5bbc9c0a15597c0ffcbc2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 11 Jul 2013 13:15:43 +0000
Subject: [PATCH] Decouple some tests from running the server.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java | 42 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 40 insertions(+), 2 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 2bb2e77..e0c51d3 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
@@ -103,6 +103,8 @@
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.dsconfig.DSConfig;
+import org.opends.server.types.AttributeType;
+import org.opends.server.types.AttributeTypeConstants;
import org.opends.server.types.ByteString;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryEnvironmentConfig;
@@ -113,6 +115,7 @@
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OperatingSystem;
import org.opends.server.types.ResultCode;
+import org.opends.server.types.Schema;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.EmbeddedUtils;
import org.opends.server.util.LDIFReader;
@@ -248,6 +251,35 @@
private static File testConfigDir;
/**
+ * Setup in-memory versions of everything needed to run unit tests with the
+ * {@link DirectoryServer} class.
+ * <p>
+ * This method is trying hard to provide sensible defaults and core data you
+ * would expect from a normal install, including AttributeTypes, etc.
+ */
+ public static void startFakeServer()
+ {
+ DirectoryServer.setSchema(initializeInMemory(new Schema()));
+ }
+
+ private static Schema initializeInMemory(final Schema schema)
+ {
+ try
+ {
+ for (AttributeType attributeType : AttributeTypeConstants.ALL)
+ {
+ schema.registerAttributeType(attributeType, true);
+ }
+ return schema;
+ }
+ catch (DirectoryException e)
+ {
+ // rethrow this to fail the current test
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* Starts the Directory Server so that it will be available for use while
* running the unit tests. This will only actually start the server once, so
* subsequent attempts to start it will be ignored because it will already be
@@ -414,8 +446,14 @@
+ "instance.loc");
installLoc.deleteOnExit();
FileWriter w = new FileWriter(installLoc);
- w.write(testInstanceRoot.getAbsolutePath());
- w.close();
+ try
+ {
+ w.write(testInstanceRoot.getAbsolutePath());
+ }
+ finally
+ {
+ w.close();
+ }
if (opendmkJar.exists())
{
--
Gitblit v1.10.0