From 0f6b1dd8e8788dd7ca5a3fe248e85820dbc1459d Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sat, 16 Sep 2006 20:19:42 +0000
Subject: [PATCH] Add a set of test cases for the internal protocol.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java   |  310 ++++++++++
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalTestCase.java                  |   45 +
 opendj-sdk/opends/ext/testng/testng.xml                                                                                          |    1 
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java  | 1146 ++++++++++++++++++++++++++++++++++++++
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalConnectionHandlerTestCase.java |  142 ++++
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/TestInternalSearchListener.java        |  110 +++
 6 files changed, 1,754 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/ext/testng/testng.xml b/opendj-sdk/opends/ext/testng/testng.xml
index d0f06bb..c083fbc 100644
--- a/opendj-sdk/opends/ext/testng/testng.xml
+++ b/opendj-sdk/opends/ext/testng/testng.xml
@@ -3,6 +3,7 @@
     <test name="default">
         <packages>
             <package name="org.opends.server.protocols.asn1"/>
+            <package name="org.opends.server.protocols.internal"/>
             <package name="org.opends.server.protocols.ldap"/>
             <package name="org.opends.server.core"/>
             <package name="org.opends.server.backends.jeb"/>
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
new file mode 100644
index 0000000..899e34a
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalClientConnectionTestCase.java
@@ -0,0 +1,1146 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.protocols.internal;
+
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import org.opends.server.TestCaseUtils;
+import org.opends.server.api.ClientConnection;
+import org.opends.server.api.ConnectionSecurityProvider;
+import org.opends.server.core.AddOperation;
+import org.opends.server.core.BindOperation;
+import org.opends.server.core.CancelRequest;
+import org.opends.server.core.CancelResult;
+import org.opends.server.core.CompareOperation;
+import org.opends.server.core.DeleteOperation;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ExtendedOperation;
+import org.opends.server.core.ModifyOperation;
+import org.opends.server.core.ModifyDNOperation;
+import org.opends.server.core.Operation;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.protocols.ldap.LDAPAttribute;
+import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.protocols.ldap.LDAPModification;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.AuthenticationInfo;
+import org.opends.server.types.DereferencePolicy;
+import org.opends.server.types.DisconnectReason;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
+import org.opends.server.types.Modification;
+import org.opends.server.types.ModificationType;
+import org.opends.server.types.RDN;
+import org.opends.server.types.ResultCode;
+import org.opends.server.types.SearchFilter;
+import org.opends.server.types.SearchResultReference;
+import org.opends.server.types.SearchScope;
+
+import static org.testng.Assert.*;
+
+import static org.opends.server.util.ServerConstants.*;
+
+
+
+/**
+ * This class defines a set of tests for the
+ * org.opends.server.protocols.internal.InternalClientConnection class.
+ */
+public class InternalClientConnectionTestCase
+       extends InternalTestCase
+{
+  /**
+   * Ensures that the Directory Server is running.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @BeforeClass()
+  public void startServer()
+         throws Exception
+  {
+    TestCaseUtils.startServer();
+  }
+
+
+
+  /**
+   * Retrieves a set of internal client connections that may be used for
+   * testing purposes.
+   *
+   * @return  A set of internal client connections that may be used for
+   *          testing purposes.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @DataProvider(name = "internalConns")
+  public Object[][] getInternalConnections()
+         throws Exception
+  {
+    return new Object[][]
+    {
+      new Object[] { new InternalClientConnection() },
+      new Object[] { InternalClientConnection.getRootConnection() },
+      new Object[] { new InternalClientConnection(new AuthenticationInfo()) },
+      new Object[] { new InternalClientConnection(
+           new AuthenticationInfo(DN.decode("cn=Directory Manager"), true)) },
+      new Object[] { new InternalClientConnection(
+           new AuthenticationInfo(DN.decode("uid=test,o=test"), false)) },
+    };
+  }
+
+
+
+  /**
+   * Tests the <CODE>nextOperationID</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testNextOperationID(InternalClientConnection conn)
+  {
+    long opID1 = conn.nextOperationID();
+    long opID2 = conn.nextOperationID();
+    assertEquals(opID2, (opID1 + 1));
+  }
+
+
+
+  /**
+   * Tests the <CODE>nextMessageID</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testNextMessageID(InternalClientConnection conn)
+  {
+    int msgID1 = conn.nextMessageID();
+    int msgID2 = conn.nextMessageID();
+    assertEquals(msgID2, (msgID1 + 1));
+  }
+
+
+
+  /**
+   * Tests the <CODE>getConnectionID</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetConnectionID(InternalClientConnection conn)
+  {
+    assertTrue(conn.getConnectionID() < 0);
+  }
+
+
+
+  /**
+   * Tests the <CODE>getConnectionHandler</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetConnectionHandler(InternalClientConnection conn)
+  {
+    assertEquals(conn.getConnectionHandler(),
+                 InternalConnectionHandler.getInstance());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getProtocol</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetProtocol(InternalClientConnection conn)
+  {
+    assertEquals(conn.getProtocol(), "internal");
+  }
+
+
+
+  /**
+   * Tests the <CODE>getClientAddress</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetClientAddress(InternalClientConnection conn)
+  {
+    assertEquals(conn.getClientAddress(), "internal");
+  }
+
+
+
+  /**
+   * Tests the <CODE>getServerAddress</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetServerAddress(InternalClientConnection conn)
+  {
+    assertEquals(conn.getServerAddress(), "internal");
+  }
+
+
+
+  /**
+   * Tests the <CODE>getRemoteAddress</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetRemoteAddress(InternalClientConnection conn)
+  {
+    assertNull(conn.getRemoteAddress());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getLocalAddress</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetLocalAddress(InternalClientConnection conn)
+  {
+    assertNull(conn.getLocalAddress());
+  }
+
+
+
+  /**
+   * Tests the <CODE>isSecure</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testIsSecure(InternalClientConnection conn)
+  {
+    assertTrue(conn.isSecure());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getConnectionSecurityProvider</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetConnectionSecurityProvider(InternalClientConnection conn)
+  {
+    assertNotNull(conn.getConnectionSecurityProvider());
+  }
+
+
+
+  /**
+   * Tests the <CODE>setConnectionSecurityProvider</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testSetConnectionSecurityProvider(InternalClientConnection conn)
+  {
+    ConnectionSecurityProvider securityProvider =
+         conn.getConnectionSecurityProvider();
+    assertNotNull(securityProvider);
+    conn.setConnectionSecurityProvider(securityProvider);
+  }
+
+
+
+  /**
+   * Tests the <CODE>getSecurityMechanism</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testGetSecurityMechanism(InternalClientConnection conn)
+  {
+    assertNotNull(conn.getSecurityMechanism());
+  }
+
+
+
+  /**
+   * Tests the <CODE>processDataRead</CODE> method.
+   *
+   * @param  conn  The internal client connection to use for the test.
+   */
+  @Test(dataProvider = "internalConns")
+  public void testProcessDataRead(InternalClientConnection conn)
+  {
+    assertFalse(conn.processDataRead(null));
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processAdd</CODE> method, which takes raw arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessAdd1()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    ASN1OctetString dn = new ASN1OctetString("cn=test,o=test");
+
+    ArrayList<LDAPAttribute> attrs = new ArrayList<LDAPAttribute>();
+
+    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
+    values.add(new ASN1OctetString("top"));
+    values.add(new ASN1OctetString("device"));
+    attrs.add(new LDAPAttribute("objectClass", values));
+
+    values = new ArrayList<ASN1OctetString>();
+    values.add(new ASN1OctetString("test"));
+    attrs.add(new LDAPAttribute("cn", values));
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(dn, attrs);
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processAdd</CODE> method, which takes processed
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessAdd2()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processSimpleBind</CODE> method, which takes raw
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSimpleBind1()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    BindOperation bindOperation =
+         conn.processSimpleBind(new ASN1OctetString("cn=Directory Manager"),
+                                new ASN1OctetString("password"));
+    assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processSimpleBind</CODE> method, which takes
+   * processed arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSimpleBind2()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    BindOperation bindOperation =
+         conn.processSimpleBind(DN.decode("cn=Directory Manager"),
+                                new ASN1OctetString("password"));
+    assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processSASLBind</CODE> method, which takes raw
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSASLBind1()
+         throws Exception
+  {
+    ASN1OctetString creds =
+         new ASN1OctetString("\u0000dn:cn=Directory Manager\u0000password");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    BindOperation bindOperation =
+         conn.processSASLBind(new ASN1OctetString(), "PLAIN", creds);
+    assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processSASLBind</CODE> method, which takes processed
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSASLBind2()
+         throws Exception
+  {
+    ASN1OctetString creds =
+         new ASN1OctetString("\u0000dn:cn=Directory Manager\u0000password");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    BindOperation bindOperation =
+         conn.processSASLBind(new DN(), "PLAIN", creds);
+    assertEquals(bindOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processCompare</CODE> method, which takes raw
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessCompare1()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    CompareOperation compareOperation =
+         conn.processCompare(new ASN1OctetString("cn=test,o=test"), "cn",
+                             new ASN1OctetString("test"));
+    assertEquals(compareOperation.getResultCode(), ResultCode.COMPARE_TRUE);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processCompare</CODE> method, which takes processed
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessCompare2()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    CompareOperation compareOperation =
+         conn.processCompare(DN.decode("cn=test,o=test"),
+                             DirectoryServer.getAttributeType("cn", true),
+                             new ASN1OctetString("test"));
+    assertEquals(compareOperation.getResultCode(), ResultCode.COMPARE_TRUE);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processDelete</CODE> method, which takes raw
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessDelete1()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    DeleteOperation deleteOperation =
+         conn.processDelete(new ASN1OctetString("cn=test,o=test"));
+    assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processDelete</CODE> method, which takes processed
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessDelete2()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    DeleteOperation deleteOperation =
+         conn.processDelete(DN.decode("cn=test,o=test"));
+    assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the <CODE>processExtendedOperation</CODE> method.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessExtendedOperation()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    ExtendedOperation extendedOperation =
+         conn.processExtendedOperation(OID_WHO_AM_I_REQUEST, null);
+    assertEquals(extendedOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processModify</CODE> method, which takes raw
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModify1()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ArrayList<ASN1OctetString> values = new ArrayList<ASN1OctetString>();
+    values.add(new ASN1OctetString("This is a test"));
+
+    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
+    mods.add(new LDAPModification(ModificationType.REPLACE,
+                                  new LDAPAttribute("description", values)));
+
+    ModifyOperation modifyOperation =
+         conn.processModify(new ASN1OctetString("cn=test,o=test"), mods);
+    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processModify</CODE> method, which takes processed
+   * arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModify2()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ArrayList<Modification> mods = new ArrayList<Modification>();
+    mods.add(new Modification(ModificationType.REPLACE,
+                              new Attribute("description", "This is a test")));
+
+    ModifyOperation modifyOperation =
+         conn.processModify(DN.decode("cn=test,o=test"), mods);
+    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processModifyDN</CODE> method, which takes raw
+   * arguments and no newSuperior option.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModifyDN1()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ModifyDNOperation modifyDNOperation =
+         conn.processModifyDN(new ASN1OctetString("cn=test,o=test"),
+                              new ASN1OctetString("cn=test2"), true);
+    assertEquals(modifyDNOperation.getResultCode(),
+                 ResultCode.UNWILLING_TO_PERFORM);
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processModifyDN</CODE> method, which takes raw
+   * arguments and allows newSuperior option.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModifyDN2()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ModifyDNOperation modifyDNOperation =
+         conn.processModifyDN(new ASN1OctetString("cn=test,o=test"),
+                              new ASN1OctetString("cn=test2"), true,
+                              new ASN1OctetString("dc=example,dc=com"));
+    assertEquals(modifyDNOperation.getResultCode(),
+                 ResultCode.UNWILLING_TO_PERFORM);
+  }
+
+
+
+  /**
+   * Tests the third <CODE>processModifyDN</CODE> method, which takes processed
+   * arguments and no newSuperior option.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModifyDN3()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ModifyDNOperation modifyDNOperation =
+         conn.processModifyDN(DN.decode("cn=test,o=test"),
+                              RDN.decode("cn=test2"), true);
+    assertEquals(modifyDNOperation.getResultCode(),
+                 ResultCode.UNWILLING_TO_PERFORM);
+  }
+
+
+
+  /**
+   * Tests the fourth <CODE>processModifyDN</CODE> method, which takes processed
+   * arguments and allows newSuperior option.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessModifyDN4()
+         throws Exception
+  {
+    TestCaseUtils.initializeTestBackend(true);
+
+    Entry e = TestCaseUtils.makeEntry("dn: cn=test,o=test",
+                                      "objectClass: top",
+                                      "objectClass: device",
+                                      "cn: test");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    AddOperation addOperation = conn.processAdd(e.getDN(), e.getObjectClasses(),
+                                                e.getUserAttributes(),
+                                                e.getOperationalAttributes());
+    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
+
+
+    ModifyDNOperation modifyDNOperation =
+         conn.processModifyDN(DN.decode("cn=test,o=test"),
+                              RDN.decode("cn=test2"), true,
+                              DN.decode("dc=example,dc=com"));
+    assertEquals(modifyDNOperation.getResultCode(),
+                 ResultCode.UNWILLING_TO_PERFORM);
+  }
+
+
+
+  /**
+   * Tests the first <CODE>processSearch</CODE> method, which takes a minimal
+   * set of raw arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch1()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new ASN1OctetString(""), SearchScope.BASE_OBJECT,
+                            LDAPFilter.decode("(objectClass=*)"));
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the second <CODE>processSearch</CODE> method, which takes a full set
+   * of raw arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch2()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new ASN1OctetString(""), SearchScope.BASE_OBJECT,
+                            DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
+                            LDAPFilter.decode("(objectClass=*)"),
+                            new LinkedHashSet<String>());
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the third <CODE>processSearch</CODE> method, which takes a full set
+   * of raw arguments and uses an internal search listener to handle the
+   * results.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch3()
+         throws Exception
+  {
+    TestInternalSearchListener searchListener =
+         new TestInternalSearchListener();
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new ASN1OctetString(""), SearchScope.BASE_OBJECT,
+                            DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
+                            LDAPFilter.decode("(objectClass=*)"),
+                            new LinkedHashSet<String>(), searchListener);
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchListener.getSearchEntries().isEmpty());
+    assertTrue(searchListener.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the fourth <CODE>processSearch</CODE> method, which takes a minimal
+   * set of processed arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch4()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new DN(), SearchScope.BASE_OBJECT,
+              SearchFilter.createFilterFromString("(objectClass=*)"));
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the fifth <CODE>processSearch</CODE> method, which takes a full set
+   * of processed arguments.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch5()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new DN(), SearchScope.BASE_OBJECT,
+              DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
+              SearchFilter.createFilterFromString("(objectClass=*)"),
+              new LinkedHashSet<String>());
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the sixth <CODE>processSearch</CODE> method, which takes a full set
+   * of processed arguments and uses an internal search listener to handle the
+   * results.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testProcessSearch6()
+         throws Exception
+  {
+    TestInternalSearchListener searchListener =
+         new TestInternalSearchListener();
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new DN(), SearchScope.BASE_OBJECT,
+              DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0, false,
+              SearchFilter.createFilterFromString("(objectClass=*)"),
+              new LinkedHashSet<String>(), searchListener);
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchListener.getSearchEntries().isEmpty());
+    assertTrue(searchListener.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the <CODE>sendSearchReference</CODE> method.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testSendSearchReference()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new ASN1OctetString(""), SearchScope.BASE_OBJECT,
+                            LDAPFilter.decode("(objectClass=*)"));
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+
+    SearchResultReference reference =
+         new SearchResultReference("ldap://server.example.com:389/");
+    conn.sendSearchReference(searchOperation, reference);
+    assertFalse(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the <CODE>sendIntermediateResponseMessage</CODE> method.
+   */
+  @Test()
+  public void testSendIntermediateResponseMessage()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    assertFalse(conn.sendIntermediateResponseMessage(null));
+  }
+
+
+
+  /**
+   * Tests the <CODE>disconnect</CODE> method.
+   */
+  @Test()
+  public void testDisconnect()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    conn.disconnect(DisconnectReason.OTHER, false, "testDisconnect", -1);
+  }
+
+
+
+  /**
+   * Tests the <CODE>bindInProgress</CODE> method.
+   */
+  @Test()
+  public void testBindInProgress()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    assertFalse(conn.bindInProgress());
+  }
+
+
+
+  /**
+   * Tests the <CODE>setBindInProgress</CODE> method.
+   */
+  @Test()
+  public void testSetBindInProgress()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    conn.setBindInProgress(true);
+    assertFalse(conn.bindInProgress());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getOperationsInProgress</CODE> method.
+   */
+  @Test()
+  public void testGetOperationsInProgress()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    Collection<Operation> opList = conn.getOperationsInProgress();
+    assertNotNull(opList);
+    assertTrue(opList.isEmpty());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getOperationInProgress</CODE> method.
+   */
+  @Test()
+  public void testGetOperationInProgress()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    assertNull(conn.getOperationInProgress(0));
+  }
+
+
+
+  /**
+   * Tests the <CODE>removeOperationInProgress</CODE> method.
+   */
+  @Test()
+  public void testRemoveOperationInProgress()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    assertFalse(conn.removeOperationInProgress(1));
+  }
+
+
+
+  /**
+   * Tests the <CODE>cancelOperation</CODE> method.
+   */
+  @Test()
+  public void testCancelOperation()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    CancelResult cancelResult =
+         conn.cancelOperation(1,
+              new CancelRequest(true, "testCancelOperation"));
+    assertEquals(cancelResult, CancelResult.CANNOT_CANCEL);
+  }
+
+
+
+  /**
+   * Tests the <CODE>cancelAllOperations</CODE> method.
+   */
+  @Test()
+  public void testCancelAllOperations()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    conn.cancelAllOperations(new CancelRequest(true, "testCancelOperation"));
+  }
+
+
+
+  /**
+   * Tests the <CODE>cancelAllOperationsExcept</CODE> method.
+   */
+  @Test()
+  public void testCancelAllOperationsExcept()
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    conn.cancelAllOperationsExcept(
+         new CancelRequest(true, "testCancelOperation"), 1);
+  }
+
+
+
+  /**
+   * Tests the <CODE>toString</CODE> method.
+   */
+  @Test()
+  public void testToString()
+  {
+    StringBuilder buffer = new StringBuilder();
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    conn.toString(buffer);
+
+    assertFalse(buffer.toString().equals(""));
+  }
+}
+
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalConnectionHandlerTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalConnectionHandlerTestCase.java
new file mode 100644
index 0000000..f552f50
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalConnectionHandlerTestCase.java
@@ -0,0 +1,142 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.protocols.internal;
+
+
+
+import java.util.Collection;
+
+import org.testng.annotations.Test;
+
+import org.opends.server.api.ClientConnection;
+
+import static org.testng.Assert.*;
+
+
+
+/**
+ * This class defines a set of tests for the
+ * org.opends.server.protocols.internal.InternalConnectionHandler class.
+ */
+public class InternalConnectionHandlerTestCase
+       extends InternalTestCase
+{
+  /**
+   * Retrieves an instance of the connection handler and initializes it.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testGetInstanceAndInitialize()
+         throws Exception
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    handler.initializeConnectionHandler(null);
+  }
+
+
+
+  /**
+   * Tests the <CODE>finalizeConnectionHandler</CODE> method.
+   */
+  @Test()
+  public void testFinalizeConnectionHandler()
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    handler.finalizeConnectionHandler(null, false);
+  }
+
+
+
+  /**
+   * Tests the <CODE>getClientConnections</CODE> method.
+   */
+  @Test()
+  public void testGetClientConnections()
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    Collection<ClientConnection> connections = handler.getClientConnections();
+    assertNotNull(connections);
+    assertTrue(connections.isEmpty());
+  }
+
+
+
+  /**
+   * Tests the <CODE>run</CODE> method.  This will make sure that it returns as
+   * expected rather than actually running as a thread.
+   */
+  @Test()
+  public void testRun()
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    handler.run();
+  }
+
+
+
+  /**
+   * Tests the first <CODE>toString</CODE> method, which doesn't take any
+   * arguments.
+   */
+  @Test()
+  public void testToString1()
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    String s = handler.toString();
+    assertNotNull(s);
+    assertFalse(s.equals(""));
+  }
+
+
+
+  /**
+   * Tests the second <CODE>toString</CODE> method, which takes a
+   * <CODE>StringBuilder</CODE> argument.
+   */
+  @Test()
+  public void testToString2()
+  {
+    InternalConnectionHandler handler = InternalConnectionHandler.getInstance();
+    assertNotNull(handler);
+
+    StringBuilder buffer = new StringBuilder();
+    handler.toString(buffer);
+    assertFalse(buffer.toString().equals(""));
+  }
+}
+
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java
new file mode 100644
index 0000000..17144b7
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalSearchOperationTestCase.java
@@ -0,0 +1,310 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.protocols.internal;
+
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.opends.server.TestCaseUtils;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.protocols.ldap.LDAPFilter;
+import org.opends.server.types.Control;
+import org.opends.server.types.DereferencePolicy;
+import org.opends.server.types.DN;
+import org.opends.server.types.Entry;
+import org.opends.server.types.ResultCode;
+import org.opends.server.types.SearchScope;
+import org.opends.server.types.SearchFilter;
+import org.opends.server.types.SearchResultEntry;
+import org.opends.server.types.SearchResultReference;
+
+import static org.testng.Assert.*;
+
+
+
+/**
+ * This class defines a set of tests for the
+ * org.opends.server.protocols.internal.InternalSearchOperation class.
+ */
+public class InternalSearchOperationTestCase
+       extends InternalTestCase
+{
+  /**
+   * Ensures that the Directory Server is running.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @BeforeClass()
+  public void startServer()
+         throws Exception
+  {
+    TestCaseUtils.startServer();
+  }
+
+
+
+  /**
+   * Tests the first constructor, which takes raw arguments, without providing
+   * an internal search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testConstructor1WithoutListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    new InternalSearchOperation(conn, conn.nextOperationID(),
+                                conn.nextMessageID(), new ArrayList<Control>(),
+                                new ASN1OctetString(), SearchScope.BASE_OBJECT,
+                                DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0,
+                                false, LDAPFilter.decode("(objectClass=*)"),
+                                new LinkedHashSet<String>(), null);
+  }
+
+
+
+  /**
+   * Tests the first constructor, which takes raw arguments, with an internal
+   * search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testConstructor1WithListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    new InternalSearchOperation(conn, conn.nextOperationID(),
+                                conn.nextMessageID(), new ArrayList<Control>(),
+                                new ASN1OctetString(), SearchScope.BASE_OBJECT,
+                                DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0,
+                                false, LDAPFilter.decode("(objectClass=*)"),
+                                new LinkedHashSet<String>(),
+                                new TestInternalSearchListener());
+  }
+
+
+
+  /**
+   * Tests the second constructor, which takes processed arguments, without
+   * providing an internal search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testConstructor2WithoutListener()
+         throws Exception
+  {
+    SearchFilter searchFilter =
+         SearchFilter.createFilterFromString("(objectClass=*)");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    new InternalSearchOperation(conn, conn.nextOperationID(),
+                                conn.nextMessageID(), new ArrayList<Control>(),
+                                new DN(), SearchScope.BASE_OBJECT,
+                                DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0,
+                                false, searchFilter,
+                                new LinkedHashSet<String>(), null);
+  }
+
+
+
+  /**
+   * Tests the second constructor, which takes processed arguments, with an
+   * internal search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testConstructor2WithListener()
+         throws Exception
+  {
+    SearchFilter searchFilter =
+         SearchFilter.createFilterFromString("(objectClass=*)");
+
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    new InternalSearchOperation(conn, conn.nextOperationID(),
+                                conn.nextMessageID(), new ArrayList<Control>(),
+                                new DN(), SearchScope.BASE_OBJECT,
+                                DereferencePolicy.NEVER_DEREF_ALIASES, 0, 0,
+                                false, searchFilter,
+                                new LinkedHashSet<String>(),
+                                new TestInternalSearchListener());
+  }
+
+
+
+  /**
+   * Tests the <CODE>getSearchEntries</CODE> and
+   * <CODE>getSearchReferences</CODE> methods.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testGetSearchEntriesAndReferences()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         conn.processSearch(new ASN1OctetString(""), SearchScope.BASE_OBJECT,
+                            LDAPFilter.decode("(objectClass=*)"));
+    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
+    assertFalse(searchOperation.getSearchEntries().isEmpty());
+    assertTrue(searchOperation.getSearchReferences().isEmpty());
+  }
+
+
+
+  /**
+   * Tests the <CODE>addSearchEntry</CODE> method without a search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testAddSearchEntryWithoutListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         new InternalSearchOperation(conn, conn.nextOperationID(),
+                                     conn.nextMessageID(),
+                                     new ArrayList<Control>(),
+                                     new ASN1OctetString(),
+                                     SearchScope.BASE_OBJECT,
+                                     DereferencePolicy.NEVER_DEREF_ALIASES, 0,
+                                     0, false,
+                                     LDAPFilter.decode("(objectClass=*)"),
+                                     new LinkedHashSet<String>(), null);
+
+    Entry e = TestCaseUtils.makeEntry("dn: ",
+                                      "objectClass: top",
+                                      "objectClass: ds-root-dse");
+    searchOperation.addSearchEntry(new SearchResultEntry(e));
+  }
+
+
+
+  /**
+   * Tests the <CODE>addSearchEntry</CODE> method with a search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testAddSearchEntryWithListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         new InternalSearchOperation(conn, conn.nextOperationID(),
+                                     conn.nextMessageID(),
+                                     new ArrayList<Control>(),
+                                     new ASN1OctetString(),
+                                     SearchScope.BASE_OBJECT,
+                                     DereferencePolicy.NEVER_DEREF_ALIASES, 0,
+                                     0, false,
+                                     LDAPFilter.decode("(objectClass=*)"),
+                                     new LinkedHashSet<String>(),
+                                     new TestInternalSearchListener());
+
+    Entry e = TestCaseUtils.makeEntry("dn: ",
+                                      "objectClass: top",
+                                      "objectClass: ds-root-dse");
+    searchOperation.addSearchEntry(new SearchResultEntry(e));
+  }
+
+
+
+  /**
+   * Tests the <CODE>addSearchReference</CODE> method without a search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testAddSearchReferenceWithoutListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         new InternalSearchOperation(conn, conn.nextOperationID(),
+                                     conn.nextMessageID(),
+                                     new ArrayList<Control>(),
+                                     new ASN1OctetString(),
+                                     SearchScope.BASE_OBJECT,
+                                     DereferencePolicy.NEVER_DEREF_ALIASES, 0,
+                                     0, false,
+                                     LDAPFilter.decode("(objectClass=*)"),
+                                     new LinkedHashSet<String>(), null);
+
+    SearchResultReference reference =
+         new SearchResultReference("ldap://server.example.com:389/");
+    searchOperation.addSearchReference(reference);
+  }
+
+
+
+  /**
+   * Tests the <CODE>addSearchReference</CODE> method with a search listener.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testAddSearchReferenceWithListener()
+         throws Exception
+  {
+    InternalClientConnection conn =
+         InternalClientConnection.getRootConnection();
+    InternalSearchOperation searchOperation =
+         new InternalSearchOperation(conn, conn.nextOperationID(),
+                                     conn.nextMessageID(),
+                                     new ArrayList<Control>(),
+                                     new ASN1OctetString(),
+                                     SearchScope.BASE_OBJECT,
+                                     DereferencePolicy.NEVER_DEREF_ALIASES, 0,
+                                     0, false,
+                                     LDAPFilter.decode("(objectClass=*)"),
+                                     new LinkedHashSet<String>(),
+                                     new TestInternalSearchListener());
+
+    SearchResultReference reference =
+         new SearchResultReference("ldap://server.example.com:389/");
+    searchOperation.addSearchReference(reference);
+  }
+}
+
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalTestCase.java
new file mode 100644
index 0000000..144dffc
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/InternalTestCase.java
@@ -0,0 +1,45 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.protocols.internal;
+
+
+
+import org.opends.server.DirectoryServerTestCase;
+import org.testng.annotations.Test;
+
+
+
+/**
+ * An abstract base class for all ASN1 test cases.
+ */
+@Test(groups = { "precommit", "internal" })
+public abstract class InternalTestCase
+       extends DirectoryServerTestCase
+{
+  // No implementation required.
+}
+
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/TestInternalSearchListener.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/TestInternalSearchListener.java
new file mode 100644
index 0000000..44e3004
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/internal/TestInternalSearchListener.java
@@ -0,0 +1,110 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.protocols.internal;
+
+
+
+import java.util.ArrayList;
+
+import org.opends.server.types.SearchResultEntry;
+import org.opends.server.types.SearchResultReference;
+
+
+
+
+/**
+ * This class provides an internal search listener that may be used for testing
+ * purposes.  It merely stores the entries and referrals in an internal list.
+ */
+public class TestInternalSearchListener
+       implements InternalSearchListener
+{
+  // The list of search result entries returned.
+  private ArrayList<SearchResultEntry> searchEntries;
+
+  // The list of search result references returned.
+  private ArrayList<SearchResultReference> searchReferences;
+
+
+
+  /**
+   * Creates a new instance of this test internal search listener.
+   */
+  public TestInternalSearchListener()
+  {
+    searchEntries    = new ArrayList<SearchResultEntry>();
+    searchReferences = new ArrayList<SearchResultReference>();
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public void handleInternalSearchEntry(InternalSearchOperation searchOperation,
+                                        SearchResultEntry searchEntry)
+  {
+    searchEntries.add(searchEntry);
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public void handleInternalSearchReference(
+                   InternalSearchOperation searchOperation,
+                   SearchResultReference searchReference)
+  {
+    searchReferences.add(searchReference);
+  }
+
+
+
+  /**
+   * Retrieves the set of search result entries returned for the search.
+   *
+   * @return  The set of search result entries returned for the search.
+   */
+  public ArrayList<SearchResultEntry> getSearchEntries()
+  {
+    return searchEntries;
+  }
+
+
+
+  /**
+   * Retrieves the set of search result references returned for the search.
+   *
+   * @return  The set of search result references returned for the search.
+   */
+  public ArrayList<SearchResultReference> getSearchReferences()
+  {
+    return searchReferences;
+  }
+}
+

--
Gitblit v1.10.0