mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

coulbeck
13.02.2006 493420530b6f5f84ea319089836156496b4056be
Added a test case for search operation that needs the JE backend rather than the memory backend.  There are now multiple test cases using the same JE backend, so add TestCaseUtils#clearJEBackend in those test cases to clear any existing data in the JE backend.
4 files modified
273 ■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/BackendImpl.java 22 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java 56 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java 184 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java 11 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -1452,4 +1452,26 @@
    assert debugEnter(CLASS_NAME, "getRootContainer");
    return rootContainer;
  }
  /**
   * Clears all the entries from the backend.  This method is for test cases
   * that use the JE backend.
   *
   * @param  configEntry  The configuration entry that contains the information
   *                      to use to initialize this backend.
   * @param  baseDNs      The set of base DNs that have been configured for this
   *                      backend.
   *
   * @throws  ConfigException  If an unrecoverable problem arises in the
   *                           process of performing the initialization.
   *
   * @throws  JebException     If an error occurs while removing the data.
   */
  public void clearBackend(ConfigEntry configEntry, DN[] baseDNs)
       throws ConfigException, JebException
  {
    Config config = new Config();
    config.initializeConfig(configEntry, baseDNs);
    EnvManager.removeFiles(config.getBackendDirectory().getPath());
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -38,9 +38,12 @@
import java.net.SocketException;
import org.opends.server.backends.MemoryBackend;
import org.opends.server.backends.jeb.BackendImpl;
import org.opends.server.config.ConfigException;
import org.opends.server.config.ConfigFileHandler;
import org.opends.server.config.ConfigEntry;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.LockFileManager;
import org.opends.server.loggers.Error;
import org.opends.server.loggers.Debug;
import org.opends.server.plugins.InvocationCounterPlugin;
@@ -53,6 +56,7 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import org.opends.server.tasks.TaskUtils;
/**
 * This class defines some utility functions which can be used by test
@@ -263,7 +267,7 @@
   * @return the bounded Server socket.
   *
   * @throws IOException in case of underlying exception.
   * @throws SocketExceptionin case of underlying exception.
   * @throws SocketException in case of underlying exception.
   */
  public static ServerSocket bindFreePort() throws IOException, SocketException
  {
@@ -326,6 +330,56 @@
  }
  /**
   * Clears all the entries from the userRoot JE backend.
   * @param  createBaseEntry  Indicate whether to automatically create the base
   *                          entry and add it to the backend.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  public static void clearJEBackend(boolean createBaseEntry)
       throws Exception
  {
    BackendImpl backend = (BackendImpl)DirectoryServer.getBackend("userRoot");
    DN[] baseDNs = backend.getBaseDNs();
    ConfigEntry configEntry = TaskUtils.getConfigEntry(backend);
    TaskUtils.setBackendEnabled(configEntry, false);
    try
    {
      String lockFile = LockFileManager.getBackendLockFileName(backend);
      StringBuilder failureReason = new StringBuilder();
      if (!LockFileManager.acquireExclusiveLock(lockFile, failureReason))
      {
        throw new RuntimeException(failureReason.toString());
      }
      try
      {
        backend.clearBackend(configEntry, baseDNs);
      }
      finally
      {
        LockFileManager.releaseLock(lockFile, failureReason);
      }
    }
    finally
    {
      TaskUtils.setBackendEnabled(configEntry, true);
    }
    if (createBaseEntry)
    {
      DN baseDN = DN.decode("dc=example,dc=com");
      Entry e = createEntry(baseDN);
      backend = (BackendImpl)DirectoryServer.getBackend("userRoot");
      backend.addEntry(e, null);
    }
  }
  /**
   * Create a temporary directory with the specified prefix.
   *
   * @param prefix
opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
@@ -33,9 +33,11 @@
import org.opends.server.protocols.asn1.ASN1Reader;
import org.opends.server.protocols.asn1.ASN1Writer;
import org.opends.server.protocols.asn1.ASN1Exception;
import org.opends.server.protocols.asn1.ASN1Element;
import org.opends.server.protocols.ldap.*;
import org.opends.server.types.*;
import org.opends.server.TestCaseUtils;
import org.opends.server.util.StaticUtils;
import org.opends.server.controls.MatchedValuesFilter;
import org.opends.server.controls.MatchedValuesControl;
import org.opends.server.plugins.InvocationCounterPlugin;
@@ -47,26 +49,58 @@
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.net.Socket;
import java.io.IOException;
public class SearchOperationTestCase extends OperationTestCase
{
  private Entry entry;
  private static final String SUFFIX = "dc=example,dc=com";
  private static final String BASE = "o=Test Core Search,dc=example,dc=com";
  private Entry testEntry;
  private int ldapAttrCount;
  @BeforeClass
  public void setUp() throws Exception
  {
    TestCaseUtils.startServer();
    TestCaseUtils.initializeTestBackend(true);
    TestCaseUtils.clearJEBackend(true);
    InternalClientConnection connection =
         InternalClientConnection.getRootConnection();
    // Add the suffix entry.
    DN suffixDN = DN.decode(SUFFIX);
    if (DirectoryServer.getEntry(suffixDN) == null)
    {
      Entry suffixEntry = StaticUtils.createEntry(suffixDN);
      AddOperation addOperation =
           connection.processAdd(suffixEntry.getDN(),
                                 suffixEntry.getObjectClasses(),
                                 suffixEntry.getUserAttributes(),
                                 suffixEntry.getOperationalAttributes());
      assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
      assertNotNull(DirectoryServer.getEntry(suffixEntry.getDN()));
    }
    // Add a search base entry.
    DN baseDN = DN.decode(BASE);
    if (DirectoryServer.getEntry(baseDN) == null)
    {
      Entry baseEntry = StaticUtils.createEntry(baseDN);
      AddOperation addOperation =
           connection.processAdd(baseEntry.getDN(),
                                 baseEntry.getObjectClasses(),
                                 baseEntry.getUserAttributes(),
                                 baseEntry.getOperationalAttributes());
      assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
      assertNotNull(DirectoryServer.getEntry(baseEntry.getDN()));
    }
    // Add a test entry.
    entry = TestCaseUtils.makeEntry(
         "dn: uid=rogasawara,o=test",
    testEntry = TestCaseUtils.makeEntry(
         "dn: uid=rogasawara," + BASE,
         "userpassword: password",
         "objectclass: top",
         "objectclass: person",
@@ -96,13 +130,13 @@
    // Calculate the total number of LDAP attributes in this entry.
    ldapAttrCount = 1; // For the objectclass attribute.
    for (Attribute a : entry.getAttributes())
    for (Attribute a : testEntry.getAttributes())
    {
      ldapAttrCount += a.getValues().size();
    }
    // The add operation changes the attributes, so let's duplicate the entry.
    Entry duplicateEntry = entry.duplicate();
    Entry duplicateEntry = testEntry.duplicate();
    AddOperation addOperation =
         connection.processAdd(duplicateEntry.getDN(),
@@ -110,11 +144,11 @@
                               duplicateEntry.getUserAttributes(),
                               duplicateEntry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    assertNotNull(DirectoryServer.getEntry(entry.getDN()));
    assertNotNull(DirectoryServer.getEntry(testEntry.getDN()));
    // Add a test ldapsubentry.
    Entry ldapSubentry = TestCaseUtils.makeEntry(
         "dn: cn=subentry,o=test",
         "dn: cn=subentry," + BASE,
         "objectclass: ldapsubentry");
    addOperation =
         connection.processAdd(ldapSubentry.getDN(),
@@ -123,6 +157,21 @@
                               ldapSubentry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    assertNotNull(DirectoryServer.getEntry(ldapSubentry.getDN()));
    // Add a test referral entry.
    Entry referralEntry = TestCaseUtils.makeEntry(
         "dn: ou=People," + BASE,
         "objectclass: extensibleobject",
         "objectclass: referral",
         "ref: ldap://hostb/OU=People,O=MNN,C=US",
         "ref: ldap://hostc/OU=People,O=MNN,C=US");
    addOperation =
         connection.processAdd(referralEntry.getDN(),
                               referralEntry.getObjectClasses(),
                               referralEntry.getUserAttributes(),
                               referralEntry.getOperationalAttributes());
    assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
    assertNotNull(DirectoryServer.getEntry(referralEntry.getDN()));
  }
@@ -137,7 +186,7 @@
                             InternalClientConnection.nextOperationID(),
                             InternalClientConnection.nextMessageID(),
                             new ArrayList<Control>(),
                             new ASN1OctetString("o=test"),
                             new ASN1OctetString(BASE),
                             SearchScope.WHOLE_SUBTREE,
                             DereferencePolicy.NEVER_DEREF_ALIASES,
                             -1,
@@ -203,16 +252,29 @@
      message = new LDAPMessage(2, searchRequest, controls);
      w.writeElement(message.encode());
      message = LDAPMessage.decode(r.readElement().decodeAsSequence());
      SearchResultEntryProtocolOp searchResultEntry =
           message.getSearchResultEntryProtocolOp();
      SearchResultEntryProtocolOp searchResultEntry = null;
      SearchResultDoneProtocolOp searchResultDone = null;
      ASN1Element element;
      while (searchResultDone == null && (element = r.readElement()) != null)
      {
        message = LDAPMessage.decode(element.decodeAsSequence());
        switch (message.getProtocolOpType())
        {
          case LDAPConstants.OP_TYPE_SEARCH_RESULT_ENTRY:
            searchResultEntry = message.getSearchResultEntryProtocolOp();
            break;
      message = LDAPMessage.decode(r.readElement().decodeAsSequence());
      SearchResultDoneProtocolOp searchResultDone =
           message.getSearchResultDoneProtocolOp();
          case LDAPConstants.OP_TYPE_SEARCH_RESULT_REFERENCE:
            break;
      assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
      assertEquals(searchResultDone.getResultCode(), LDAPResultCode.SUCCESS);
          case LDAPConstants.OP_TYPE_SEARCH_RESULT_DONE:
            searchResultDone = message.getSearchResultDoneProtocolOp();
            assertEquals(searchResultDone.getResultCode(),
                         LDAPResultCode.SUCCESS);
            assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1);
            break;
        }
      }
      return searchResultEntry;
    }
@@ -253,7 +315,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -265,6 +327,7 @@
    searchOperation.run();
    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
    assertEquals(searchOperation.getEntriesSent(), 2);
    assertEquals(searchOperation.getReferencesSent(), 1);
    assertEquals(searchOperation.getErrorMessage().length(), 0);
    examineCompletedOperation(searchOperation);
@@ -282,7 +345,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -293,9 +356,9 @@
    Entry resultEntry = searchInternalForSingleEntry(searchOperation);
    assertEquals(resultEntry.getObjectClasses(), entry.getObjectClasses());
    assertEquals(resultEntry.getObjectClasses(), testEntry.getObjectClasses());
    assertEquals(resultEntry.getUserAttributes().size(),
                 entry.getUserAttributes().size());
                 testEntry.getUserAttributes().size());
    assertEquals(resultEntry.getOperationalAttributes().size(), 0);
  }
@@ -312,7 +375,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -325,7 +388,7 @@
    assertEquals(resultEntry.getObjectClasses().size(), 0);
    assertEquals(resultEntry.getUserAttributes().size(),
                 entry.getUserAttributes().size() + 1);
                 testEntry.getUserAttributes().size() + 1);
    assertEquals(resultEntry.getOperationalAttributes().size(), 0);
  }
@@ -343,7 +406,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -375,7 +438,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -386,10 +449,10 @@
    Entry resultEntry = searchInternalForSingleEntry(searchOperation);
    assertEquals(resultEntry.getObjectClasses(), entry.getObjectClasses());
    assertEquals(resultEntry.getObjectClasses(), testEntry.getObjectClasses());
    assertTrue(resultEntry.getOperationalAttributes().size() > 0);
    assertEquals(resultEntry.getUserAttributes().size(),
                 entry.getUserAttributes().size());
                 testEntry.getUserAttributes().size());
  }
  @Test
@@ -408,7 +471,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -419,9 +482,9 @@
    Entry resultEntry = searchInternalForSingleEntry(searchOperation);
    assertEquals(resultEntry.getObjectClasses(), entry.getObjectClasses());
    assertEquals(resultEntry.getObjectClasses(), testEntry.getObjectClasses());
    assertEquals(resultEntry.getUserAttributes().size(),
                 entry.getUserAttributes().size());
                 testEntry.getUserAttributes().size());
    assertEquals(resultEntry.getOperationalAttributes().size(), 1);
  }
@@ -441,7 +504,7 @@
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -462,7 +525,7 @@
  {
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -482,7 +545,7 @@
    attributes.add("*");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -501,7 +564,7 @@
  {
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -526,7 +589,7 @@
    attributes.add("*");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -551,7 +614,7 @@
    attributes.add("objectclass");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -576,7 +639,7 @@
    attributes.add("objectclass");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -601,7 +664,7 @@
    attributes.add("createtimestamp");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -623,7 +686,7 @@
    attributes.add("title");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -646,7 +709,7 @@
    attributes.add("title");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -672,7 +735,7 @@
    attributes.add("title;lang-ja;phonetic");
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -703,7 +766,7 @@
    SearchRequestProtocolOp searchRequest =
         new SearchRequestProtocolOp(
              new ASN1OctetString("o=test"),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
@@ -726,4 +789,41 @@
    assertEquals(valueCount, 1);
  }
  @Test
  public void testSearchInternalReferences() throws Exception
  {
    InvocationCounterPlugin.resetAllCounters();
    InternalClientConnection conn =
         InternalClientConnection.getRootConnection();
    InternalSearchOperation searchOperation =
         new InternalSearchOperation(
              conn,
              InternalClientConnection.nextOperationID(),
              InternalClientConnection.nextMessageID(),
              new ArrayList<Control>(),
              new ASN1OctetString(BASE),
              SearchScope.WHOLE_SUBTREE,
              DereferencePolicy.NEVER_DEREF_ALIASES,
              Integer.MAX_VALUE,
              Integer.MAX_VALUE,
              false,
              LDAPFilter.decode("(objectclass=inetorgperson)"),
              null, null);
    searchOperation.run();
    assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
    assertEquals(searchOperation.getReferencesSent(), 1);
    assertEquals(searchOperation.getErrorMessage().length(), 0);
    examineCompletedOperation(searchOperation);
    List<SearchResultReference> references =
         searchOperation.getSearchReferences();
    assertEquals(references.size(), 1);
    List<String> referrals = references.get(0).getReferralURLs();
    assertEquals(referrals.size(), 2);
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
@@ -54,24 +54,19 @@
public class TestModifyDNOperation extends OperationTestCase
{
  private Entry exampleCom;
  private Entry people;
  private Entry entry;
  private Entry entry1;
  private Entry entry2;
  private Object[][] parameters;
  @BeforeClass
  public void setUp() throws Exception
  {
    TestCaseUtils.startServer();
    TestCaseUtils.initializeTestBackend(true);
    TestCaseUtils.clearJEBackend(false);
    InternalClientConnection connection =
         InternalClientConnection.getRootConnection();
    // Add the example.com entry
    exampleCom = TestCaseUtils.makeEntry(
    Entry exampleCom = TestCaseUtils.makeEntry(
      "dn: dc=example,dc=com",
      "objectclass: top",
      "objectclass: domain",
@@ -79,7 +74,7 @@
    );
    // Add the people entry
    people = TestCaseUtils.makeEntry(
    Entry people = TestCaseUtils.makeEntry(
      "dn: ou=People,dc=example,dc=com",
      "objectclass: top",
      "objectclass: organizationalUnit",