From 5bd36ac50986bb76cf23fbf9d598b834dea85ed8 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 01 Feb 2007 21:55:08 +0000
Subject: [PATCH] Add new convenience methods into the TestCaseUtils class:

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 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 5b3ffd7..2a39fe9 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
@@ -48,6 +48,7 @@
 import org.opends.server.backends.jeb.BackendImpl;
 import org.opends.server.config.ConfigException;
 import org.opends.server.config.ConfigEntry;
+import org.opends.server.core.AddOperation;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.LockFileManager;
 import org.opends.server.extensions.ConfigFileHandler;
@@ -55,11 +56,13 @@
 import org.opends.server.loggers.Error;
 import org.opends.server.loggers.Debug;
 import org.opends.server.plugins.InvocationCounterPlugin;
+import org.opends.server.protocols.internal.InternalClientConnection;
 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.NullOutputStream;
+import org.opends.server.types.ResultCode;
 
 import static org.testng.Assert.*;
 
@@ -709,6 +712,96 @@
      return entriesFromLdifString(makeLdif(lines));
   }
 
+
+
+  /**
+   * Adds the provided entry to the Directory Server using an internal
+   * operation.
+   *
+   * @param  entry  The entry to be added.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  public static void addEntry(Entry entry)
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+
+    AddOperation addOperation = conn.processAdd(entry.getDN(),
+                                     entry.getObjectClasses(),
+                                     entry.getUserAttributes(),
+                                     entry.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Adds the provided entry to the Directory Server using an internal
+   * operation.
+   *
+   * @param  lines  The lines that make up the entry to be added.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  public static void addEntry(String... lines)
+         throws Exception
+  {
+    Entry entry = makeEntry(lines);
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+
+    AddOperation addOperation = conn.processAdd(entry.getDN(),
+                                     entry.getObjectClasses(),
+                                     entry.getUserAttributes(),
+                                     entry.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Adds the provided set of entries to the Directory Server using internal
+   * operations.
+   *
+   * @param  entries  The entries to be added.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  public static void addEntries(List<Entry> entries)
+         throws Exception
+  {
+    for (Entry entry : entries)
+    {
+      addEntry(entry);
+    }
+  }
+
+
+
+  /**
+   * Adds the provided set of entries to the Directory Server using internal
+   * operations.
+   *
+   * @param  lines  The lines defining the entries to add.  If there are
+   *                multiple entries, then they should be separated by blank
+   *                lines.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  public static void addEntries(String... lines)
+         throws Exception
+  {
+    for (Entry entry : makeEntries(lines))
+    {
+      addEntry(entry);
+    }
+  }
+
+
+
   /**
    * Creates a temporary text file with the specified contents.  It will be
    * marked for automatic deletion when the JVM exits.

--
Gitblit v1.10.0