From c3c3a652d26f7c6515aad1bfac8e64845bd6b87d Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 25 Nov 2015 15:09:53 +0000
Subject: [PATCH] Delete tests specific to local-db
---
/dev/null | 921 ---------------------------------------------------------
1 files changed, 0 insertions(+), 921 deletions(-)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java
deleted file mode 100644
index 21e7154..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestBackendImpl.java
+++ /dev/null
@@ -1,1557 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.forgerock.opendj.ldap.SearchScope;
-import org.forgerock.opendj.ldap.schema.MatchingRule;
-import org.forgerock.opendj.ldap.spi.IndexingOptions;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.admin.server.AdminTestCaseUtils;
-import org.opends.server.admin.std.meta.LocalDBBackendCfgDefn;
-import org.opends.server.admin.std.server.LocalDBBackendCfg;
-import org.opends.server.backends.jeb.BackendImpl.JELogFilesIterator;
-import org.opends.server.controls.SubtreeDeleteControl;
-import org.opends.server.core.DeleteOperationBasis;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.core.ModifyDNOperationBasis;
-import org.opends.server.core.ModifyOperationBasis;
-import org.opends.server.protocols.internal.InternalClientConnection;
-import org.opends.server.protocols.internal.InternalSearchOperation;
-import org.opends.server.protocols.internal.SearchRequest;
-import org.opends.server.types.Attribute;
-import org.opends.server.types.AttributeBuilder;
-import org.opends.server.types.AttributeType;
-import org.opends.server.types.Attributes;
-import org.opends.server.types.Control;
-import org.opends.server.types.DN;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.Entry;
-import org.opends.server.types.Modification;
-import org.opends.server.types.RDN;
-import org.opends.server.types.SearchResultEntry;
-import org.opends.server.util.Base64;
-import org.opends.server.util.StaticUtils;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import com.sleepycat.je.DatabaseEntry;
-import com.sleepycat.je.LockMode;
-
-import static java.util.Collections.*;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.forgerock.opendj.ldap.ConditionResult.*;
-import static org.forgerock.opendj.ldap.ModificationType.*;
-import static org.mockito.Mockito.*;
-import static org.opends.server.backends.pluggable.SuffixContainer.*;
-import static org.opends.server.protocols.internal.InternalClientConnection.*;
-import static org.opends.server.protocols.internal.Requests.*;
-import static org.opends.server.schema.SchemaConstants.*;
-import static org.opends.server.types.Attributes.*;
-import static org.opends.server.util.StaticUtils.*;
-import static org.testng.Assert.*;
-
-/** BackendImpl Tester. */
-@SuppressWarnings("javadoc")
-public class TestBackendImpl extends JebTestCase {
-
- private String homeDirName;
-
- private BackendImpl backend;
-
- private AttributeType givenName;
- private AttributeType title;
- private AttributeType name;
-
- private List<Entry> topEntries;
- private List<Entry> entries;
- private List<Entry> additionalEntries;
- private Entry replaceEntry;
- private Entry newTop;
-
- @BeforeClass
- public void setUp() throws Exception {
- // This test suite depends on having the schema available, so we'll make
- // sure the server is started.
- TestCaseUtils.startServer();
- TestCaseUtils.enableBackend("indexRoot");
-
- homeDirName = "db_index_test";
-
- backend = (BackendImpl)DirectoryServer.getBackend("indexRoot");
-
- topEntries = TestCaseUtils.makeEntries(
- "dn: dc=test,dc=com",
- "objectclass: top",
- "objectclass: domain",
- "dc: example",
- "",
- "dn: ou=People,dc=test,dc=com",
- "objectclass: top",
- "objectclass: organizationalUnit",
- "ou: People",
- "",
- "dn: dc=test1,dc=com",
- "objectclass: top",
- "objectclass: domain",
- "dc: example1");
- entries = TestCaseUtils.makeEntries(
- "dn: uid=user.0,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Aaccf",
- "sn: Amar",
- "cn: Aaccf Amar",
- "initials: AQA",
- "employeeNumber: 0",
- "uid: user.0",
- "mail: user.0@example.com",
- "userPassword: password",
- "telephoneNumber: 380-535-2354",
- "homePhone: 707-626-3913",
- "pager: 456-345-7750",
- "mobile: 366-674-7274",
- "street: 99262 Eleventh Street",
- "l: Salem",
- "st: NM",
- "postalCode: 36530",
- "postalAddress: Aaccf Amar$99262 Eleventh Street$Salem, NM 36530",
- "description: This is the description for Aaccf Amar.",
- "",
- "dn: uid=user.1,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Aaren",
- "givenName;lang-fr: test2",
- "givenName;lang-cn: test2",
- "givenName;lang-es: test3",
- "sn: Atp",
- "cn: Aaren Atp",
- "initials: APA",
- "employeeNumber: 1",
- "uid: user.1",
- "mail: user.1@example.com",
- "userPassword: password",
- "telephoneNumber: 643-278-6134",
- "homePhone: 546-786-4099",
- "pager: 508-261-3187",
- "mobile: 377-267-7824",
- "carLicense: 377-267-7824",
- "street: 78113 Fifth Street",
- "l: Chico",
- "st: TN",
- "postalCode: 72322",
- "postalAddress: Aaren Atp$78113 Fifth Street$Chico, TN 72322",
- "description: This is the description for Aaren Atp.",
- "",
- "dn: uid=user.2,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Aarika",
- "sn: Atpco",
- "cn: Aarika Atpco",
- "initials: ARA",
- "employeeNumber: 2",
- "uid: user.2",
- "mail: user.2@example.com",
- "userPassword: password",
- "telephoneNumber: 547-504-3498",
- "homePhone: 955-899-7308",
- "pager: 710-832-9316",
- "mobile: 688-388-4525",
- "carLicense: 688-388-4525",
- "street: 59208 Elm Street",
- "l: Youngstown",
- "st: HI",
- "postalCode: 57377",
- "postalAddress: Aarika Atpco$59208 Elm Street$Youngstown, HI 57377",
- "description: This is the description for Aarika Atpco.",
- "",
- "dn: uid=user.3,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Aaron",
- "sn: Atrc",
- "cn: Aaron Atrc",
- "initials: AIA",
- "employeeNumber: 3",
- "uid: user.3",
- "mail: user.3@example.com",
- "userPassword: password",
- "telephoneNumber: 128-108-4939",
- "homePhone: 512-782-9966",
- "pager: 322-646-5118",
- "mobile: 360-957-9137",
- "carLicense: 360-957-9137",
- "street: 25074 Hill Street",
- "l: Toledo",
- "st: OR",
- "postalCode: 55237",
- "postalAddress: Aaron Atrc$25074 Hill Street$Toledo, OR 55237",
- "description: This is the description for Aaron Atrc.",
- "",
- "dn: uid=user.4,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Aartjan",
- "sn: Aalders",
- "cn: Aartjan Aalders",
- "initials: ALA",
- "employeeNumber: 4",
- "uid: user.4",
- "mail: user.4@example.com",
- "userPassword: password",
- "telephoneNumber: 981-148-3303",
- "homePhone: 196-877-2684",
- "pager: 910-998-4607",
- "mobile: 123-239-8262",
- "carLicense: 123-239-8262",
- "street: 81512 Sunset Street",
- "l: Chattanooga",
- "st: WV",
- "postalCode: 29530",
- "postalAddress: Aartjan Aalders$81512 Sunset Street$Chattanooga, WV 29530",
- "description: This is the description for Aartjan Aalders.",
- "",
- "dn: uid=user.5,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abagael",
- "sn: Aasen",
- "cn: Abagael Aasen",
- "initials: AKA",
- "employeeNumber: 5",
- "uid: user.5",
- "mail: user.5@example.com",
- "userPassword: password",
- "telephoneNumber: 930-493-2391",
- "homePhone: 078-254-3960",
- "pager: 281-936-8197",
- "mobile: 559-822-7712",
- "carLicense: 559-822-7712",
- "street: 31988 Central Street",
- "l: Chico",
- "st: MS",
- "postalCode: 20135",
- "postalAddress: Abagael Aasen$31988 Central Street$Chico, MS 20135",
- "description: This is the description for Abagael Aasen.",
- "",
- "dn: uid=user.6,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abagail",
- "sn: Abadines",
- "cn: Abagail Abadines",
- "initials: AQA",
- "employeeNumber: 6",
- "uid: user.6",
- "mail: user.6@example.com",
- "userPassword: password",
- "telephoneNumber: 110-761-3861",
- "homePhone: 459-123-0553",
- "pager: 799-151-2688",
- "mobile: 953-582-7252",
- "carLicense: 953-582-7252",
- "street: 60100 Dogwood Street",
- "l: Hartford",
- "st: NE",
- "postalCode: 79353",
- "postalAddress: Abagail Abadines$60100 Dogwood Street$Hartford, NE 79353",
- "description: This is the description for Abagail Abadines.",
- "",
- "dn: uid=user.7,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abahri",
- "sn: Abazari",
- "cn: Abahri Abazari",
- "initials: AXA",
- "employeeNumber: 7",
- "uid: user.7",
- "mail: user.7@example.com",
- "userPassword: password",
- "telephoneNumber: 594-537-4292",
- "homePhone: 174-724-6390",
- "pager: 733-217-8194",
- "mobile: 879-706-0172",
- "carLicense: 879-706-0172",
- "street: 77693 Oak Street",
- "l: Philadelphia",
- "st: MN",
- "postalCode: 78550",
- "postalAddress: Abahri Abazari$77693 Oak Street$Philadelphia, MN 78550",
- "description: This is the description for Abahri Abazari.",
- "",
- "dn: uid=user.8,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abbas",
- "sn: Abbatantuono",
- "cn: Abbas Abbatantuono",
- "initials: AVA",
- "employeeNumber: 8",
- "uid: user.8",
- "mail: user.8@example.com",
- "userPassword: password",
- "telephoneNumber: 246-674-8407",
- "homePhone: 039-769-3372",
- "pager: 226-950-2371",
- "mobile: 587-709-2996",
- "carLicense: 587-709-2996",
- "street: 23230 Hill Street",
- "l: Little Rock",
- "st: AR",
- "",
- "dn: uid=user.9,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abbe",
- "sn: Abbate",
- "cn: Abbe Abbate",
- "initials: AWA",
- "employeeNumber: 9",
- "uid: user.9",
- "mail: user.9@example.com",
- "userPassword: password",
- "telephoneNumber: 205-805-3357",
- "homePhone: 770-780-5917",
- "pager: 537-074-8005",
- "mobile: 120-204-7597",
- "carLicense: 120-204-7597",
- "street: 47952 Center Street",
- "l: Butte",
- "st: TN",
- "postalCode: 69384",
- "postalAddress: Abbe Abbate$47952 Center Street$Butte, TN 69384",
- "description: This is the description for Abbe Abbate.",
- "",
- "dn: uid=user.10,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Abbey",
- "sn: Abbie",
- "cn: Abbey Abbie",
- "initials: AZA",
- "employeeNumber: 10",
- "uid: user.10",
- "mail: user.10@example.com",
- "userPassword: password",
- "telephoneNumber: 457-819-0832",
- "homePhone: 931-305-5452",
- "pager: 118-165-7194",
- "mobile: 553-729-5572",
- "carLicense: 553-729-5572",
- "street: 54262 Highland Street",
- "l: Spartanburg",
- "st: PA",
- "postalCode: 38151",
- "postalAddress: Abbey Abbie$54262 Highland Street$Spartanburg, PA 38151",
- "description: This is the description for Abbey Abbie.",
- "",
- "dn: uid=user.539,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Ardyth",
- "sn: Bainton",
- "cn: Ardyth Bainton",
- "initials: AIB",
- "employeeNumber: 539",
- "uid: user.539",
- "mail: user.539@example.com",
- "userPassword: password",
- "telephoneNumber: 641-433-7404",
- "homePhone: 524-765-8780",
- "pager: 985-331-1308",
- "mobile: 279-423-0188",
- "carLicense: 279-423-0188",
- "street: 81170 Taylor Street",
- "l: Syracuse",
- "st: WV",
- "postalCode: 93507",
- "postalAddress: Ardyth Bainton$81170 Taylor Street$Syracuse, WV 93507",
- "description: This is the description for Ardyth Bainton.",
- "",
- "dn: uid=user.446,dc=test1,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Annalee",
- "sn: Avard",
- "cn: Annalee Avard",
- "initials: ANA",
- "employeeNumber: 446",
- "uid: user.446",
- "mail: user.446@example.com",
- "userPassword: password",
- "telephoneNumber: 875-335-2712",
- "homePhone: 181-995-6635",
- "pager: 586-905-4185",
- "mobile: 826-857-7592",
- "carLicense: 826-857-7592",
- "street: 46168 Mill Street",
- "l: Charleston",
- "st: CO",
- "postalCode: 60948",
- "postalAddress: Annalee Avard$46168 Mill Street$Charleston, CO 60948",
- "description: This is the description for Annalee Avard.",
- "",
- "dn: uid=user.362,dc=test1,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Andaree",
- "sn: Asawa",
- "cn: Andaree Asawa",
- "initials: AEA",
- "employeeNumber: 362",
- "uid: user.362",
- "mail: user.362@example.com",
- "userPassword: password",
- "telephoneNumber: 399-788-7334",
- "homePhone: 798-076-5683",
- "pager: 034-026-9411",
- "mobile: 948-743-9197",
- "carLicense: 948-743-9197",
- "street: 81028 Forest Street",
- "l: Wheeling",
- "st: IA",
- "postalCode: 60905",
- "postalAddress: Andaree Asawa$81028 Forest Street$Wheeling, IA 60905",
- "description: This is the description for Andaree Asawa.");
-
- replaceEntry = TestCaseUtils.makeEntry(
- "dn: uid=user.0,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Testing",
- "sn: Test",
- "cn: Testing Test",
- "initials: TT",
- "employeeNumber: 777",
- "uid: user.0",
- "mail: user.0@example.com",
- "userPassword: password",
- "telephoneNumber: 380-535-2354",
- "homePhone: 707-626-3913",
- "pager: 456-345-7750",
- "mobile: 366-674-7274",
- "carLicense: 366-674-7274",
- "street: 99262 Eleventh Street",
- "l: Salem",
- "st: NM",
- "postalCode: 36530",
- "postalAddress: Aaccf Amar$99262 Eleventh Street$Salem, NM 36530",
- "description: This is the description for Aaccf Amar.");
-
- additionalEntries = TestCaseUtils.makeEntries(
- "dn: uid=user.446,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Annalee",
- "sn: Avard",
- "cn: Annalee Avard",
- "initials: ANA",
- "employeeNumber: 446",
- "uid: user.446",
- "mail: user.446@example.com",
- "userPassword: password",
- "telephoneNumber: 875-335-2712",
- "homePhone: 181-995-6635",
- "pager: 586-905-4185",
- "mobile: 826-857-7592",
- "carLicense: 826-857-7592",
- "street: 46168 Mill Street",
- "l: Charleston",
- "st: CO",
- "postalCode: 60948",
- "postalAddress: Annalee Avard$46168 Mill Street$Charleston, CO 60948",
- "description: This is the description for Annalee Avard.",
- "",
- "dn: uid=user.362,ou=People,dc=test,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: Andaree",
- "sn: Asawa",
- "cn: Andaree Asawa",
- "initials: AEA",
- "employeeNumber: 362",
- "uid: user.362",
- "mail: user.362@example.com",
- "userPassword: password",
- "telephoneNumber: 399-788-7334",
- "homePhone: 798-076-5683",
- "pager: 034-026-9411",
- "mobile: 948-743-9197",
- "carLicense: 948-743-9197",
- "street: 81028 Forest Street",
- "l: Wheeling",
- "st: IA",
- "postalCode: 60905",
- "postalAddress: Andaree Asawa$81028 Forest Street$Wheeling, IA 60905",
- "description: This is the description for Andaree Asawa.");
-
- newTop = TestCaseUtils.makeEntry(
- "dn: ou=JEB Testers,dc=test,dc=com",
- "objectclass: top",
- "objectclass: organizationalUnit",
- "ou: People"
- );
-
- givenName = DirectoryServer.getAttributeTypeOrNull("givenname");
- title = DirectoryServer.getAttributeTypeOrNull("title");
- name = DirectoryServer.getAttributeTypeOrNull("name");
- }
-
- @AfterClass
- public void cleanUp() throws Exception {
- TestCaseUtils.disableBackend("importRoot");
- }
-
- /**
- * Note: this test has been rewritten to avoid expectedException in the test annotation because
- * it was skipping all tests that depends on this method
- */
- @Test
- public void testAddNoParent() throws Exception {
- try
- {
- for (Entry entry : entries) {
- backend.addEntry(entry, null);
- }
- failBecauseExceptionWasNotThrown(DirectoryException.class);
- }
- catch (DirectoryException expected)
- {
- // expected
- }
- }
-
- @Test(dependsOnMethods = "testAddNoParent")
- public void testAdd() throws Exception {
- for (Entry topEntry : topEntries) {
- backend.addEntry(topEntry, null);
- assertNotNull(backend.getEntry(topEntry.getName()));
- }
-
- for (Entry entry : entries) {
- backend.addEntry(entry, null);
- assertNotNull(backend.getEntry(entry.getName()));
- }
- }
-
- @Test(dependsOnMethods = "testAdd")
- public void testSearchScope() throws Exception {
- InternalClientConnection conn = getRootConnection();
-
- DN dn = DN.valueOf("dc=test,dc=com");
- InternalSearchOperation search = conn.processSearch(newSearchRequest(dn, SearchScope.BASE_OBJECT));
- List<SearchResultEntry> result = search.getSearchEntries();
-
- assertEquals(result.size(), 1);
- assertEquals(result.get(0).getName(), dn);
-
- search = conn.processSearch(newSearchRequest(dn, SearchScope.BASE_OBJECT, "(ou=People)"));
- result = search.getSearchEntries();
-
- assertEquals(result.size(), 0);
-
- search = conn.processSearch(newSearchRequest(dn, SearchScope.SINGLE_LEVEL));
- result = search.getSearchEntries();
-
- assertEquals(result.size(), 1);
- assertEquals(result.get(0).getName().toString(),
- "ou=People,dc=test,dc=com");
-
- search = conn.processSearch(newSearchRequest(dn, SearchScope.SUBORDINATES));
- result = search.getSearchEntries();
-
- assertEquals(result.size(), 13);
- for (Entry entry : result) {
- assertThat(entry.getName()).isNotEqualTo(dn);
- }
-
- search = conn.processSearch(newSearchRequest(dn, SearchScope.WHOLE_SUBTREE));
- result = search.getSearchEntries();
-
- assertEquals(result.size(), 14);
- }
-
- @Test(dependsOnMethods = "testAdd")
- public void testNumSubordinates() throws Exception
- {
- DN dn = DN.valueOf("dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 1);
- assertEquals(backend.getNumberOfEntriesInBaseDN(dn), 14);
- dn = DN.valueOf("ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 12);
- dn = DN.valueOf("dc=com");
- assertEquals(backend.getNumberOfChildren(dn), -1);
- dn = DN.valueOf("dc=test1,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 2);
- dn = DN.valueOf("uid=user.10,ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 0);
- dn = DN.valueOf("uid=does not exist,ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), -1);
- }
-
- @Test(expectedExceptions = DirectoryException.class)
- public void testCannotGetNumberOfEntriesInNotBaseDN() throws Exception
- {
- backend.getNumberOfEntriesInBaseDN(DN.valueOf("ou=People,dc=test,dc=com"));
- }
-
- @Test(dependsOnMethods = "testAdd")
- public void testSearchIndex() throws Exception {
- Set<String> attribs = new LinkedHashSet<>();
- String debugString;
- List<SearchResultEntry> result;
-
- // search 1
- result = doSubtreeSearch("(&(cn=Aaccf Amar)(cn=Ardyth Bainton))", attribs);
- assertEquals(result.size(), 0);
-
- // Adding a debug search attribute for next searches
- attribs.add(ATTR_DEBUG_SEARCH_INDEX);
-
- // search 2
- result = doSubtreeSearch("(&(cn=Aaccf Amar)(employeeNumber=222))", attribs);
-
- // Only one index should be used because it is below the FILTER_CANDIDATE
- debugString = getDebugString(result);
- assertTrue(debugString.split("cn").length <= 3);
- assertResultsCountIs(1, debugString);
-
- // search 3
- result = doSubtreeSearch("(|(cn=Aaccf Amar)(cn=Ardyth Bainton))", attribs);
-
- debugString = getDebugString(result);
- assertThat(debugString).doesNotContain("NOT-INDEXED");
- assertResultsCountIs(2, debugString);
-
- // search 4
- result = doSubtreeSearch("(&(employeeNumber=*)(cn=A*)(employeeNumber>=0)(employeeNumber<=z))", attribs);
-
- debugString = getDebugString(result);
- assertThat(debugString).doesNotContain("NOT-INDEXED");
- assertResultsCountIs(12, debugString);
-
- // search 5
- result = doSubtreeSearch("(&(employeeNumber<=z)(cn<=Abbey Abbie)(cn>=0)(|(cn>=Abahri Abazari)(employeeNumber<=9)))",
- attribs);
-
- debugString = getDebugString(result);
- assertThat(debugString).doesNotContain("NOT-INDEXED");
- assertResultsCountIs(11, debugString);
-
- // search 6
- result = doSubtreeSearch("(cn~=Aartjan)", attribs);
-
- debugString = getDebugString(result);
- assertThat(debugString).doesNotContain("NOT-INDEXED");
- assertResultsCountIs(1, debugString);
- }
-
- private static void assertResultsCountIs(int expectedCount, String debugString)
- {
- int finalStartPos = debugString.indexOf("final=") + 13;
- int finalEndPos = debugString.indexOf("]", finalStartPos);
- int finalCount = Integer.parseInt(debugString.substring(finalStartPos, finalEndPos));
- assertEquals(finalCount, expectedCount);
- }
-
- /** Returns the debug string from a search result. */
- private static String getDebugString(List<SearchResultEntry> result)
- {
- return result.get(0).getAttribute("debugsearchindex").get(0).toString();
- }
-
- /** Returns the results of subtree search on provided connection with provided filter. */
- private static List<SearchResultEntry> doSubtreeSearch(String filter, Set<String> attribs) throws Exception
- {
- final SearchRequest request =
- newSearchRequest("dc=test,dc=com", SearchScope.WHOLE_SUBTREE, filter).addAttribute(attribs);
- InternalSearchOperation search = getRootConnection().processSearch(request);
- return search.getSearchEntries();
- }
-
- @Test(dependsOnMethods = {"testAdd", "testSearchIndex",
- "testSearchScope", "testSearchNotIndexed", "testModifyDNNewSuperior",
- "testMatchedDN", "testNumSubordinates",
- "testNumSubordinatesIndexEntryLimitExceeded"})
- public void testDeleteSubtree() throws Exception {
- Control control = new SubtreeDeleteControl(false);
- List<Control> deleteSubTreeControl = Collections.singletonList(control);
-
- DeleteOperationBasis delete = new DeleteOperationBasis(
- getRootConnection(), nextOperationID(), nextMessageID(),
- deleteSubTreeControl,
- DN.valueOf("dc=test1,dc=com"));
-
- backend.deleteEntry(DN.valueOf("dc=test1,dc=com"), delete);
-
- EntryContainer ec =
- backend.getRootContainer().getEntryContainer(DN.valueOf("dc=test1,dc=com"));
- ec.sharedLock.lock();
- try
- {
- assertFalse(ec.entryExists(DN.valueOf("dc=test1,dc=com")));
- assertFalse(ec.entryExists(DN.valueOf("uid=user.362,dc=test1,dc=com")));
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- @Test(dependsOnMethods = {"testAdd", "testSearchIndex",
- "testSearchScope", "testMatchedDN"})
- public void testDeleteEntry() throws Exception {
- List<Control> noControls = new ArrayList<>(0);
- EntryContainer ec =
- backend.getRootContainer().getEntryContainer(DN.valueOf("ou=People,dc=test,dc=com"));
-
- ec.sharedLock.lock();
- try
- {
- Entry entry =
- ec.getEntry(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"));
- EntryID entryID = ec.getDN2ID().get(null,
- DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), LockMode.DEFAULT);
-
- DeleteOperationBasis delete = new DeleteOperationBasis(
- getRootConnection(), nextOperationID(), nextMessageID(),
- noControls,
- DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"));
- backend.deleteEntry(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), delete);
-
- assertFalse(ec.entryExists(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com")));
- assertNull(ec.getDN2ID().get(null,
- DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), LockMode.DEFAULT));
- assertFalse(ec.getDN2URI().delete(null,
- DN.valueOf("uid=user.539,ou=People,dc=test,dc=com")));
-
- AttributeType attribute = entries.get(0).getAttribute("cn").get(0).getAttributeType();
- AttributeIndex index = ec.getAttributeIndex(attribute);
- AttributeType attrType = index.getAttributeType();
-
- List<? extends Indexer> indexers = singletonList(new PresenceIndexer(index.getAttributeType()));
- assertIndexContainsID(indexers, entry, index.getIndex("presence"), entryID, FALSE);
-
- indexers = newAttributeIndexers(attrType, attrType.getEqualityMatchingRule());
- assertIndexContainsID(indexers, entry, index.getIndex(EMR_CASE_IGNORE_NAME), entryID, FALSE);
-
- indexers = newAttributeIndexers(attrType, attrType.getSubstringMatchingRule());
- assertIndexContainsID(indexers, entry, index.getIndex(substringIndexId()), entryID, FALSE);
-
- // OrderingIndex is now handled by EqualityIndex (OPENDJ-1864)
- assertThat(index.getIndex(OMR_CASE_IGNORE_NAME)).isNull();
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- private static List<AttributeIndexer> newAttributeIndexers(AttributeType attrType, MatchingRule matchingRule)
- {
- List<AttributeIndexer> indexers = new ArrayList<>();
- for (org.forgerock.opendj.ldap.spi.Indexer indexer : matchingRule.createIndexers(getOptions()))
- {
- indexers.add(new AttributeIndexer(attrType, indexer));
- }
- return indexers;
- }
-
- private static IndexingOptions getOptions()
- {
- final IndexingOptions options = mock(IndexingOptions.class);
- when(options.substringKeySize()).thenReturn(6);
- return options;
- }
-
- private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index, EntryID entryID)
- {
- assertIndexContainsID(indexers, entry, index, entryID, TRUE);
- }
-
- private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index,
- EntryID entryID, ConditionResult expected)
- {
- for (Indexer indexer : indexers)
- {
- Set<ByteString> addKeys = new HashSet<>();
- indexer.indexEntry(entry, addKeys);
-
- assertIndexContainsID(addKeys, index, entryID, expected);
- }
- }
-
- private static void assertIndexContainsID(Set<ByteString> addKeys, Index index, EntryID entryID,
- ConditionResult expected)
- {
- DatabaseEntry key = new DatabaseEntry();
- for (ByteString keyBytes : addKeys)
- {
- key.setData(keyBytes.toByteArray());
- assertEquals(index.containsID(null, key, entryID), expected);
- }
- }
-
- @Test(dependsOnMethods = {"testSearchNotIndexed", "testAdd",
- "testSearchIndex", "testSearchScope", "testMatchedDN",
- "testNumSubordinates", "testNumSubordinatesIndexEntryLimitExceeded"})
- public void testReplaceEntry() throws Exception {
- Entry oldEntry = entries.get(0);
- backend.replaceEntry(oldEntry, replaceEntry, null);
-
- EntryContainer ec =
- backend.getRootContainer().getEntryContainer(DN.valueOf("dc=test,dc=com"));
- ec.sharedLock.lock();
- try
- {
- Entry entry =
- ec.getEntry(DN.valueOf("uid=user.0,ou=People,dc=test,dc=com"));
- EntryID entryID = ec.getDN2ID().get(null,
- DN.valueOf("uid=user.0,ou=People,dc=test,dc=com"), LockMode.DEFAULT);
-
- assertNotNull(entry);
- for (ByteString value : entry.getAttribute("cn").get(0)) {
- assertEquals(value.toString(), "Testing Test");
- }
- for (ByteString value : entry.getAttribute("sn").get(0)) {
- assertEquals(value.toString(), "Test");
- }
- for (ByteString value : entry.getAttribute("givenname").get(0)) {
- assertEquals(value.toString(), "Testing");
- }
- for (ByteString value : entry.getAttribute("employeenumber").get(0)) {
- assertEquals(value.toString(), "777");
- }
-
- AttributeType attribute = entry.getAttribute("cn").get(0).getAttributeType();
- AttributeIndex index = ec.getAttributeIndex(attribute);
- AttributeType attrType = index.getAttributeType();
-
- List<? extends Indexer> indexers;
- indexers = newAttributeIndexers(attrType, attrType.getOrderingMatchingRule());
- // OrderingIndex is now handled by EqualityIndex (OPENDJ-1864)
- assertThat(index.getIndex(OMR_CASE_IGNORE_NAME)).isNull();
-
- indexers = newAttributeIndexers(attrType, attrType.getSubstringMatchingRule());
- assertIndexContainsID(indexers, entry, index.getIndex(substringIndexId()), entryID, TRUE);
- assertIndexContainsID(indexers, oldEntry, index.getIndex(substringIndexId()), entryID, FALSE);
-
- indexers = newAttributeIndexers(attrType, attrType.getEqualityMatchingRule());
- assertIndexContainsID(indexers, entry, index.getIndex(EMR_CASE_IGNORE_NAME), entryID, TRUE);
- assertIndexContainsID(indexers, oldEntry, index.getIndex(EMR_CASE_IGNORE_NAME), entryID, FALSE);
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- @Test(dependsOnMethods = {"testSearchNotIndexed", "testAdd",
- "testSearchIndex", "testSearchScope", "testMatchedDN",
- "testNumSubordinates", "testNumSubordinatesIndexEntryLimitExceeded"})
- public void testModifyEntry() throws Exception
- {
- Entry entry;
- Entry newEntry;
- EntryID entryID;
- AttributeIndex titleIndex;
- AttributeIndex nameIndex;
- Set<ByteString> addKeys;
- List<? extends Indexer> indexers;
-
- EntryContainer ec = backend.getRootContainer().getEntryContainer(
- DN.valueOf("dc=test,dc=com"));
- ec.sharedLock.lock();
- try
- {
- List<Modification> modifications = new ArrayList<>();
- modifications.add(new Modification(ADD, create("title", "debugger")));
-
- Attribute attr = attributeWithOption("title", "debugger2", "lang-en");
- modifications.add(new Modification(ADD, attr));
- modifications.add(new Modification(DELETE, create("cn", "Aaren Atp")));
- modifications.add(new Modification(ADD, create("cn", "Aaren Rigor")));
- modifications.add(new Modification(ADD, create("cn", "Aarenister Rigor")));
-
- attr = attributeWithOption("givenname", "test", "lang-de");
- modifications.add(new Modification(ADD, attr));
-
- attr = attributeWithOption("givenname", "test2", "lang-cn");
- modifications.add(new Modification(DELETE, attr));
-
- attr = attributeWithOption("givenname", "newtest3", "lang-es");
- modifications.add(new Modification(REPLACE, attr));
- modifications.add(new Modification(REPLACE, create("employeenumber", "222")));
-
- newEntry = entries.get(1);
- newEntry.applyModifications(modifications);
- entry = ec.getEntry(DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"));
- entryID = ec.getDN2ID().get(null,
- DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"), LockMode.DEFAULT);
-
- assertNotNull(entryID);
-
- titleIndex = ec.getAttributeIndex(title);
- nameIndex = ec.getAttributeIndex(name);
-
- // This current entry in the DB shouldn't be in the presence titleIndex.
- addKeys = new HashSet<>();
- addKeys.add(PresenceIndexer.presenceKey);
- assertIndexContainsID(addKeys, titleIndex.getIndex("presence"), entryID, FALSE);
-
- // This current entry should be in the presence nameIndex.
- addKeys = new HashSet<>();
- addKeys.add(PresenceIndexer.presenceKey);
- assertIndexContainsID(addKeys, nameIndex.getIndex("presence"), entryID, TRUE);
-
- List<Control> noControls = new ArrayList<>(0);
- ModifyOperationBasis modifyOp = new ModifyOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(),
- noControls, DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"), modifications);
-
- backend.replaceEntry(entry, newEntry, modifyOp);
-
- entry = ec.getEntry(DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"));
-
- assertTrue(entry.getAttribute("title").contains(
- Attributes.create("title", "debugger")));
-
- final Attribute cnAttr = entry.getAttribute("cn").get(0);
- assertTrue(cnAttr.contains(ByteString.valueOfUtf8("Aaren Rigor")));
- assertTrue(cnAttr.contains(ByteString.valueOfUtf8("Aarenister Rigor")));
- assertFalse(cnAttr.contains(ByteString.valueOfUtf8("Aaren Atp")));
-
- Set<String> options = Collections.singleton("lang-de");
- assertTrue(entry.getAttribute("givenname", options).get(0).contains(
- ByteString.valueOfUtf8("test")));
- options = Collections.singleton("lang-cn");
- assertNull(entry.getAttribute("givenname", options));
- options = Collections.singleton("lang-es");
- assertTrue(entry.getAttribute("givenname", options).get(0).contains(
- ByteString.valueOfUtf8("newtest3")));
- options = Collections.singleton("lang-fr");
- assertTrue(entry.getAttribute("givenname", options).get(0).contains(
- ByteString.valueOfUtf8("test2")));
-
- assertTrue(entry.getAttribute("employeenumber").contains(
- Attributes.create("employeenumber", "222")));
- assertFalse(entry.getAttribute("employeenumber").contains(
- Attributes.create("employeenumber", "1")));
-
- AttributeType titleIndexAttrType = titleIndex.getAttributeType();
- AttributeType nameIndexAttrType = nameIndex.getAttributeType();
-
- indexers = singletonList(new PresenceIndexer(titleIndexAttrType));
- assertIndexContainsID(indexers, entry, titleIndex.getIndex("presence"), entryID);
- indexers = singletonList(new PresenceIndexer(nameIndexAttrType));
- assertIndexContainsID(indexers, entry, nameIndex.getIndex("presence"), entryID);
-
- // OrderingIndex is now handled by EqualityIndex (OPENDJ-1864)
- assertThat(getIndexNames(titleIndex)).containsOnly(
- indexName(ec, titleIndexAttrType, "presence"),
- indexName(ec, titleIndexAttrType, EMR_CASE_IGNORE_NAME),
- indexName(ec, titleIndexAttrType, SMR_CASE_IGNORE_NAME + ":6"));
- assertThat(getIndexNames(nameIndex)).containsOnly(
- indexName(ec, nameIndexAttrType, "presence"),
- indexName(ec, nameIndexAttrType, AMR_DOUBLE_METAPHONE_NAME),
- indexName(ec, nameIndexAttrType, EMR_CASE_IGNORE_NAME),
- indexName(ec, nameIndexAttrType, SMR_CASE_IGNORE_NAME + ":6"));
-
- indexers = newAttributeIndexers(titleIndexAttrType, titleIndexAttrType.getEqualityMatchingRule());
- assertIndexContainsID(indexers, entry, titleIndex.getIndex(EMR_CASE_IGNORE_NAME), entryID);
- indexers = newAttributeIndexers(nameIndexAttrType, nameIndexAttrType.getEqualityMatchingRule());
- assertIndexContainsID(indexers, entry, nameIndex.getIndex(EMR_CASE_IGNORE_NAME), entryID);
-
- indexers = newAttributeIndexers(titleIndexAttrType, titleIndexAttrType.getSubstringMatchingRule());
- assertIndexContainsID(indexers, entry, titleIndex.getIndex(substringIndexId()), entryID);
- indexers = newAttributeIndexers(nameIndexAttrType, nameIndexAttrType.getSubstringMatchingRule());
- assertIndexContainsID(indexers, entry, nameIndex.getIndex(substringIndexId()), entryID);
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- private Attribute attributeWithOption(String attributeName, String value, String option)
- {
- AttributeBuilder builder = new AttributeBuilder(attributeName);
- builder.add(value);
- builder.setOption(option);
- return builder.toAttribute();
- }
-
- @Test(dependsOnMethods = {"testAdd", "testSearchIndex", "testSearchScope",
- "testMatchedDN"})
- public void testModifyDN() throws Exception {
- EntryContainer ec =
- backend.getRootContainer().getEntryContainer(DN.valueOf("dc=test,dc=com"));
- ec.sharedLock.lock();
- try
- {
- DN user2Dn = DN.valueOf("uid=user.2,ou=People,dc=test,dc=com");
- DN abbieDn = DN.valueOf("cn=Abbey Abbie,ou=People,dc=test,dc=com");
- Entry entry = ec.getEntry(user2Dn);
- entry.setDN(abbieDn);
-
- backend.renameEntry(user2Dn, entry, null);
-
- assertNotNull(backend.getEntry(abbieDn));
- assertNotNull(ec.getDN2ID().get(null, abbieDn, LockMode.DEFAULT));
-
- assertNull(backend.getEntry(user2Dn));
- assertNull(ec.getDN2ID().get(null, user2Dn, LockMode.DEFAULT));
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- @Test(dependsOnMethods = {"testSearchNotIndexed", "testAdd", "testSearchIndex",
- "testSearchScope", "testModifyEntry", "testModifyDN", "testReplaceEntry",
- "testDeleteEntry", "testMatchedDN", "testNumSubordinates",
- "testNumSubordinatesIndexEntryLimitExceeded"})
- public void testModifyDNNewSuperior() throws Exception {
- //Add the new superior entry we want to move to. Test to see if the child ID
- //always above parent invarient is preseved.
- backend.addEntry(newTop, null);
-
- EntryContainer ec =
- backend.getRootContainer().getEntryContainer(DN.valueOf("dc=test,dc=com"));
- ec.sharedLock.lock();
- try
- {
- EntryID newSuperiorID = ec.getDN2ID().get(null, DN.valueOf("ou=JEB Testers,dc=test,dc=com"), LockMode.DEFAULT);
- EntryID oldID = ec.getDN2ID().get(null,
- DN.valueOf("ou=People,dc=test,dc=com"), LockMode.DEFAULT);
- assertTrue(newSuperiorID.compareTo(oldID) > 0);
-
- List<Control> noControls = new ArrayList<>(0);
- ModifyDNOperationBasis modifyDN = new ModifyDNOperationBasis(
- getRootConnection(), nextOperationID(), nextMessageID(),
- noControls,
- DN.valueOf("ou=People,dc=test,dc=com"),
- RDN.decode("ou=Good People"),
- false,
- DN.valueOf("ou=JEB Testers,dc=test,dc=com"));
-
- modifyDN.run();
-
- assertNotNull(backend.getEntry(DN.valueOf("ou=Good People,ou=JEB Testers,dc=test,dc=com")));
- EntryID newID = ec.getDN2ID().get(null, DN.valueOf("ou=Good People,ou=JEB Testers,dc=test,dc=com"), LockMode.DEFAULT);
- assertNotNull(newID);
- assertTrue(newID.compareTo(newSuperiorID) > 0);
- DN subDN = DN.valueOf("uid=user.0,ou=Good People,ou=JEB Testers,dc=test,dc=com");
- Entry subEntry = backend.getEntry(subDN);
- assertNotNull(subEntry);
- assertEquals(subDN, subEntry.getName());
- EntryID newSubordinateID = ec.getDN2ID().get(null, subDN, LockMode.DEFAULT);
- assertTrue(newSubordinateID.compareTo(newID) > 0);
-
- assertNull(backend.getEntry(DN.valueOf("ou=People,dc=test,dc=com")));
- assertNull(ec.getDN2ID().get(null,
- DN.valueOf("ou=People,dc=test,dc=com"), LockMode.DEFAULT));
- }
- finally
- {
- ec.sharedLock.unlock();
- }
- }
-
- @Test(dependsOnMethods = {"testModifyDN",
- "testSearchScope", "testSearchIndex", "testReplaceEntry",
- "testModifyEntry", "testModifyDN", "testDeleteSubtree",
- "testDeleteEntry", "testAddNoParent", "testAdd",
- "testSearchNotIndexed",
- "testModifyDNNewSuperior", "testApplyIndexConfig", "testMatchedDN"})
- public void testApplyConfig() throws Exception {
- Entry configEntry = TestCaseUtils.makeEntry(
- "dn: ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "objectClass: top",
- "objectClass: ds-cfg-backend",
- "objectClass: ds-cfg-local-db-backend",
- "ds-cfg-base-dn: dc=test,dc=com",
- "ds-cfg-base-dn: dc=newsuffix,dc=com",
- "ds-cfg-enabled: true",
- "ds-cfg-writability-mode: enabled",
- "ds-cfg-java-class: org.opends.server.backends.jeb.BackendImpl",
- "ds-cfg-backend-id: indexRoot",
- "ds-cfg-db-directory:: " +
- Base64.encode(homeDirName.getBytes()),
- "ds-cfg-import-temp-directory: import-tmp");
-
- LocalDBBackendCfg cfg = AdminTestCaseUtils.getConfiguration(
- LocalDBBackendCfgDefn.getInstance(), configEntry);
-
- backend.applyConfigurationChange(cfg);
-
- RootContainer rootContainer = backend.getRootContainer();
-
- assertNull(rootContainer.getEntryContainer(DN.valueOf("dc=test1,dc=com")));
-
- assertNotNull(rootContainer.getEntryContainer(DN.valueOf("dc=newsuffix,dc=com")));
- }
-
- /** @since OPENDJ-1864 Equality and Ordering indexes share the same database */
- @Test
- public void testRemovingOrderingIndexDoesNotRemoveEquality() throws Exception
- {
- int resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index,ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "replace: ds-cfg-index-type",
- "ds-cfg-index-type: equality",
- "ds-cfg-index-type: ordering");
- assertEquals(resultCode, 0);
-
- RootContainer rootContainer = backend.getRootContainer();
- EntryContainer ec = rootContainer.getEntryContainer(DN.valueOf("dc=test,dc=com"));
-
- Collection<String> containerNames = getContainerNames(ec);
- assertThat(containerNames).contains(indexName(ec, givenName, EMR_CASE_IGNORE_NAME));
- assertThat(containerNames).doesNotContain(indexName(ec, givenName, OMR_CASE_IGNORE_NAME));
-
- // Remove equality indexes
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index,ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "replace: ds-cfg-index-type",
- "ds-cfg-index-type: ordering");
- assertEquals(resultCode, 0);
-
- // Since ordering is using the same equality db, it must remain
- containerNames = getContainerNames(ec);
- assertThat(containerNames).contains(indexName(ec, givenName, EMR_CASE_IGNORE_NAME));
- assertThat(containerNames).doesNotContain(indexName(ec, givenName, OMR_CASE_IGNORE_NAME));
- }
-
- @Test(dependsOnMethods = {"testModifyDN",
- "testSearchScope", "testSearchIndex", "testReplaceEntry",
- "testModifyEntry", "testModifyDN", "testDeleteSubtree",
- "testDeleteEntry", "testAddNoParent", "testAdd",
- "testSearchNotIndexed",
- "testModifyDNNewSuperior", "testMatchedDN"})
- public void testApplyIndexConfig() throws Exception {
- int resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index,ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "replace: ds-cfg-index-type",
- "ds-cfg-index-type: approximate");
-
- assertEquals(resultCode, 0);
-
- RootContainer rootContainer = backend.getRootContainer();
- EntryContainer ec = rootContainer.getEntryContainer(DN.valueOf("dc=test,dc=com"));
-
- Collection<String> containerNames = getContainerNames(ec);
- assertThat(containerNames).doesNotContain(
- indexName(ec, givenName, EMR_CASE_IGNORE_NAME),
- indexName(ec, givenName, "presence"),
- indexName(ec, givenName, substringIndexId()),
- indexName(ec, givenName, OMR_CASE_IGNORE_NAME));
- assertThat(containerNames).contains(indexName(ec, givenName, AMR_DOUBLE_METAPHONE_NAME));
-
- final SearchRequest request = newSearchRequest("dc=test,dc=com", SearchScope.SUBORDINATES, "(givenName~=Aaccf)")
- .addAttribute(ATTR_DEBUG_SEARCH_INDEX);
- InternalSearchOperation search = getRootConnection().processSearch(request);
- List<SearchResultEntry> result = search.getSearchEntries();
-
- //No indexes should be used.
- String debugString =
- result.get(0).getAttribute("debugsearchindex").get(0).toString();
- assertThat(debugString).containsIgnoringCase("not-indexed");
-
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index, ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "replace: ds-cfg-index-type",
- "ds-cfg-index-type: equality",
- "ds-cfg-index-type: presence",
- "ds-cfg-index-type: ordering",
- "ds-cfg-index-type: substring");
-
- assertEquals(resultCode, 0);
-
- containerNames = getContainerNames(ec);
- assertThat(containerNames).contains(
- indexName(ec, givenName, EMR_CASE_IGNORE_NAME),
- indexName(ec, givenName, "presence"),
- indexName(ec, givenName, substringIndexId()));
- // Ordering is also handled by equality since OPENDJ-1864
- assertThat(containerNames).doesNotContain(
- indexName(ec, givenName, OMR_CASE_IGNORE_NAME),
- indexName(ec, givenName, AMR_DOUBLE_METAPHONE_NAME));
-
- // Delete the entries attribute index.
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index," +
- "ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: delete");
-
- assertEquals(resultCode, 0);
-
- AttributeType givennameAttr = DirectoryServer.getAttributeTypeOrNull("givenname");
- assertNull(ec.getAttributeIndex(givennameAttr));
-
- List<DatabaseContainer> databases = new ArrayList<>();
- ec.listDatabases(databases);
- for(DatabaseContainer dc : databases)
- {
- assertFalse(dc.getName().toLowerCase().contains("givenname"));
- }
-
- // Add it back
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=givenName,cn=Index," +
- "ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: add",
- "objectClass: top",
- "objectClass: ds-cfg-local-db-index",
- "ds-cfg-attribute: givenName",
- "ds-cfg-index-type: equality",
- "ds-cfg-index-type: presence",
- "ds-cfg-index-type: ordering",
- "ds-cfg-index-type: substring");
-
- assertEquals(resultCode, 0);
-
- assertNotNull(ec.getAttributeIndex(givennameAttr));
-
- containerNames = getContainerNames(ec);
- assertThat(containerNames).contains(
- indexName(ec, givenName, EMR_CASE_IGNORE_NAME),
- indexName(ec, givenName, "presence"),
- indexName(ec, givenName, substringIndexId()));
- // Equality and Ordering indexes share the same database since OPENDJ-1864
- assertThat(containerNames).doesNotContain(
- indexName(ec, givenName, OMR_CASE_IGNORE_NAME),
- indexName(ec, givenName, AMR_DOUBLE_METAPHONE_NAME));
-
- // Make sure changing the index entry limit on an index where the limit
- // is already exceeded causes warnings.
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=mail,cn=Index," +
- "ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "replace: ds-cfg-index-entry-limit",
- "ds-cfg-index-entry-limit: 30");
-
- assertEquals(resultCode, 0);
-
- // Make sure removing a index entry limit for an index makes it use the
- // backend wide setting.
- resultCode = TestCaseUtils.applyModifications(true,
- "dn: ds-cfg-attribute=mail,cn=Index," +
- "ds-cfg-backend-id=indexRoot,cn=Backends,cn=config",
- "changetype: modify",
- "delete: ds-cfg-index-entry-limit");
-
- assertEquals(resultCode, 0);
- }
-
- private static Collection<String> getContainerNames(EntryContainer container)
- {
- final List<DatabaseContainer> databases = new ArrayList<>();
- container.listDatabases(databases);
- final Collection<String> names = new ArrayList<>(databases.size());
- for (DatabaseContainer dc : databases)
- {
- names.add(dc.getName().toLowerCase());
- }
- return names;
- }
-
- private static Collection<String> getIndexNames(AttributeIndex index)
- {
- final Collection<String> names = new ArrayList<>();
- for (Index idx : index.getAllIndexes())
- {
- names.add(idx.getName().toLowerCase());
- }
- return names;
- }
-
- private static String indexName(EntryContainer entryContainer, AttributeType attrType, String indexID)
- {
- return entryContainer.getDatabasePrefix() + "_" + attrType.getPrimaryName().toLowerCase() + "." + indexID.toLowerCase();
- }
-
- @Test(dependsOnMethods = {"testDeleteEntry", "testSearchScope",
- "testSearchIndex", "testMatchedDN"})
- public void testSearchNotIndexed() throws Exception {
- //Add 2 more entries to overflow the index entry limit.
- for (Entry entry : additionalEntries) {
- backend.addEntry(entry, null);
- assertNotNull(backend.getEntry(entry.getName()));
- }
-
- final SearchRequest request = newSearchRequest("dc=test,dc=com", SearchScope.SUBORDINATES, "(carLicense=377*)")
- .addAttribute(ATTR_DEBUG_SEARCH_INDEX);
- InternalSearchOperation search = getRootConnection().processSearch(request);
- List<SearchResultEntry> result = search.getSearchEntries();
-
- //No indexes should be used.
- String debugString =
- result.get(0).getAttribute("debugsearchindex").get(0).toString();
- assertThat(debugString).containsIgnoringCase("not-indexed");
- }
-
- @Test(dependsOnMethods = "testSearchNotIndexed")
- public void testNumSubordinatesIndexEntryLimitExceeded() throws Exception
- {
- DN dn = DN.valueOf("dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 1);
- assertEquals(backend.getNumberOfEntriesInBaseDN(dn), 15);
-
- // 1 entry was deleted and 2 added for a total of 13
- dn = DN.valueOf("ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 13);
- dn = DN.valueOf("dc=com");
- assertEquals(backend.getNumberOfChildren(dn), -1);
- dn = DN.valueOf("dc=test1,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 2);
- dn = DN.valueOf("uid=user.10,ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), 0);
- dn = DN.valueOf("uid=does not exist,ou=People,dc=test,dc=com");
- assertEquals(backend.getNumberOfChildren(dn), -1);
- }
-
- /**
- * Provides a set of DNs for the matched DN test case.
- *
- * @return set of DNs
- * @throws Exception when DN.decode fails
- */
- @DataProvider(name = "MatchedDNs")
- public Object[][] initMatchedDNs() throws Exception {
- ResultCode success = ResultCode.SUCCESS;
- ResultCode noSuchObject = ResultCode.NO_SUCH_OBJECT;
-
- DN testComDN = DN.valueOf( "dc=test,dc=com");
- DN dummyTestComDN = DN.valueOf( "cn=dummy,dc=test,dc=com");
- DN peopleTestComDN = DN.valueOf( "ou=people,dc=test,dc=com");
- DN dummyPeopleTestComDN = DN.valueOf("cn=dummy,ou=people,dc=test,dc=com");
-
- // Sets of DNs
- return new Object[][] {
- {testComDN, null, success},
- {peopleTestComDN, null, success},
- {dummyTestComDN, testComDN, noSuchObject},
- {dummyPeopleTestComDN, peopleTestComDN, noSuchObject},
- };
- }
-
- /**
- * Executes an internal search operation and check the result code and
- * matched DN field.
- *
- * @param searchBaseDN the search base DN to use for the current test
- * @param expectedResultCode the expected LDAP result code
- * @param expectedMatchedDN the expected matched DN, may be <code>null</code>
- */
- @Test(dataProvider = "MatchedDNs", dependsOnMethods = "testAdd")
- public void testMatchedDN(
- DN searchBaseDN,
- DN expectedMatchedDN,
- ResultCode expectedResultCode
- ) throws Exception
- {
- // Test is performed with each and every scope
- for (SearchScope scope: SearchScope.values())
- {
- final SearchRequest request = newSearchRequest(searchBaseDN, scope);
- InternalSearchOperation searchOperation = getRootConnection().processSearch(request);
-
- assertEquals(searchOperation.getResultCode(), expectedResultCode);
- assertEquals(searchOperation.getMatchedDN(), expectedMatchedDN);
- }
- }
-
- @Test
- public void testJELogFilesIterator() throws Exception
- {
- File rootDir = TestCaseUtils.createTemporaryDirectory("jeLogFilesIterator");
- try
- {
- createLogFilesInDirectory(rootDir.toPath(), "content", 0, 3);
- JELogFilesIterator iterator = new BackendImpl.JELogFilesIterator(rootDir, "backendID");
-
- assertLogFilesIterator(iterator, rootDir, 0, 2);
- assertThat(iterator.hasNext()).isFalse();
- }
- finally
- {
- StaticUtils.recursiveDelete(rootDir);
- }
- }
-
- @Test
- public void testJELogFilesIteratorWhenFileIsDeletedAndNewOneAdded() throws Exception
- {
- File rootDir = TestCaseUtils.createTemporaryDirectory("jeLogFilesIteratorDelete");
- try
- {
- createLogFilesInDirectory(rootDir.toPath(), "content", 0, 2);
- JELogFilesIterator iterator = new BackendImpl.JELogFilesIterator(rootDir, "backendID");
-
- assertLogFilesIterator(iterator, rootDir, 0, 1);
- assertThat(iterator.hasNext()).isFalse();
-
- // delete first file log0.jdb and create a new one log2.jdb
- new File(rootDir, "log0.jdb").delete();
- createLogFilesInDirectory(rootDir.toPath(), "content", 2, 1);
-
- assertLogFilesIterator(iterator, rootDir, 2, 2);
- assertThat(iterator.hasNext()).isFalse();
- }
- finally
- {
- StaticUtils.recursiveDelete(rootDir);
- }
- }
-
- @Test
- public void testJELogFilesIteratorWhenFileIsDeletedAndLastOneHasLargerSize() throws Exception
- {
- File rootDir = TestCaseUtils.createTemporaryDirectory("jeLogFilesIteratorDelete2");
- try
- {
- createLogFilesInDirectory(rootDir.toPath(), "content", 0, 2);
- JELogFilesIterator iterator = new BackendImpl.JELogFilesIterator(rootDir, "backendID");
-
- assertLogFilesIterator(iterator, rootDir, 0, 1);
-
- // delete first file log0.jdb and update last one with larger content
- new File(rootDir, "log0.jdb").delete();
- new File(rootDir, "log1.jdb").delete();
- createLogFilesInDirectory(rootDir.toPath(), "morecontent", 1, 1);
-
- assertLogFilesIterator(iterator, rootDir, 1, 1);
- assertThat(iterator.hasNext()).isFalse();
- }
- finally
- {
- StaticUtils.recursiveDelete(rootDir);
- }
- }
-
- private void assertLogFilesIterator(JELogFilesIterator iterator, File rootDir, int from, int to)
- {
- for (int i = from; i <= to; i++)
- {
- assertThat(iterator.hasNext()).as("hasNext expected to be true for " + i).isTrue();
- assertThat(iterator.next().toFile()).isEqualTo(new File(rootDir, "log" + i + ".jdb"));
- }
- }
-
- /**
- * Creates dummy "logN.jdb" (where N is a number) files in given directory
- * with provided label as content for files.
- */
- private List<Path> createLogFilesInDirectory(Path directory, String label, int start, int numberOfFiles)
- throws Exception
- {
- List<Path> files = new ArrayList<>();
- for (int i = start; i < start+numberOfFiles; i++)
- {
- String filename = "log" + i + ".jdb";
- Path file = directory.resolve(filename);
- createFile(file, StaticUtils.getBytes(label));
- files.add(file);
- }
- return files;
- }
-
- private void createFile(Path file, byte[] content) throws Exception {
- OutputStream output = new FileOutputStream(file.toFile(), false);
- try
- {
- output.write(content);
- }
- finally {
- close(output);
- }
- }
-
- private static String substringIndexId() {
- return SMR_CASE_IGNORE_NAME + ":" + getOptions().substringKeySize();
- }
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEntryContainer.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEntryContainer.java
deleted file mode 100644
index 9c38b1e..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEntryContainer.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import java.util.List;
-
-import org.opends.server.TestCaseUtils;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.DN;
-import org.opends.server.types.Entry;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static org.assertj.core.api.Assertions.*;
-
-/**
- * Test class for EntryContainer.
- */
-public class TestEntryContainer extends JebTestCase {
-
- private static final String backendID = "userRoot";
- private BackendImpl be;
-
- private static final String ldifString = "dn: dc=example,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: domain\n" + "\n"
- + "dn: ou=People,dc=example,dc=com\n" + "objectClass: top\n"
- + "objectClass: organizationalUnit\n" + "\n"
- + "dn: uid=user.1,ou=People,dc=example,dc=com\n"
- + "objectClass: top\n" + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n" + "uid: user.1\n"
- + "homePhone: 951-245-7634\n"
- + "description: This is the description for Aaccf Amar.\n"
- + "st: NC\n" + "mobile: 027-085-0537\n"
- + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
- + "$Rockford, NC 85762\n" + "mail: user.1@example.com\n"
- + "cn: Aaccf Amar\n" + "l: Rockford\n" + "pager: 508-763-4246\n"
- + "street: 17984 Thirteenth Street\n"
- + "telephoneNumber: 216-564-6748\n" + "employeeNumber: 1\n"
- + "sn: Amar\n" + "givenName: Aaccf\n" + "postalCode: 85762\n"
- + "userPassword: password\n" + "initials: AA\n" + "\n"
- + "dn: o=Airius,dc=example,dc=com\n" + "objectClass: top\n"
- + "objectClass: organization\n" + "\n"
- + "dn:: b3U95Za25qWt6YOoLG89QWlyaXVzLGRjPWV4YW1wbGUsZGM9Y29t\n"
- + "# dn:: ou=<JapaneseOU>,o=Airius\n" + "objectclass: top\n"
- + "objectclass: organizationalUnit\n" + "ou:: 5Za25qWt6YOo\n"
- + "# ou:: <JapaneseOU>\n" + "ou;lang-ja:: 5Za25qWt6YOo\n"
- + "# ou;lang-ja:: <JapaneseOU>\n"
- + "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n"
- + "# ou;lang-ja:: <JapaneseOU_in_phonetic_representation>\n"
- + "ou;lang-en: Sales\n" + "description: Japanese office\n" + "\n"
- + "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVzLGRjPWV4YW1wbGUsZGM9Y29t\n"
- + "# dn:: uid=<uid>,ou=<JapaneseOU>,o=Airius\n"
- + "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n"
- + "objectclass: top\n" + "objectclass: person\n"
- + "objectclass: organizationalPerson\n"
- + "objectclass: inetOrgPerson\n" + "uid: rogasawara\n"
- + "mail: rogasawara@airius.co.jp\n"
- + "givenname;lang-ja:: 44Ot44OJ44OL44O8\n"
- + "# givenname;lang-ja:: <JapaneseGivenname>\n"
- + "sn;lang-ja:: 5bCP56yg5Y6f\n" + "# sn;lang-ja:: <JapaneseSn>\n"
- + "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn;lang-ja:: <JapaneseCn>\n"
- + "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title;lang-ja:: <JapaneseTitle>\n" + "preferredlanguage: ja\n"
- + "givenname:: 44Ot44OJ44OL44O8\n"
- + "# givenname:: <JapaneseGivenname>\n" + "sn:: 5bCP56yg5Y6f\n"
- + "# sn:: <JapaneseSn>\n" + "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn:: <JapaneseCn>\n" + "title:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title:: <JapaneseTitle>\n"
- + "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n"
- + "# givenname;lang-ja;phonetic:: "
- + "<JapaneseGivenname_in_phonetic_representation_kana>\n"
- + "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n"
- + "# sn;lang-ja;phonetic:: "
- + "<JapaneseSn_in_phonetic_representation_kana>\n"
- + "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n"
- + "# cn;lang-ja;phonetic:: "
- + "<JapaneseCn_in_phonetic_representation_kana>\n"
- + "title;lang-ja;phonetic:: " + ""
- + "44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n"
- + "# title;lang-ja;phonetic::\n"
- + "# <JapaneseTitle_in_phonetic_representation_kana>\n"
- + "givenname;lang-en: Rodney\n" + "sn;lang-en: Ogasawara\n"
- + "cn;lang-en: Rodney Ogasawara\n"
- + "title;lang-en: Sales, Director\n" + "\n" + "";
-
- private List<Entry> entryList;
-
- private long calculatedHighestID;
-
- /**
- * Set up the environment for performing the tests in this suite.
- *
- * @throws Exception
- * If the environment could not be set up.
- */
- @BeforeClass
- public void setUp() throws Exception {
- // This test suite depends on having the schema available, so we'll make
- // sure the server is started.
- TestCaseUtils.startServer();
-
- // Create a set of entries
- entryList = TestCaseUtils.entriesFromLdifString(ldifString);
-
- // Remember the highest entryID
- calculatedHighestID = entryList.size();
- }
-
- /**
- * Tears down the environment for performing the tests in this suite.
- *
- * @throws Exception
- * If the environment could not be finalized.
- */
- @AfterClass
- public void tearDown() throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- }
-
- /**
- * Test the entry container.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test
- public void testGetHighestEntryID() throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- be = (BackendImpl) DirectoryServer.getBackend(backendID);
- RootContainer rootContainer = be.getRootContainer();
- EntryContainer entryContainer =
- rootContainer.getEntryContainer(DN.valueOf("dc=example,dc=com"));
-
- entryContainer.sharedLock.lock();
- try
- {
- EntryID actualHighestID = entryContainer.getHighestEntryID();
- assertThat(actualHighestID.longValue()).isEqualTo(0);
-
- for (Entry entry : entryList) {
- entryContainer.addEntry(entry, null);
- final Entry afterEntry = entryContainer.getEntry(entry.getName());
- assertThat(afterEntry).as("Entry should have been added").isNotNull();
- }
- actualHighestID = entryContainer.getHighestEntryID();
- assertThat(actualHighestID.longValue()).isEqualTo(calculatedHighestID);
- }
- finally
- {
- entryContainer.sharedLock.unlock();
- }
- }
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEnvManager.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEnvManager.java
deleted file mode 100644
index b5b6e63..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestEnvManager.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.io.File;
-
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.AfterClass;
-
-import org.opends.server.TestCaseUtils;
-import com.sleepycat.je.Environment;
-import com.sleepycat.je.EnvironmentConfig;
-
-/**
- * EnvManager Tester.
- */
-public class TestEnvManager extends JebTestCase {
- private File tempDir;
- private String homeDirName;
-
- /**
- * Set up the environment for performing the tests in this suite.
- *
- * @throws Exception
- * If the environment could not be set up.
- */
- @BeforeClass
- public void setUp() throws Exception {
- tempDir = TestCaseUtils.createTemporaryDirectory("jebtest");
- homeDirName = tempDir.getAbsolutePath();
- }
-
- /**
- * Tears down the environment for performing the tests in this suite.
- *
- * @throws Exception
- * If the environment could not be finalized.
- */
- @AfterClass
- public void tearDown() throws Exception {
- TestCaseUtils.deleteDirectory(tempDir);
- }
-
- /**
- * Test for valid home directory.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test
- public void testValidHomeDir() throws Exception {
- File homeDir = new File(homeDirName);
-
- EnvManager.createHomeDir(homeDirName);
- EnvironmentConfig envConfig = new EnvironmentConfig();
- envConfig.setTransactional(true);
- envConfig.setAllowCreate(true);
- Environment env = new Environment(new File(homeDirName), envConfig);
- env.close();
-
- assertTrue(homeDir.list().length > 0);
-
- EnvManager.removeFiles(homeDirName);
-
- assertTrue(homeDir.list().length == 0);
- }
-
- /**
- * Test for invalid home directory.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(expectedExceptions = JebException.class)
- public void testInvalidHomeDir() throws Exception {
- File tempFile = File.createTempFile("jebtest", "");
- tempFile.deleteOnExit();
-
- String invalidHomeDirName = tempFile.getAbsolutePath();
-
- EnvManager.createHomeDir(invalidHomeDirName);
- }
-
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java
deleted file mode 100644
index f130d0e..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java
+++ /dev/null
@@ -1,615 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import static org.testng.Assert.*;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import org.assertj.core.api.SoftAssertions;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.opendj.ldap.ByteString;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.api.Backend;
-import org.opends.server.backends.VerifyConfig;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.tasks.TaskUtils;
-import org.opends.server.types.AttributeType;
-import org.opends.server.types.DN;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.Entry;
-import org.opends.server.types.InitializationException;
-import org.opends.server.types.LDIFImportConfig;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-@SuppressWarnings("javadoc")
-public class TestImportJob extends JebTestCase
-{
- static class RejectSkippedEntries
- {
- private ByteArrayOutputStream rejectedEntries = new ByteArrayOutputStream();
- private ByteArrayOutputStream skippedEntries = new ByteArrayOutputStream();
-
- private void noSkippedOrRejectedEntries()
- {
- SoftAssertions softly = new SoftAssertions();
- softly.assertThat(rejectedEntries.toString()).isEmpty();
- softly.assertThat(skippedEntries.toString()).isEmpty();
- softly.assertAll();
- }
- }
-
- private String backendID = "importRoot";
- private File tempDir;
- private String homeDirName;
-
- private DN importtest1DN;
- private DN importtestDN;
- private DN[] baseDNs;
-
- // @formatter:off
- private String top =
- "dn: dc=importtest,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: domain\n"
- + "dc: importtest\n"
- + "\n"
- + "dn: ou=People,dc=importtest,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: organizationalUnit\n"
- + "ou: People\n"
- + "\n"
- + "dn: ou=Others,ou=People,dc=importtest,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: organizationalUnit\n"
- + "ou: Others\n"
- + "\n"
- + "dn: dc=importtest1,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: domain\n"
- + "dc: importtest1\n";
-
- private String entries1 =
- "dn: uid=user.0,ou=People,dc=importtest,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Aaccf\n"
- + "sn: Amar\n"
- + "cn: Aaccf Amar\n"
- + "initials: AQA\n"
- + "employeeNumber: 0\n"
- + "uid: user.0\n"
- + "mail: user.0@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 380-535-2354\n"
- + "homePhone: 707-626-3913\n"
- + "pager: 456-345-7750\n"
- + "mobile: 366-674-7274\n"
- + "street: 99262 Eleventh Street\n"
- + "l: Salem\n"
- + "st: NM\n"
- + "postalCode: 36530\n"
- + "postalAddress: Aaccf Amar$99262 Eleventh Street$Salem, NM 36530\n"
- + "description: This is the description for Aaccf Amar.\n"
- + "\n"
- + "dn: uid=user.539,ou=People,dc=importtest,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Ardyth\n"
- + "sn: Bainton\n"
- + "cn: Ardyth Bainton\n"
- + "initials: AIB\n"
- + "employeeNumber: 539\n"
- + "uid: user.539\n"
- + "mail: user.539@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 641-433-7404\n"
- + "homePhone: 524-765-8780\n"
- + "pager: 985-331-1308\n"
- + "mobile: 279-423-0188\n"
- + "street: 81170 Taylor Street\n"
- + "l: Syracuse\n"
- + "st: WV\n"
- + "postalCode: 93507\n"
- + "postalAddress: Ardyth Bainton$81170 Taylor Street$Syracuse, WV 93507\n"
- + "description: This is the description for Ardyth Bainton.\n"
- + "\n"
- + "dn: uid=user.446,dc=importtest1,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Annalee\n"
- + "sn: Avard\n"
- + "cn: Annalee Avard\n"
- + "initials: ANA\n"
- + "employeeNumber: 446\n"
- + "uid: user.446\n"
- + "mail: user.446@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 875-335-2712\n"
- + "homePhone: 181-995-6635\n"
- + "pager: 586-905-4185\n"
- + "mobile: 826-857-7592\n"
- + "street: 46168 Mill Street\n"
- + "l: Charleston\n"
- + "st: CO\n"
- + "postalCode: 60948\n"
- + "postalAddress: Annalee Avard$46168 Mill Street$Charleston, CO 60948\n"
- + "description: This is the description for Annalee Avard.\n"
- + "\n"
- + "dn: uid=user.362,dc=importtest1,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Andaree\n"
- + "sn: Asawa\n"
- + "cn: Andaree Asawa\n"
- + "initials: AEA\n"
- + "employeeNumber: 362\n"
- + "uid: user.362\n"
- + "mail: user.362@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 399-788-7334\n"
- + "homePhone: 798-076-5683\n"
- + "pager: 034-026-9411\n"
- + "mobile: 948-743-9197\n"
- + "street: 81028 Forest Street\n"
- + "l: Wheeling\n"
- + "st: IA\n"
- + "postalCode: 60905\n"
- + "postalAddress: Andaree Asawa$81028 Forest Street$Wheeling, IA 60905\n"
- + "description: This is the description for Andaree Asawa.\n";
-
- private String replacement1 =
- "dn: uid=user.446,dc=importtest1,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Annalee\n"
- + "sn: Bogard\n"
- + "cn: Annalee Bogard\n"
- + "initials: ANG\n"
- + "employeeNumber: 446\n"
- + "uid: user.446\n"
- + "mail: user.446@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 875-335-8882\n"
- + "homePhone: 181-995-6635\n"
- + "pager: 586-905-4185\n"
- + "mobile: 826-857-7592\n"
- + "street: 43221 Hill Street\n"
- + "l: Charleston\n"
- + "st: CO\n"
- + "postalCode: 60918\n"
- + "postalAddress: Annalee Avard$43221 Hill Street$Charleston, CO 60918\n"
- + "description: This is the description for Annalee Bogard.\n";
-
- private String skippedEntries =
- "dn: dc=skipped,dc=importtest1,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: domain\n"
- + "dc: skipped\n"
- + "\n"
- + "dn: uid=user.446,dc=skipped,dc=importtest1,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Annalee\n"
- + "sn: Bogard\n"
- + "cn: Annalee Bogard\n"
- + "initials: ANG\n"
- + "employeeNumber: 446\n"
- + "uid: user.446\n"
- + "mail: user.446@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 875-335-8882\n"
- + "homePhone: 181-995-6635\n"
- + "pager: 586-905-4185\n"
- + "mobile: 826-857-7592\n"
- + "street: 43221 Hill Street\n"
- + "l: Charleston\n"
- + "st: CO\n"
- + "postalCode: 60918\n"
- + "postalAddress: Annalee Avard$43221 Hill Street$Charleston, CO 60918\n"
- + "description: This is the description for Annalee Bogard.\n";
- // @formatter:on
-
- private String file(String basename)
- {
- return homeDirName + File.separator + basename;
- }
-
- @BeforeClass
- public void setUp() throws Exception
- {
- // This test suite depends on having the schema available, so we'll make
- // sure the server is started.
- TestCaseUtils.startServer();
- TestCaseUtils.enableBackend(backendID);
-
- tempDir = TestCaseUtils.createTemporaryDirectory("jebimporttest");
- homeDirName = tempDir.getAbsolutePath();
-
- EnvManager.createHomeDir(homeDirName);
-
- writeTo(top, "top.ldif");
- writeTo(entries1, "entries1.ldif");
- writeTo(replacement1, "replacement1.ldif");
- writeTo(skippedEntries, "skipped.ldif");
-
- importtest1DN = DN.valueOf("dc=importtest1,dc=com");
- importtestDN = DN.valueOf("dc=importtest,dc=com");
- baseDNs = new DN[] { importtestDN, importtest1DN };
- }
-
- private void writeTo(String ldif, String baseName) throws IOException, FileNotFoundException
- {
- File file = new File(file(baseName));
- file.deleteOnExit();
- try (OutputStream ldifFile = new FileOutputStream(file);
- PrintStream writer = new PrintStream(ldifFile))
- {
- writer.println(ldif);
- }
- }
-
- @AfterClass
- public void cleanUp() throws Exception
- {
- TestCaseUtils.disableBackend(backendID);
- TestCaseUtils.deleteDirectory(tempDir);
- }
-
- @Test
- public void importCaseInsensitiveDNs() throws Exception
- {
- String top2 =
- "dn: dc=case_insensitive_dns,dc=importtest,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: domain\n"
- + "dc: case_insensitive_dns\n"
- + "\n"
- + "dn: ou=People,dc=CASE_INSENSITIVE_DNS,dc=importtest,dc=com\n"
- + "objectclass: top\n"
- + "objectclass: organizationalUnit\n"
- + "ou: People\n";
- writeTo(top2, "top2.ldif");
-
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "top.ldif", "top2.ldif");
- cleanImport(importConfig);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
- }
-
- @Test
- public void importDNsWithInteger() throws Exception
- {
- String entryWithIntegerInDN =
- "dn: photo=#04020001,ou=People,dc=importtest,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "givenName: Aaccf\n"
- + "sn: Amar\n"
- + "cn: Aaccf Amar\n"
- + "initials: AQA\n"
- + "employeeNumber: 0\n"
- + "uid: user.0\n"
- + "mail: user.0@example.com\n"
- + "userPassword: password\n"
- + "telephoneNumber: 380-535-2354\n"
- + "homePhone: 707-626-3913\n"
- + "pager: 456-345-7750\n"
- + "mobile: 366-674-7274\n"
- + "street: 99262 Eleventh Street\n"
- + "l: Salem\n"
- + "st: NM\n"
- + "postalCode: 36530\n"
- + "postalAddress: Aaccf Amar$99262 Eleventh Street$Salem, NM 36530\n"
- + "description: This is the description for Aaccf Amar.\n";
- writeTo(entryWithIntegerInDN, "entryWithIntegerInDN.ldif");
-
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "top.ldif", "entryWithIntegerInDN.ldif");
- cleanImport(importConfig);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
-
- EntryContainer entryContainer = getEntryContainer(importtestDN);
- entryContainer.sharedLock.lock();
- try
- {
- assertTrue(entryContainer.entryExists(DN.valueOf("photo=#04020001,ou=People,dc=importtest,dc=com")));
- }
- finally
- {
- entryContainer.sharedLock.unlock();
- }
- }
-
- @Test(dependsOnMethods = { "importCaseInsensitiveDNs", "importDNsWithInteger" })
- public void importAll() throws Exception
- {
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "top.ldif", "entries1.ldif");
- cleanImport(importConfig);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
-
- assertImportedData();
- }
-
- @Test(dependsOnMethods = "importAll")
- public void importPartial() throws Exception
- {
- Set<DN> includeBranches = Collections.singleton(DN.valueOf("ou=People,dc=importtest,dc=com"));
- Set<DN> excludeBranches = Collections.singleton(DN.valueOf("ou=Others,ou=People,dc=importtest,dc=com"));
-
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "top.ldif", "entries1.ldif");
- importConfig.setAppendToExistingData(false);
- importConfig.setReplaceExistingEntries(false);
- importConfig.setValidateSchema(true);
- importConfig.setIncludeBranches(includeBranches);
- importConfig.setExcludeBranches(excludeBranches);
-
- importLDIF(importConfig);
-
- SoftAssertions softly = new SoftAssertions();
- softly.assertThat(entries.rejectedEntries.toString()).isEmpty();
- softly.assertThat(entries.skippedEntries.toString()).isNotEmpty();
- softly.assertAll();
-
- assertImportedData();
- }
-
- private void assertImportedData() throws Exception
- {
- for (DN baseDN : baseDNs)
- {
- EntryContainer entryContainer = getEntryContainer(baseDN);
- entryContainer.sharedLock.lock();
- try
- {
- if (baseDN.equals(importtestDN))
- {
- assertEquals(entryContainer.getEntryCount(), 5);
- assertTrue(entryContainer.entryExists(baseDN));
- assertTrue(entryContainer.entryExists(DN.valueOf("ou=People,dc=importtest,dc=com")));
- assertTrue(entryContainer.entryExists(DN.valueOf("ou=Others,ou=People,dc=importtest,dc=com")));
- assertTrue(entryContainer.entryExists(DN.valueOf("uid=user.0,ou=People,dc=importtest,dc=com")));
- assertTrue(entryContainer.entryExists(DN.valueOf("uid=user.539,ou=People,dc=importtest,dc=com")));
-
- assertEquals(verifyBackend(baseDN), 0);
- }
- else if (baseDN.equals(importtest1DN))
- {
- assertEquals(entryContainer.getEntryCount(), 3);
- assertTrue(entryContainer.entryExists(baseDN));
- assertTrue(entryContainer.entryExists(DN.valueOf("uid=user.446,dc=importtest1,dc=com")));
- assertTrue(entryContainer.entryExists(DN.valueOf("uid=user.362,dc=importtest1,dc=com")));
-
- assertEquals(verifyBackend(baseDN), 0);
- }
- else
- {
- throw new IllegalStateException("No asserts exist for baseDN \"" + baseDN + "\". Please provide some.");
- }
- }
- finally
- {
- entryContainer.sharedLock.unlock();
- }
- }
- }
-
- @Test(dependsOnMethods = "importPartial")
- public void importReplaceExisting() throws Exception
- {
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "replacement1.ldif");
- importConfig.setAppendToExistingData(true);
- importConfig.setReplaceExistingEntries(true);
- importConfig.setValidateSchema(true);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
-
- EntryContainer entryContainer = getEntryContainer(importtest1DN);
- entryContainer.sharedLock.lock();
- try
- {
- Entry entry = entryContainer.getEntry(DN.valueOf("uid=user.446,dc=importtest1,dc=com"));
- assertNotNull(entry);
-
- AttributeType attrType = DirectoryServer.getAttributeTypeOrNull("cn");
- assertTrue(entry.hasValue(attrType, null, ByteString.valueOfUtf8("Annalee Bogard")));
-
- assertEquals(verifyBackend(importtest1DN), 0);
- }
- finally
- {
- entryContainer.sharedLock.unlock();
- }
- }
-
- private long verifyBackend(DN baseDN) throws InitializationException, ConfigException, DirectoryException
- {
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDN);
-
- Backend<?> backend = DirectoryServer.getBackend(backendID);
- return backend.verifyBackend(verifyConfig);
- }
-
- @Test(dependsOnMethods = "importReplaceExisting")
- public void importNoParent() throws Exception
- {
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "replacement1.ldif");
- importConfig.setAppendToExistingData(false);
- importConfig.setReplaceExistingEntries(true);
- importConfig.setValidateSchema(true);
-
- importLDIF(importConfig);
-
- SoftAssertions softly = new SoftAssertions();
- softly.assertThat(entries.rejectedEntries.toString()).contains("uid=user.446,dc=importtest1,dc=com");
- softly.assertThat(entries.skippedEntries.toString()).isEmpty();
- softly.assertAll();
- }
-
- @Test(dependsOnMethods = "importReplaceExisting")
- public void importAppend() throws Exception
- {
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "top.ldif");
- cleanImport(importConfig);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
-
- entries = new RejectSkippedEntries();
- importConfig = newLDIFImportConfig(entries, "entries1.ldif");
- importConfig.setAppendToExistingData(true);
- importConfig.setReplaceExistingEntries(false);
- importConfig.setValidateSchema(true);
-
- importLDIF(importConfig);
- entries.noSkippedOrRejectedEntries();
-
- assertImportedData();
- }
-
- @Test(dependsOnMethods = "importPartial")
- public void importNotReplaceExisting() throws Exception
- {
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "replacement1.ldif");
- importConfig.setAppendToExistingData(true);
- importConfig.setReplaceExistingEntries(false);
- importConfig.setValidateSchema(true);
-
- importLDIF(importConfig);
-
- SoftAssertions softly = new SoftAssertions();
- softly.assertThat(entries.rejectedEntries.toString()).contains("uid=user.446,dc=importtest1,dc=com");
- softly.assertThat(entries.skippedEntries.toString()).isEmpty();
- softly.assertAll();
- }
-
- @Test(dependsOnMethods = "importPartial")
- public void importSkip() throws Exception
- {
- Set<DN> excludeBranches = Collections.singleton(DN.valueOf("dc=skipped,dc=importtest1,dc=com"));
- RejectSkippedEntries entries = new RejectSkippedEntries();
- LDIFImportConfig importConfig = newLDIFImportConfig(entries, "skipped.ldif");
- importConfig.setAppendToExistingData(true);
- importConfig.setReplaceExistingEntries(true);
- importConfig.setValidateSchema(true);
- importConfig.setExcludeBranches(excludeBranches);
-
- importLDIF(importConfig);
-
- SoftAssertions softly = new SoftAssertions();
- softly.assertThat(entries.rejectedEntries.toString()).isEmpty();
- softly.assertThat(entries.skippedEntries.toString()).contains(
- "dc=skipped,dc=importtest1,dc=com",
- "uid=user.446,dc=skipped,dc=importtest1,dc=com");
- softly.assertAll();
- }
-
- private EntryContainer getEntryContainer(DN baseDN)
- {
- Backend<?> backend = DirectoryServer.getBackend(backendID);
- RootContainer rootContainer = ((BackendImpl) backend).getRootContainer();
-
- EntryContainer entryContainer = rootContainer.getEntryContainer(baseDN);
- assertNotNull(entryContainer);
- return entryContainer;
- }
-
- private LDIFImportConfig newLDIFImportConfig(RejectSkippedEntries entries, String... baseNames)
- {
- List<String> ldifFiles = new ArrayList<>(baseNames.length);
- for (String baseName : baseNames)
- {
- ldifFiles.add(file(baseName));
- }
- LDIFImportConfig cfg = new LDIFImportConfig(ldifFiles);
- cfg.writeRejectedEntries(entries.rejectedEntries);
- cfg.writeSkippedEntries(entries.skippedEntries);
- return cfg;
- }
-
- private void cleanImport(LDIFImportConfig importConfig) throws Exception
- {
- TestCaseUtils.clearJEBackend(backendID);
- importConfig.setAppendToExistingData(false);
- importConfig.setReplaceExistingEntries(false);
- importConfig.setValidateSchema(true);
- }
-
- private void importLDIF(LDIFImportConfig importConfig) throws DirectoryException
- {
- Backend<?> backend = DirectoryServer.getBackend(backendID);
- TaskUtils.disableBackend(backendID);
- try
- {
- backend.importLDIF(importConfig, DirectoryServer.getInstance().getServerContext());
- }
- finally
- {
- TaskUtils.enableBackend(backendID);
- }
- }
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java
deleted file mode 100644
index 6d0dba7..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import java.io.ByteArrayInputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ByteStringBuilder;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
-import org.opends.server.util.LDIFReader;
-import org.opends.server.util.StaticUtils;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.opends.server.backends.jeb.JebFormat.*;
-import static org.opends.server.util.StaticUtils.*;
-import static org.testng.Assert.*;
-
-/**
- * JebFormat Tester.
- */
-@SuppressWarnings("javadoc")
-public class TestJebFormat extends JebTestCase {
- private static final String ldifString =
- "dn: uid=user.1,ou=People,dc=example,dc=com\n"
- + "objectClass: top\n"
- + "objectClass: person\n"
- + "objectClass: organizationalPerson\n"
- + "objectClass: inetOrgPerson\n"
- + "uid: user.1\n"
- + "homePhone: 951-245-7634\n"
- + "description: This is the description for Aaccf Amar.\n"
- + "st: NC\n"
- + "mobile: 027-085-0537\n"
- + "postalAddress: Aaccf Amar$17984 Thirteenth Street"
- + "$Rockford, NC 85762\n"
- + "mail: user.1@example.com\n"
- + "cn: Aaccf Amar\n"
- + "l: Rockford\n"
- + "pager: 508-763-4246\n"
- + "street: 17984 Thirteenth Street\n"
- + "telephoneNumber: 216-564-6748\n"
- + "employeeNumber: 1\n"
- + "sn: Amar\n"
- + "givenName: Aaccf\n"
- + "postalCode: 85762\n"
- + "userPassword: password\n"
- + "initials: AA\n"
- + "\n"
- + "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz\n"
- + "# dn:: ou=<JapaneseOU>,o=Airius\n"
- + "objectclass: top\n"
- + "objectclass: organizationalUnit\n"
- + "ou:: 5Za25qWt6YOo\n"
- + "# ou:: <JapaneseOU>\n"
- + "ou;lang-ja:: 5Za25qWt6YOo\n"
- + "# ou;lang-ja:: <JapaneseOU>\n"
- + "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n"
- + "# ou;lang-ja:: <JapaneseOU_in_phonetic_representation>\n"
- + "ou;lang-en: Sales\n"
- + "description: Japanese office\n"
- + "\n"
- + "dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz\n"
- + "# dn:: uid=<uid>,ou=<JapaneseOU>,o=Airius\n"
- + "userpassword: {SHA}O3HSv1MusyL4kTjP+HKI5uxuNoM=\n"
- + "objectclass: top\n"
- + "objectclass: person\n"
- + "objectclass: organizationalPerson\n"
- + "objectclass: inetOrgPerson\n"
- + "uid: rogasawara\n"
- + "mail: rogasawara@airius.co.jp\n"
- + "givenname;lang-ja:: 44Ot44OJ44OL44O8\n"
- + "# givenname;lang-ja:: <JapaneseGivenname>\n"
- + "sn;lang-ja:: 5bCP56yg5Y6f\n"
- + "# sn;lang-ja:: <JapaneseSn>\n"
- + "cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn;lang-ja:: <JapaneseCn>\n"
- + "title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title;lang-ja:: <JapaneseTitle>\n"
- + "preferredlanguage: ja\n"
- + "givenname:: 44Ot44OJ44OL44O8\n"
- + "# givenname:: <JapaneseGivenname>\n"
- + "sn:: 5bCP56yg5Y6f\n"
- + "# sn:: <JapaneseSn>\n"
- + "cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==\n"
- + "# cn:: <JapaneseCn>\n"
- + "title:: 5Za25qWt6YOoIOmDqOmVtw==\n"
- + "# title:: <JapaneseTitle>\n"
- + "givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8\n"
- + "# givenname;lang-ja;phonetic:: "
- + "<JapaneseGivenname_in_phonetic_representation_kana>\n"
- + "sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ\n"
- + "# sn;lang-ja;phonetic:: "
- + "<JapaneseSn_in_phonetic_representation_kana>\n"
- + "cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==\n"
- + "# cn;lang-ja;phonetic:: "
- + "<JapaneseCn_in_phonetic_representation_kana>\n"
- + "title;lang-ja;phonetic:: "
- + ""
- + "44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==\n"
- + "# title;lang-ja;phonetic::\n"
- + "# <JapaneseTitle_in_phonetic_representation_kana>\n"
- + "givenname;lang-en: Rodney\n"
- + "sn;lang-en: Ogasawara\n"
- + "cn;lang-en: Rodney Ogasawara\n"
- + "title;lang-en: Sales, Director\n" + "\n" + "";
-
- @DataProvider
- public Object[][] entryIDToAndFromDatabaseDataProvider()
- {
- return new Object[][] {
- { 128 }, { 1234567 }, { 0 }, { 1 }, { -1 },
- { 2 ^ 32 - 1 }, { 2 ^ 63 - 1 }, { Long.MIN_VALUE }, { Long.MAX_VALUE },
- };
- }
-
- /**
- * Test entry IDs.
- */
- @Test(dataProvider = "entryIDToAndFromDatabaseDataProvider")
- public void testEntryIDToAndFromDatabase(long before) throws Exception
- {
- byte[] bytes = JebFormat.entryIDToDatabase(before);
- long after = JebFormat.entryIDFromDatabase(bytes);
- assertEquals(after, before);
- }
-
- @DataProvider
- public Object[][] entryIDUndefinedSizeToAndFromDatabaseDataProvider()
- {
- return new Object[][] {
- { 128 }, { 1234567 }, { 0 }, { 1 },
- { 2 ^ 32 - 1 }, { 2 ^ 63 - 1 }, { Long.MAX_VALUE },
- };
- }
-
- /**
- * Test entry ID set counts.
- */
- @Test(dataProvider = "entryIDUndefinedSizeToAndFromDatabaseDataProvider")
- public void testEntryIDUndefinedSizeToAndFromDatabase(long before) throws Exception
- {
- byte[] bytes = JebFormat.entryIDUndefinedSizeToDatabase(before);
- assertEquals(bytes[0] & 0x80, 0x80);
- long after = JebFormat.entryIDUndefinedSizeFromDatabase(bytes);
- assertEquals(after, before);
- }
-
- @Test
- public void testEntryIDUndefinedSizeFromDatabase() throws Exception
- {
- assertEquals(JebFormat.entryIDUndefinedSizeFromDatabase(null), 0);
- assertEquals(JebFormat.entryIDUndefinedSizeFromDatabase(new byte[0]), Long.MAX_VALUE);
- assertEquals(JebFormat.entryIDUndefinedSizeFromDatabase(new byte[9]), Long.MAX_VALUE);
- }
-
- /**
- * Test entry ID lists.
- */
- @Test(dataProvider = "entryIDListToAndFromDatabaseDataProvider")
- public void entryIDListToAndFromDatabase(long[] before) throws Exception
- {
- byte[] bytes = JebFormat.entryIDListToDatabase(before);
- long[] after = JebFormat.entryIDListFromDatabase(bytes);
- assertTrue(Arrays.equals(before, after));
- }
-
- @DataProvider
- public Object[][] entryIDListToAndFromDatabaseDataProvider() throws Exception
- {
- long[] array = new long[100000];
- for (int i = 0; i < 100000; i++) {
- array[i] = i * 2 + 1;
- }
- return new Object[][] {
- { new long[] { 1, 2, 3, 4, 5 } },
- { new long[] { 999999 } },
- { new long[] { 1, 128, 1234567 } },
- { array },
- };
- }
-
- /**
- * Encodes this entry using the V3 encoding.
- *
- * @param buffer The buffer to encode into.
- *
- * @throws DirectoryException If a problem occurs while attempting
- * to encode the entry.
- */
- private void encodeV1(Entry entry, ByteStringBuilder buffer)
- throws DirectoryException
- {
- // The version number will be one byte.
- buffer.appendByte(0x01);
-
- // TODO: Can we encode the DN directly into buffer?
- byte[] dnBytes = getBytes(entry.getName().toString());
- buffer.appendBERLength(dnBytes.length);
- buffer.appendBytes(dnBytes);
-
-
- // Encode number of OCs and 0 terminated names.
- int i = 1;
- ByteStringBuilder bsb = new ByteStringBuilder();
- for (String ocName : entry.getObjectClasses().values())
- {
- bsb.appendUtf8(ocName);
- if(i < entry.getObjectClasses().values().size())
- {
- bsb.appendByte(0x00);
- }
- i++;
- }
- buffer.appendBERLength(bsb.length());
- buffer.appendBytes(bsb);
-
-
- // Encode the user attributes in the appropriate manner.
- encodeV1Attributes(buffer, entry.getUserAttributes());
-
-
- // The operational attributes will be encoded in the same way as
- // the user attributes.
- encodeV1Attributes(buffer, entry.getOperationalAttributes());
- }
-
- private void encodeV1Attributes(ByteStringBuilder buffer,
- Map<AttributeType,List<Attribute>> attributes)
- throws DirectoryException
- {
- int numAttributes = 0;
-
- // First count how many attributes are there to encode.
- for (List<Attribute> attrList : attributes.values())
- {
- for (Attribute a : attrList)
- {
- if (a.isVirtual() || a.isEmpty())
- {
- continue;
- }
-
- numAttributes++;
- }
- }
-
- // Encoded one-to-five byte number of attributes
- buffer.appendBERLength(numAttributes);
-
- append(buffer, attributes);
- }
-
- /**
- * Encodes this entry using the V3 encoding.
- *
- * @param buffer The buffer to encode into.
- *
- * @throws DirectoryException If a problem occurs while attempting
- * to encode the entry.
- */
- private void encodeV2(Entry entry, ByteStringBuilder buffer,
- EntryEncodeConfig config)
- throws DirectoryException
- {
- // The version number will be one byte.
- buffer.appendByte(0x02);
-
- // Get the encoded respresentation of the config.
- config.encode(buffer);
-
- // If we should include the DN, then it will be encoded as a
- // one-to-five byte length followed by the UTF-8 byte
- // representation.
- if (! config.excludeDN())
- {
- // TODO: Can we encode the DN directly into buffer?
- byte[] dnBytes = getBytes(entry.getName().toString());
- buffer.appendBERLength(dnBytes.length);
- buffer.appendBytes(dnBytes);
- }
-
-
- // Encode the object classes in the appropriate manner.
- if (config.compressObjectClassSets())
- {
- config.getCompressedSchema().encodeObjectClasses(buffer,
- entry.getObjectClasses());
- }
- else
- {
- // Encode number of OCs and 0 terminated names.
- int i = 1;
- ByteStringBuilder bsb = new ByteStringBuilder();
- for (String ocName : entry.getObjectClasses().values())
- {
- bsb.appendUtf8(ocName);
- if(i < entry.getObjectClasses().values().size())
- {
- bsb.appendByte(0x00);
- }
- i++;
- }
- buffer.appendBERLength(bsb.length());
- buffer.appendBytes(bsb);
- }
-
-
- // Encode the user attributes in the appropriate manner.
- encodeV2Attributes(buffer, entry.getUserAttributes(), config);
-
-
- // The operational attributes will be encoded in the same way as
- // the user attributes.
- encodeV2Attributes(buffer, entry.getOperationalAttributes(), config);
- }
-
- private void encodeV2Attributes(ByteStringBuilder buffer,
- Map<AttributeType,List<Attribute>> attributes,
- EntryEncodeConfig config)
- throws DirectoryException
- {
- int numAttributes = 0;
-
- // First count how many attributes are there to encode.
- for (List<Attribute> attrList : attributes.values())
- {
- for (Attribute a : attrList)
- {
- if (a.isVirtual() || a.isEmpty())
- {
- continue;
- }
-
- numAttributes++;
- }
- }
-
- // Encoded one-to-five byte number of attributes
- buffer.appendBERLength(numAttributes);
-
- if (config.compressAttributeDescriptions())
- {
- for (List<Attribute> attrList : attributes.values())
- {
- for (Attribute a : attrList)
- {
- if (a.isVirtual() || a.isEmpty())
- {
- continue;
- }
-
- ByteStringBuilder bsb = new ByteStringBuilder();
- config.getCompressedSchema().encodeAttribute(bsb, a);
- buffer.appendBERLength(bsb.length());
- buffer.appendBytes(bsb);
- }
- }
- }
- else
- {
- append(buffer, attributes);
- }
- }
-
- /**
- * The attributes will be encoded as a sequence of:
- * - A UTF-8 byte representation of the attribute name.
- * - A zero delimiter
- * - A one-to-five byte number of values for the attribute
- * - A sequence of:
- * - A one-to-five byte length for the value
- * - A UTF-8 byte representation for the value
- */
- private void append(ByteStringBuilder buffer,
- Map<AttributeType, List<Attribute>> attributes)
- {
- for (List<Attribute> attrList : attributes.values())
- {
- for (Attribute a : attrList)
- {
- byte[] nameBytes = getBytes(a.getNameWithOptions());
- buffer.appendBytes(nameBytes);
- buffer.appendByte(0x00);
-
- buffer.appendBERLength(a.size());
- for (ByteString v : a)
- {
- buffer.appendBERLength(v.length());
- buffer.appendBytes(v);
- }
- }
- }
- }
-
- /**
- * Test entry.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test
- public void testEntryToAndFromDatabase() throws Exception {
- ensureServerIsUpAndRunning();
-
- // Convert the test LDIF string to a byte array
- byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
-
- LDIFReader reader = new LDIFReader(new LDIFImportConfig(
- new ByteArrayInputStream(originalLDIFBytes)));
-
- Entry entryBefore, entryAfter;
- while ((entryBefore = reader.readEntry(false)) != null) {
- ByteString bytes = ID2Entry.entryToDatabase(entryBefore,
- new DataConfig(false, false, null));
-
- entryAfter = ID2Entry.entryFromDatabase(bytes,
- DirectoryServer.getDefaultCompressedSchema());
-
- // check DN and number of attributes
- assertEquals(entryBefore.getAttributes().size(), entryAfter
- .getAttributes().size());
-
- assertEquals(entryBefore.getName(), entryAfter.getName());
-
- // check the object classes were not changed
- for (String ocBefore : entryBefore.getObjectClasses().values()) {
- ObjectClass objectClass = DirectoryServer.getObjectClass(ocBefore
- .toLowerCase());
- if (objectClass == null) {
- objectClass = DirectoryServer.getDefaultObjectClass(ocBefore);
- }
- String ocAfter = entryAfter.getObjectClasses().get(objectClass);
-
- assertEquals(ocBefore, ocAfter);
- }
-
- // check the user attributes were not changed
- for (AttributeType attrType : entryBefore.getUserAttributes()
- .keySet()) {
- List<Attribute> listBefore = entryBefore.getAttribute(attrType);
- List<Attribute> listAfter = entryAfter.getAttribute(attrType);
-
- assertNotNull(listAfter);
- assertEquals(listBefore.size(), listAfter.size());
-
- for (Attribute attrBefore : listBefore) {
- boolean found = false;
-
- for (Attribute attrAfter : listAfter) {
- if (attrAfter.optionsEqual(attrBefore.getOptions())) {
- // Found the corresponding attribute
-
- assertEquals(attrBefore, attrAfter);
- found = true;
- }
- }
-
- assertTrue(found);
- }
- }
- }
- reader.close();
- }
-
- /**
- * Tests the entry encoding and decoding process the version 1 encoding.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test
- public void testEntryToAndFromDatabaseV1() throws Exception {
- ensureServerIsUpAndRunning();
-
- // Convert the test LDIF string to a byte array
- byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
-
- LDIFReader reader = new LDIFReader(new LDIFImportConfig(
- new ByteArrayInputStream(originalLDIFBytes)));
-
- Entry entryBefore, entryAfterV1;
- while ((entryBefore = reader.readEntry(false)) != null) {
- ByteStringBuilder bsb = new ByteStringBuilder();
- encodeV1(entryBefore, bsb);
- entryAfterV1 = Entry.decode(bsb.asReader());
-
- assertEquals(entryBefore, entryAfterV1);
- }
- reader.close();
- }
-
- /**
- * Retrieves a set of entry encode configurations that may be used to test the
- * entry encoding and decoding capabilities.
- */
- @DataProvider(name = "encodeConfigs")
- public Object[][] getEntryEncodeConfigs()
- {
- return new Object[][]
- {
- new Object[] { new EntryEncodeConfig() },
- new Object[] { new EntryEncodeConfig(false, false, false) },
- new Object[] { new EntryEncodeConfig(true, false, false) },
- new Object[] { new EntryEncodeConfig(false, true, false) },
- new Object[] { new EntryEncodeConfig(false, false, true) },
- new Object[] { new EntryEncodeConfig(true, true, false) },
- new Object[] { new EntryEncodeConfig(true, false, true) },
- new Object[] { new EntryEncodeConfig(false, true, true) },
- new Object[] { new EntryEncodeConfig(true, true, true) },
- };
- }
-
- /**
- * Tests the entry encoding and decoding process the version 1 encoding.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(dataProvider = "encodeConfigs")
- public void testEntryToAndFromDatabaseV2(EntryEncodeConfig config)
- throws Exception {
- ensureServerIsUpAndRunning();
-
- // Convert the test LDIF string to a byte array
- byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
-
- LDIFReader reader = new LDIFReader(new LDIFImportConfig(
- new ByteArrayInputStream(originalLDIFBytes)));
-
- Entry entryBefore, entryAfterV2;
- while ((entryBefore = reader.readEntry(false)) != null) {
- ByteStringBuilder bsb = new ByteStringBuilder();
- encodeV2(entryBefore, bsb, config);
- entryAfterV2 = Entry.decode(bsb.asReader());
- if (config.excludeDN())
- {
- entryAfterV2.setDN(entryBefore.getName());
- }
- assertEquals(entryBefore, entryAfterV2);
- }
- reader.close();
- }
-
- /**
- * Tests the entry encoding and decoding process the version 1 encoding.
- *
- * @throws Exception
- * If the test failed unexpectedly.
- */
- @Test(dataProvider = "encodeConfigs")
- public void testEntryToAndFromDatabaseV3(EntryEncodeConfig config)
- throws Exception {
- ensureServerIsUpAndRunning();
-
- // Convert the test LDIF string to a byte array
- byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
-
- LDIFReader reader = new LDIFReader(new LDIFImportConfig(
- new ByteArrayInputStream(originalLDIFBytes)));
-
- Entry entryBefore, entryAfterV3;
- while ((entryBefore = reader.readEntry(false)) != null) {
- ByteStringBuilder bsb = new ByteStringBuilder();
- entryBefore.encode(bsb, config);
- entryAfterV3 = Entry.decode(bsb.asReader());
- if (config.excludeDN())
- {
- entryAfterV3.setDN(entryBefore.getName());
- }
- assertEquals(entryBefore, entryAfterV3);
- }
- reader.close();
- }
-
- @DataProvider
- private Object[][] findDnKeyParentData()
- {
- return new Object[][]
- {
- // dn, expected length of parent
- { "dc=example", 0 },
- { "dc=example,dc=com", 7 },
- { "dc=example,dc=com\\,org", 11 },
- };
- }
-
- @Test(dataProvider="findDnKeyParentData")
- public void testFindDnKeyParent(String dn, int expectedLength) throws Exception
- {
- ensureServerIsUpAndRunning();
- byte[] dnKey = dnToDNKey(DN.valueOf(dn), 0);
- assertThat(findDNKeyParent(dnKey)).isEqualTo(expectedLength);
- }
-
- private void ensureServerIsUpAndRunning() throws Exception
- {
- TestCaseUtils.startServer();
- }
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestRebuildJob.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestRebuildJob.java
deleted file mode 100644
index d066d36..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestRebuildJob.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2009 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import static org.testng.Assert.*;
-
-import org.opends.server.TestCaseUtils;
-import org.opends.server.api.Backend;
-import org.opends.server.backends.RebuildConfig;
-import org.opends.server.backends.RebuildConfig.RebuildMode;
-import org.opends.server.backends.VerifyConfig;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.core.ServerContext;
-import org.opends.server.tasks.TaskUtils;
-import org.opends.server.types.DN;
-import org.opends.server.types.DirectoryException;
-import org.opends.server.types.InitializationException;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-@SuppressWarnings("javadoc")
-public class TestRebuildJob extends JebTestCase
-{
- private String backendID = "rebuildRoot";
- private static String suffix="dc=rebuild,dc=jeb";
- private static String vBranch="ou=rebuild tests," + suffix;
- private String numUsersLine="define numusers= #numEntries#";
-
- private DN[] baseDNs;
- private Backend<?> backend;
-
- @DataProvider(name = "systemIndexes")
- public Object[][] systemIndexes() {
- return new Object[][] {
- { "dn2id" },
- { "dn2uri" }
- // { "id2entry" } internal index
- };
- }
-
- @DataProvider(name = "attributeIndexes")
- public Object[][] attributeIndexes() {
- return new Object[][] {
- { "mail" },
- { "mail.presence" },
- { "mail.substring" },
- { "mail.ordering" },
- { "mail.equality" },
- { "mail.approximate" },
- { "vlv.testvlvindex" }
- };
- }
-
- @DataProvider(name = "badIndexes")
- public Object[][] badIndexes() {
- return new Object[][] {
- { "nonindex" },
- { "id2subtree" },
- { "id2children" },
- { "mail.nonindex" }
- };
- }
-
- private static String[] template = new String[] {
- "define suffix="+suffix,
- "define maildomain=example.com",
- "define numusers= #numEntries#",
- "",
- "branch: [suffix]",
- "",
- "branch: " + vBranch,
- "subordinateTemplate: person:[numusers]",
- "",
- "template: person",
- "rdnAttr: uid",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: ABOVE LIMIT",
- "sn: <last>",
- "cn: {givenName} {sn}",
- "initials: {givenName:1}<random:chars:" +
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}",
- "employeeNumber: <sequential:0>",
- "uid: user.{employeeNumber}",
- "mail: {uid}@[maildomain]",
- "userPassword: password",
- "telephoneNumber: <random:telephone>",
- "homePhone: <random:telephone>",
- "pager: <random:telephone>",
- "mobile: <random:telephone>",
- "street: <random:numeric:5> <file:streets> Street",
- "l: <file:cities>",
- "st: <file:states>",
- "postalCode: <random:numeric:5>",
- "postalAddress: {cn}${street}${l}, {st} {postalCode}",
- "description: This is the description for {cn}.",
- ""};
-
- @BeforeClass
- public void setup() throws Exception {
- TestCaseUtils.startServer();
- TestCaseUtils.enableBackend(backendID);
- baseDNs = new DN[] {
- DN.valueOf(suffix)
- };
- }
-
- @AfterClass
- public void cleanUp() throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- TestCaseUtils.disableBackend(backendID);
- }
-
- /**
- * Cleans verify backend and loads some number of entries.
- * @param numEntries number of entries to load into the backend.
- * @throws Exception if the entries are not loaded or created.
- */
- private void cleanAndLoad(int numEntries) throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- template[2] = numUsersLine.replaceAll("#numEntries#", String.valueOf(numEntries));
- createLoadEntries(template, numEntries);
- }
-
- /**
- * Runs rebuild against the system indexes.
- *
- * @throws Exception if
- */
- @Test(dataProvider = "attributeIndexes")
- public void testRebuildAttributeIndexes(String index) throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex(index);
- backend = DirectoryServer.getBackend(backendID);
- backend.rebuildBackend(rebuildConfig, getServerContext());
-
- if(index.contains(".") && !index.startsWith("vlv."))
- {
- assertEquals(verifyBackend(index.split("\\.")[0]), 0);
- }
- else
- {
- assertEquals(verifyBackend(index), 0);
- }
- }
-
- /**
- * Try to rebuild the main system index id2entry.
- * (primary index from which all other indexes are derived).
- * It cannot ever be rebuilt. Online mode.
- *
- * @throws InitializationException There is no index configured
- * for attribute type 'id2entry'.
- */
- @Test(expectedExceptions = InitializationException.class)
- public void testRebuildForbiddenSystemIndexId2EntryOnline() throws Exception
- {
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex("id2entry");
- backend = DirectoryServer.getBackend(backendID);
- backend.rebuildBackend(rebuildConfig, getServerContext());
- }
-
- /**
- * Try to rebuild the main system index id2entry.
- * (primary index from which all other indexes are derived).
- * It cannot ever be rebuilt. Offline mode.
- *
- * @throws InitializationException There is no index configured
- * for attribute type 'id2entry'.
- */
- @Test(expectedExceptions = InitializationException.class)
- public void testRebuildForbiddenSystemIndexId2EntryOffline() throws Exception
- {
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex("id2entry");
- backend = DirectoryServer.getBackend(backendID);
- TaskUtils.disableBackend(backendID);
-
- try {
- backend.rebuildBackend(rebuildConfig, getServerContext());
- } finally {
- TaskUtils.enableBackend(backendID);
- }
- }
-
- @Test(dataProvider = "badIndexes",
- expectedExceptions = InitializationException.class)
- public void testRebuildBadIndexes(final String index) throws Exception
- {
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex(index);
- backend = DirectoryServer.getBackend(backendID);
- backend.rebuildBackend(rebuildConfig, getServerContext());
- }
-
- @Test(dataProvider = "systemIndexes",
- expectedExceptions = DirectoryException.class)
- public void testRebuildSystemIndexesOnline(String index) throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex(index);
- backend = DirectoryServer.getBackend(backendID);
- backend.rebuildBackend(rebuildConfig, getServerContext());
- }
-
- @Test(dataProvider = "systemIndexes")
- public void testRebuildSystemIndexesOffline(String index) throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex(index);
-
- backend = DirectoryServer.getBackend(backendID);
- TaskUtils.disableBackend(backendID);
- backend.rebuildBackend(rebuildConfig, getServerContext());
-
- //TODO: Verify dn2uri database as well.
- if (!"dn2uri".equalsIgnoreCase(index))
- {
- assertEquals(verifyBackend(index), 0);
- }
-
- TaskUtils.enableBackend(backendID);
- }
-
- @Test
- public void testRebuildAll() throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.setRebuildMode(RebuildMode.ALL);
-
- rebuildIndexes(rebuildConfig);
- }
-
- @Test
- public void testRebuildDegraded() throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.setRebuildMode(RebuildMode.DEGRADED);
-
- rebuildIndexes(rebuildConfig);
- }
-
- @Test
- public void testRebuildDN2ID() throws Exception
- {
- cleanAndLoad(10);
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex("dn2id");
-
- rebuildIndexes(rebuildConfig);
- }
-
- private void rebuildIndexes(RebuildConfig rebuildConfig) throws Exception
- {
- backend = DirectoryServer.getBackend(backendID);
- TaskUtils.disableBackend(backendID);
- try
- {
- backend.rebuildBackend(rebuildConfig, getServerContext());
- assertEquals(verifyBackend(null), 0);
- }
- finally
- {
- TaskUtils.enableBackend(backendID);
- }
- }
-
- private ServerContext getServerContext()
- {
- return DirectoryServer.getInstance().getServerContext();
- }
-
- @Test
- public void testRebuildRedundentIndexes() throws Exception
- {
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.addRebuildIndex("dn2id");
- rebuildConfig.addRebuildIndex("dn2id");
- rebuildConfig.addRebuildIndex("cn");
- rebuildConfig.addRebuildIndex("cn.presence");
- rebuildConfig.addRebuildIndex("uid.equality");
- rebuildConfig.addRebuildIndex("uid");
-
- assertEquals(rebuildConfig.getRebuildList().size(), 3);
- assertTrue(rebuildConfig.getRebuildList().contains("dn2id"));
- assertTrue(rebuildConfig.getRebuildList().contains("cn"));
- assertTrue(rebuildConfig.getRebuildList().contains("uid"));
- }
-
- @Test
- public void testRebuildMultipleJobs() throws Exception
- {
- RebuildConfig rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex("dn2id");
- rebuildConfig.addRebuildIndex("id2children");
- rebuildConfig.addRebuildIndex("cn");
-
- RebuildConfig rebuildConfig2 = new RebuildConfig();
- rebuildConfig2.setBaseDN(baseDNs[0]);
- rebuildConfig2.addRebuildIndex("dn2id");
-
- assertNotNull(rebuildConfig.checkConflicts(rebuildConfig2));
- assertNotNull(rebuildConfig2.checkConflicts(rebuildConfig));
-
- rebuildConfig = new RebuildConfig();
- rebuildConfig.setBaseDN(baseDNs[0]);
- rebuildConfig.addRebuildIndex("cn");
-
- rebuildConfig2 = new RebuildConfig();
- rebuildConfig2.setBaseDN(baseDNs[0]);
- rebuildConfig2.addRebuildIndex("cn.presence");
- rebuildConfig2.addRebuildIndex("dn2id");
-
- assertNotNull(rebuildConfig.checkConflicts(rebuildConfig2));
- assertNotNull(rebuildConfig2.checkConflicts(rebuildConfig));
- }
-
- private long verifyBackend(String index) throws Exception
- {
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- if(index != null)
- {
- verifyConfig.addCleanIndex(index);
- }
- return backend.verifyBackend(verifyConfig);
- }
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVLVIndex.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVLVIndex.java
deleted file mode 100644
index 2fd8cee..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVLVIndex.java
+++ /dev/null
@@ -1,961 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.TreeSet;
-
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ResultCode;
-import org.forgerock.opendj.ldap.SearchScope;
-import org.opends.server.DirectoryServerTestCase;
-import org.opends.server.TestCaseUtils;
-import org.forgerock.opendj.ldap.schema.MatchingRule;
-import org.opends.server.controls.ServerSideSortRequestControl;
-import org.opends.server.controls.ServerSideSortResponseControl;
-import org.opends.server.controls.VLVRequestControl;
-import org.opends.server.controls.VLVResponseControl;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.protocols.internal.InternalSearchOperation;
-import org.opends.server.protocols.internal.Requests;
-import org.opends.server.protocols.internal.SearchRequest;
-import org.opends.server.protocols.ldap.LDAPControl;
-import org.opends.server.protocols.ldap.LDAPResultCode;
-import org.opends.server.types.*;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.opends.server.protocols.internal.InternalClientConnection.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.testng.Assert.*;
-
-@SuppressWarnings("javadoc")
-public class TestVLVIndex extends DirectoryServerTestCase {
- private SortOrder sortOrder;
-
- private String beID="indexRoot";
- private BackendImpl be;
-
- /** The DN for "Aaccf Johnson". */
- private DN aaccfJohnsonDN;
- /** The DN for "Aaron Zimmerman". */
- private DN aaronZimmermanDN;
- /** The DN for "Albert Smith". */
- private DN albertSmithDN;
- /** The DN for "Albert Zimmerman". */
- private DN albertZimmermanDN;
- /** The DN for "lowercase mcgee". */
- private DN lowercaseMcGeeDN;
- /** The DN for "Mararet Jones". */
- private DN margaretJonesDN;
- /** The DN for "Mary Jones". */
- private DN maryJonesDN;
- /** The DN for "Sam Zweck". */
- private DN samZweckDN;
- /** The DN for "Zorro". */
- private DN zorroDN;
- /** The DN for suffix. */
- private DN suffixDN;
-
- private TreeSet<SortValues> expectedSortedValues;
- private List<Entry> entries;
-
- @BeforeClass
- public void setUp() throws Exception {
- TestCaseUtils.startServer();
- TestCaseUtils.enableBackend(beID);
-
- SortKey[] sortKeys = new SortKey[] {
- new SortKey(DirectoryServer.getAttributeTypeOrNull("givenname"), true),
- new SortKey(DirectoryServer.getAttributeTypeOrNull("sn"), false),
- new SortKey(DirectoryServer.getAttributeTypeOrNull("uid"), true),
- };
- sortOrder = new SortOrder(sortKeys);
-
- aaccfJohnsonDN = DN.valueOf("uid=aaccf.johnson,dc=vlvtest,dc=com");
- aaronZimmermanDN = DN.valueOf("uid=aaron.zimmerman,dc=vlvtest,dc=com");
- albertSmithDN = DN.valueOf("uid=albert.smith,dc=vlvtest,dc=com");
- albertZimmermanDN = DN.valueOf("uid=albert.zimmerman,dc=vlvtest,dc=com");
- lowercaseMcGeeDN = DN.valueOf("uid=lowercase.mcgee,dc=vlvtest,dc=com");
- margaretJonesDN = DN.valueOf("uid=margaret.jones,dc=vlvtest,dc=com");
- maryJonesDN = DN.valueOf("uid=mary.jones,dc=vlvtest,dc=com");
- samZweckDN = DN.valueOf("uid=sam.zweck,dc=vlvtest,dc=com");
- zorroDN = DN.valueOf("uid=zorro,dc=vlvtest,dc=com");
- suffixDN = DN.valueOf("dc=vlvtest,dc=com");
-
- expectedSortedValues = new TreeSet<>();
-
- entries = TestCaseUtils.makeEntries(
- "dn: dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: domain",
- "",
- "dn: uid=albert.zimmerman,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: albert.zimmerman",
- "givenName: Albert",
- "sn: Zimmerman",
- "cn: Albert Zimmerman",
- "",
- "dn: uid=albert.smith,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: albert.smith",
- "givenName: Albert",
- "sn: Smith",
- "cn: Albert Smith",
- "",
- "dn: uid=aaron.zimmerman,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: albert.zimmerman",
- "givenName: Aaron",
- "givenName: Zeke",
- "sn: Zimmerman",
- "cn: Aaron Zimmerman",
- "",
- "dn: uid=mary.jones,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: mary.jones",
- "givenName: Mary",
- "sn: Jones",
- "cn: Mary Jones",
- "",
- "dn: uid=margaret.jones,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: margaret.jones",
- "givenName: Margaret",
- "givenName: Maggie",
- "sn: Jones",
- "sn: Smith",
- "cn: Maggie Jones-Smith",
- "",
- "dn: uid=aaccf.johnson,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: aaccf.johnson",
- "givenName: Aaccf",
- "sn: Johnson",
- "cn: Aaccf Johnson",
- "",
- "dn: uid=sam.zweck,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: sam.zweck",
- "givenName: Sam",
- "sn: Zweck",
- "cn: Sam Zweck",
- "",
- "dn: uid=lowercase.mcgee,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: lowercase.mcgee",
- "givenName: lowercase",
- "sn: mcgee",
- "cn: lowercase mcgee",
- "",
- "dn: uid=zorro,dc=vlvtest,dc=com",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "uid: zorro",
- "sn: Zorro",
- "cn: Zorro"
- );
- }
-
- @AfterClass
- public void cleanUp() throws Exception {
- TestCaseUtils.clearJEBackend(beID);
- TestCaseUtils.disableBackend(beID);
- }
-
- /**
- * Populates the JE DB with a set of test data.
- *
- * @throws Exception If an unexpected problem occurs.
- */
- private void populateDB()
- throws Exception
- {
- long id = 1;
- for(Entry entry : entries)
- {
- TestCaseUtils.addEntry(entry);
- expectedSortedValues.add(new SortValues(new EntryID(id), entry,
- sortOrder));
- id++;
- }
- }
-
- @Test
- public void testDel() throws Exception
- {
- populateDB();
-
- TestCaseUtils.deleteEntry(entries.get(1));
- TestCaseUtils.deleteEntry(entries.get(entries.size() - 1));
-
- be=(BackendImpl) DirectoryServer.getBackend(beID);
- RootContainer rootContainer = be.getRootContainer();
- EntryContainer entryContainer =
- rootContainer.getEntryContainer(DN.valueOf("dc=vlvtest,dc=com"));
-
- for(VLVIndex vlvIndex : entryContainer.getVLVIndexes())
- {
- if(vlvIndex.getName().contains("testvlvindex"))
- {
- SortValues sv1 = expectedSortedValues.first();
- SortValuesSet svs1 = getSortValuesSet(vlvIndex, sv1);
- assertEquals(svs1.size(), 3);
-
- SortValues sv2 = expectedSortedValues.last();
- SortValuesSet svs2 = getSortValuesSet(vlvIndex, sv2);
- assertEquals(svs2.size(), 5);
- }
- }
-
- for(int i = 2; i <= entries.size() - 2; i++)
- {
- TestCaseUtils.deleteEntry(entries.get(i));
- }
- // Delete the base entry
- TestCaseUtils.deleteEntry(entries.get(0));
-
- for(VLVIndex vlvIndex : entryContainer.getVLVIndexes())
- {
- if(vlvIndex.getName().contains("testvlvindex"))
- {
- SortValues sv1 = expectedSortedValues.first();
- SortValuesSet svs1 = getSortValuesSet(vlvIndex, sv1);
- assertEquals(svs1.size(), 0);
- assertNull(svs1.getKeyBytes());
-
- SortValues sv2 = expectedSortedValues.last();
- SortValuesSet svs2 = getSortValuesSet(vlvIndex, sv2);
- assertEquals(svs2.size(), 0);
- assertNull(svs2.getKeyBytes());
- }
- }
- }
-
- private SortValuesSet getSortValuesSet(VLVIndex vlvIndex, SortValues sv)
- throws DirectoryException
- {
- SortValuesSet result =
- vlvIndex.getSortValuesSet(null, 0, sv.getValues(), sv.getTypes());
- assertNotNull(result);
- return result;
- }
-
- @Test( dependsOnMethods = { "testDel" } )
- public void testAdd() throws Exception
- {
- populateDB();
- be=(BackendImpl) DirectoryServer.getBackend(beID);
- RootContainer rootContainer = be.getRootContainer();
- EntryContainer entryContainer =
- rootContainer.getEntryContainer(DN.valueOf("dc=vlvtest,dc=com"));
-
- for(VLVIndex vlvIndex : entryContainer.getVLVIndexes())
- {
- if(vlvIndex.getName().contains("testvlvindex"))
- {
- SortValues sv1 = expectedSortedValues.first();
- SortValuesSet svs1 = getSortValuesSet(vlvIndex, sv1);
- assertEquals(svs1.size(), 4);
-
- SortValues sv2 = expectedSortedValues.last();
- SortValuesSet svs2 = getSortValuesSet(vlvIndex, sv2);
- assertEquals(svs2.size(), 6);
-
- int i = 0;
- for(SortValues values : expectedSortedValues)
- {
- ByteString[] attrValues = values.getValues();
- AttributeType[] attrTypes = values.getTypes();
- for(int j = 0; j < attrValues.length; j++)
- {
- ByteString value;
- if(i < 4)
- {
- value = svs1.getValue(i * 3 + j);
- }
- else
- {
- value = svs2.getValue((i - 4) * 3 + j);
- }
- ByteString oValue = null;
- if(attrValues[j] != null)
- {
- MatchingRule eqRule = attrTypes[j].getEqualityMatchingRule();
- oValue = eqRule.normalizeAttributeValue(attrValues[j]);
- }
- assertEquals(value, oValue);
- }
- i++;
- }
- }
- }
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an offset of one.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetOneOffset() throws Exception
- {
- SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, 1, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder());
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 1);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- private ArrayList<DN> getDNs(InternalSearchOperation internalSearch)
- {
- ArrayList<DN> results = new ArrayList<>();
- for (Entry e : internalSearch.getSearchEntries())
- {
- results.add(e.getName());
- }
- return results;
- }
-
- private List<DN> expectedDNOrder()
- {
- return Arrays.asList(
- aaccfJohnsonDN, // Aaccf
- aaronZimmermanDN, // Aaron
- albertZimmermanDN, // Albert, bigger
- albertSmithDN); // Albert, smaller sn
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an offset of zero, which should be treated like
- * an offset of one.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetZeroOffset() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, 0, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder());
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 1);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an offset that isn't at the beginning of the
- * result set but is still completely within the bounds of that set.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetThreeOffset() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, 3, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(albertZimmermanDN); // Albert, bigger
- expectedDNOrder.add(albertSmithDN); // Albert, smaller sn
- expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
- expectedDNOrder.add(margaretJonesDN); // Maggie
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 3);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control with a negative
- * target offset.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetNegativeOffset() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, -1, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
-
- // It will be successful because it's not a critical control.
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
-
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- }
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(),
- LDAPResultCode.OFFSET_RANGE_ERROR);
- }
-
- /**
- * Tests performing an internal search using the VLV control with an offset of
- * one but a beforeCount that puts the start position at a negative value.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetNegativeStartPosition() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(3, 3, 1, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
-
- // It will be successful because it's not a critical control.
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
-
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- }
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS);
- }
-
- /**
- * Tests performing an internal search using the VLV control with a start
- * start position beyond the end of the result set.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetStartPositionTooHigh() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(3, 3, 30, 0));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
-
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(samZweckDN); // Sam
- expectedDNOrder.add(zorroDN); // No first name
- expectedDNOrder.add(suffixDN); // No sort attributes
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
-
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- }
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS);
- assertEquals(vlvResponse.getTargetPosition(), 11);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control with a start
- * start position within the bounds of the list but not enough remaining
- * entries to meet the afterCount
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByOffsetIncompleteAfterCount() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 4, 7, 0));
-
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(maryJonesDN); // Mary
- expectedDNOrder.add(samZweckDN); // Sam
- expectedDNOrder.add(zorroDN); // No first name
- expectedDNOrder.add(suffixDN); // No sort attributes
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 7);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- private VLVResponseControl asVLVResponseControl(Control c) throws DirectoryException
- {
- if(c instanceof LDAPControl)
- {
- return VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue());
- }
- return (VLVResponseControl) c;
- }
-
- private ServerSideSortResponseControl asServerSideSortResponseControl(Control c) throws DirectoryException
- {
- if(c instanceof LDAPControl)
- {
- return ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue());
- }
- return (ServerSideSortResponseControl) c;
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an assertion value before any actual value in
- * the list.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByValueBeforeAll() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, ByteString.valueOfUtf8("a")));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
-
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder());
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 1);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an assertion value that matches the first value
- * in the list.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByValueMatchesFirst() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, ByteString.valueOfUtf8("aaccf")));
-
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder());
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 1);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an assertion value that matches the third value
- * in the list.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByValueMatchesThird() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, ByteString.valueOfUtf8("albert")));
-
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
- expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
- expectedDNOrder.add(margaretJonesDN); // Maggie
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 3);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an assertion value that matches the third value
- * in the list and includes a nonzero before count.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByValueMatchesThirdWithBeforeCount() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(1, 3, ByteString.valueOfUtf8("albert")));
-
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(aaronZimmermanDN); // Aaron
- expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID
- expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID
- expectedDNOrder.add(lowercaseMcGeeDN); // lowercase
- expectedDNOrder.add(margaretJonesDN); // Maggie
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
- assertEquals(responseControls.size(), 2);
-
- ServerSideSortResponseControl sortResponse = null;
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL))
- {
- sortResponse = asServerSideSortResponseControl(c);
- }
- else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- else
- {
- Assert.fail("Response control with unexpected OID " + c.getOID());
- }
- }
-
- assertNotNull(sortResponse);
- assertEquals(sortResponse.getResultCode(), 0);
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(), 0);
- assertEquals(vlvResponse.getTargetPosition(), 3);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
- /**
- * Tests performing an internal search using the VLV control to retrieve a
- * subset of the entries using an assertion value that is after all values in
- * the list.
- *
- * @throws Exception If an unexpected problem occurred.
- */
- @Test( dependsOnMethods = { "testAdd" } )
- public void testInternalSearchByValueAfterAll() throws Exception
- {
- final SearchRequest request = Requests.newSearchRequest(DN.valueOf("dc=vlvtest,dc=com"), SearchScope.WHOLE_SUBTREE)
- .addControl(new ServerSideSortRequestControl(sortOrder))
- .addControl(new VLVRequestControl(0, 3, ByteString.valueOfUtf8("zz")));
- InternalSearchOperation internalSearch = getRootConnection().processSearch(request);
-
- // It will be successful because the control isn't critical.
- assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS);
-
- // Null values for given name are still bigger then zz
- ArrayList<DN> expectedDNOrder = new ArrayList<>();
- expectedDNOrder.add(zorroDN); // No first name
- expectedDNOrder.add(suffixDN); // No sort attributes
-
- assertThat(getDNs(internalSearch)).isEqualTo(expectedDNOrder);
-
- List<Control> responseControls = internalSearch.getResponseControls();
- assertNotNull(responseControls);
-
- VLVResponseControl vlvResponse = null;
- for (Control c : responseControls)
- {
- if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL))
- {
- vlvResponse = asVLVResponseControl(c);
- }
- }
-
- assertNotNull(vlvResponse);
- assertEquals(vlvResponse.getVLVResultCode(),
- LDAPResultCode.SUCCESS);
- assertEquals(vlvResponse.getTargetPosition(), 9);
- assertEquals(vlvResponse.getContentCount(), 10);
- }
-
-}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVerifyJob.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVerifyJob.java
deleted file mode 100644
index 1d25299..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestVerifyJob.java
+++ /dev/null
@@ -1,921 +0,0 @@
-/*
- * 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 legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 legal-notices/CDDLv1_0.txt.
- * 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
- *
- *
- * Copyright 2006-2010 Sun Microsystems, Inc.
- * Portions Copyright 2011-2015 ForgeRock AS
- */
-package org.opends.server.backends.jeb;
-
-import static org.opends.server.schema.SchemaConstants.*;
-import static org.opends.server.util.ServerConstants.*;
-import static org.testng.Assert.*;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.forgerock.opendj.ldap.ByteString;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.api.Backend;
-import org.opends.server.backends.VerifyConfig;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
-import org.opends.server.util.StaticUtils;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import com.sleepycat.je.DatabaseEntry;
-import com.sleepycat.je.DatabaseException;
-import com.sleepycat.je.LockMode;
-import com.sleepycat.je.OperationStatus;
-import com.sleepycat.je.Transaction;
-
-@SuppressWarnings("javadoc")
-public class TestVerifyJob extends JebTestCase
-{
-
- private static final String EQUALITY_CASE_IGNORE = EMR_CASE_IGNORE_NAME;
- private static final String EQUALITY_TELEPHONE = EMR_TELEPHONE_NAME;
- private static final String ORDERING_CASE_IGNORE = OMR_CASE_IGNORE_NAME;
- private static final String SUBSTRING_CASE_IGNORE_IA5 = SMR_CASE_IGNORE_IA5_NAME;
-
- /** Root suffix for verify backend. */
- private static String suffix="dc=verify,dc=jeb";
- private static String vBranch="ou=verify tests," + suffix;
- private String backendID = "verifyRoot";
- private String numUsersLine="define numusers= #numEntries#";
- private DN[] baseDNs;
- private Backend<?> backend;
- private EntryContainer eContainer;
- private DN2ID dn2id;
- private ID2Entry id2entry;
- private Index id2child;
- private Index id2subtree;
- private Transaction txn;
-
- /** Some DNs needed mostly for DN2ID tests. */
- private String junkDN="cn=junk," + vBranch;
- private String junkDN1="cn=junk1," + vBranch;
- private String junkDN2="cn=junk2," + vBranch;
- private String junkDN3="cn=junk3," + vBranch;
- /** This DN has no parent. */
- private String noParentDN="cn=junk1,cn=junk22," + vBranch;
- /** Parent child combo for id2child/subtree type tests. */
- private String pDN="cn=junk222," + vBranch;
- private String cDN="cn=junk4,cn=junk222," + vBranch;
- /** Bad DN. */
- private String badDN="this is a bad DN";
- /** This index file should not exist. */
- private String badIndexName="badIndexName";
-
- @DataProvider(name = "indexes")
- public Object[][] indexes() {
- return new Object[][] {
- { "telephoneNumber"},
- {"givenName"},
- { "id2subtree"},
- {"id2children"},
- {"dn2id"}
- };
- }
-
- private static String[] template = new String[] {
- "define suffix="+suffix,
- "define maildomain=example.com",
- "define numusers= #numEntries#",
- "",
- "branch: [suffix]",
- "",
- "branch: " + vBranch,
- "subordinateTemplate: person:[numusers]",
- "",
- "template: person",
- "rdnAttr: uid",
- "objectClass: top",
- "objectClass: person",
- "objectClass: organizationalPerson",
- "objectClass: inetOrgPerson",
- "givenName: ABOVE LIMIT",
- "sn: <last>",
- "cn: {givenName} {sn}",
- "initials: {givenName:1}<random:chars:" +
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}",
- "employeeNumber: <sequential:0>",
- "uid: user.{employeeNumber}",
- "mail: {uid}@[maildomain]",
- "userPassword: password",
- "telephoneNumber: <random:telephone>",
- "homePhone: <random:telephone>",
- "pager: <random:telephone>",
- "mobile: <random:telephone>",
- "street: <random:numeric:5> <file:streets> Street",
- "l: <file:cities>",
- "st: <file:states>",
- "postalCode: <random:numeric:5>",
- "postalAddress: {cn}${street}${l}, {st} {postalCode}",
- "description: This is the description for {cn}.",
- ""};
-
- @BeforeClass
- public void setup() throws Exception {
- TestCaseUtils.startServer();
- TestCaseUtils.enableBackend(backendID);
- baseDNs = new DN[] {
- DN.valueOf(suffix)
- };
- }
-
- @AfterClass
- public void cleanUp() throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- TestCaseUtils.disableBackend(backendID);
- }
-
- /**
- * Performs a complete verify against a backend using the entries loaded in
- * the setup initializer.
- *
- * @throws Exception
- * if error count is not equal to 0.
- */
- @Test
- public void testCompleteVerifyJob() throws Exception {
- cleanAndLoad(9);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- backend = DirectoryServer.getBackend(backendID);
- assertEquals(backend.verifyBackend(verifyConfig), 0);
- }
-
- /**
- * Adds more than "entry limit" number of entries and runs clean
- * verify against two indexes.
- *
- * @throws Exception if error count is not equal to 0.
- */
- @Test
- public void testEntryLimitVerifyJob() throws Exception {
- cleanAndLoad(25);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- verifyConfig.addCleanIndex("telephoneNumber");
- verifyConfig.addCleanIndex("givenName");
- backend = DirectoryServer.getBackend(backendID);
- assertEquals(backend.verifyBackend(verifyConfig), 0);
- }
-
- /**
- * Runs clean verify jobs against a set of indexes (defined in
- * indexes array).
- * @param index An element of the indexes array.
- * @throws Exception if the error count is not equal to 0.
- */
-
- @Test(dataProvider = "indexes")
- public void testCleanVerifyJob(String index) throws Exception {
- cleanAndLoad(9);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- verifyConfig.addCleanIndex(index);
- backend = DirectoryServer.getBackend(backendID);
- assertEquals(backend.verifyBackend(verifyConfig), 0);
- }
-
- /*
- * Begin Clean index tests. These are tests that cursor through an index
- * file and validate it's keys and idlists against the id2entry database entries.
- * The complete index tests go the other way. They cursor the id2entry database
- * and validate each entry against the various index files.
- */
-
- /**
- * Runs clean verify against the dn2id index after adding
- * various errors in that index file.
- *
- * @throws Exception if the error count is not equal to 5.
- */
- @Test
- public void testCleanDN2ID() throws Exception {
- preTest(3);
- eContainer.sharedLock.lock();
- try
- {
- //Add a junk DN and non-existent entry id to DN2ID index
- DN testDN=DN.valueOf(junkDN);
- EntryID id=new EntryID(45);
- assertTrue(dn2id.insert(txn, testDN, id));
- //Make two DN keys point at same entry.
- testDN=DN.valueOf(junkDN1);
- id=new EntryID(3);
- assertTrue(dn2id.insert(txn, testDN, id));
- //Add badDN key with bad entry id
- DatabaseEntry key = new DatabaseEntry(StaticUtils.getBytes(badDN));
- DatabaseEntry data = new EntryID(37).getDatabaseEntry();
- assertEquals(dn2id.put(txn, key, data), OperationStatus.SUCCESS);
- //Add DN key with malformed entryID
- key=new DatabaseEntry(StaticUtils.getBytes(junkDN2));
- data= new DatabaseEntry(new byte[3]);
- assertEquals(dn2id.put(txn, key, data), OperationStatus.SUCCESS);
- //Try to break JebFormat version
- addID2EntryReturnKey(junkDN3, 20, true);
- id=new EntryID(20);
- assertTrue(dn2id.insert(txn, DN.valueOf(junkDN3), id));
- performBECleanVerify("dn2id", 5);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs clean verify against the id2children index after adding
- * various errors in that index file.
- *
- * @throws Exception if the error count is not equal to 6.
- */
- @Test
- public void testCleanID2Children() throws Exception {
- preTest(3);
- eContainer.sharedLock.lock();
- try
- {
- //Add malformed key
- byte[] shortBytes = new byte[3];
- DatabaseEntry key= new DatabaseEntry(shortBytes);
- EntryIDSet idSet=new EntryIDSet();
- id2child.writeKey(txn, key, idSet);
- //Try to break JebFormat version of key entry
- key=addID2EntryReturnKey(junkDN, 4, true);
- idSet=new EntryIDSet(new byte[16], new byte[16]);
- id2child.writeKey(txn, key, idSet);
- //put invalid key -- no EntryID matches
- key= new EntryID(45).getDatabaseEntry();
- id2child.writeKey(txn, key, idSet);
- //invalid ids in id list
- key=addID2EntryReturnKey(junkDN1, 5, false);
- byte[] idBytes=new byte[24];
- //doesn't exist
- idBytes[3] = (byte)0xff;
- //not a child
- idBytes[15] = (byte)1;
- //bad jeb format
- idBytes[23] = (byte) 0x04;
- idSet = new EntryIDSet(null, idBytes);
- id2child.writeKey(txn, key, idSet);
- performBECleanVerify("id2children", 6);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs clean verify against the id2subtree index after adding
- * various errors in that index file.
- *
- * @throws Exception if the error count is not equal to 7.
- */
- @Test
- public void testCleanID2Subtree() throws Exception {
- preTest(4);
- eContainer.sharedLock.lock();
- try
- {
- //break key
- byte[] shortBytes = new byte[3];
- DatabaseEntry key= new DatabaseEntry(shortBytes);
- EntryIDSet idSet=new EntryIDSet();
- id2subtree.writeKey(txn, key, idSet);
- //put invalid ids into entry 3 idlist
- key= new EntryID(3).getDatabaseEntry();
- byte[] idBytes=new byte[16];
- //invalid id
- idBytes[3] = (byte)0xff;
- //non-subordinate
- idBytes[15] = (byte)1;
- idSet = new EntryIDSet(null, idBytes);
- id2subtree.writeKey(txn, key, idSet);
- //Try to break JebFormat version of key entry
- key=addID2EntryReturnKey(junkDN, 4, true);
- idBytes[3]=(byte) 0x04;
- idBytes[15]=(byte)0x00;
- EntryIDSet idSet1 = new EntryIDSet(null, idBytes);
- id2subtree.writeKey(txn, key, idSet1);
- //put invalid key -- no EntryID matches
- key= new EntryID(45).getDatabaseEntry();
- idSet = new EntryIDSet(null, idBytes);
- id2subtree.writeKey(txn, key, idSet);
- performBECleanVerify("id2subtree", 7);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs clean verify against the telephoneNumber.equality index
- * after adding various errors in that index file.
- *
- * @throws Exception if the error count is not equal to 4.
- */
- @Test
- public void testCleanAttrIndex() throws Exception {
- String phoneType="telephonenumber";
- preTest(3);
- eContainer.sharedLock.lock();
- try
- {
- AttributeType attributeType = DirectoryServer.getAttributeTypeOrNull(phoneType);
- Index index = eContainer.getAttributeIndex(attributeType).getIndex(EQUALITY_TELEPHONE);
- //Add entry with bad JEB format Version
- addID2EntryReturnKey(junkDN, 4, true);
- //Add phone number with various bad id list entryIDs
- byte[] subBytes = StaticUtils.getBytes("0009999999");
- DatabaseEntry key= new DatabaseEntry(subBytes);
- byte[] dataBytes=new byte[32];
- //put duplicate ids in list
- dataBytes[7] = (byte)1;
- dataBytes[15] = (byte)1;
- //put id that doesn't exist
- dataBytes[23] = (byte)0xff;
- //point to bad entry added above
- dataBytes[31] = (byte) 0x04;
- DatabaseEntry data= new DatabaseEntry(dataBytes);
- OperationStatus status = index.put(txn, key, data);
- assertEquals(status, OperationStatus.SUCCESS);
- //really 5 errors, but duplicate reference doesn't increment error
- //count for some reason
- performBECleanVerify(phoneType, 4);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs clean verify against the testvlvindex VLV index
- * after adding various errors to each of these index files.
- * @throws Exception if the error count is not equal to 6.
- */
- @Test
- public void testCleanVLV() throws Exception {
- String indexName = "testvlvindex";
- preTest(4);
- eContainer.sharedLock.lock();
- try
- {
- VLVIndex vlvIndex = eContainer.getVLVIndex(indexName);
- AttributeType[] types = vlvIndex.getSortTypes();
-
- // Add an incorrectly ordered values.
- SortValuesSet svs =
- vlvIndex.getSortValuesSet(null, 0, new ByteString[3], new AttributeType[3]);
- long id = svs.getEntryIDs()[0];
- Entry entry = eContainer.getID2Entry().get(null, new EntryID(id), LockMode.DEFAULT);
-
- SortValuesSet svs2 = svs.split(2);
- svs2.add(id, vlvIndex.getSortValues(entry), types);
-
- // Add an invalid ID
- svs2.add(1000, vlvIndex.getSortValues(entry), types);
-
- // Muck up the values of another ID
- id = svs.getEntryIDs()[0];
- entry = eContainer.getID2Entry().get(null, new EntryID(id), LockMode.DEFAULT);
- ByteString[] values = vlvIndex.getSortValues(entry);
- ByteString[] badValues = new ByteString[values.length];
- System.arraycopy(values, 1, badValues, 0, values.length - 1);
- badValues[badValues.length-1] = values[0];
- remove(svs, id, values);
- svs.add(id, badValues, types);
-
- putSortValuesSet(vlvIndex, svs);
- putSortValuesSet(vlvIndex, svs2);
- performBECleanVerify("vlv." + indexName, 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
-
- }
-
-
- /*
- * Begin complete verify index tests. As described above, these are
- * tests that cursor through the id2entry database and validate
- * each entry against the various index files.
- *
- */
-
- /**
- * Runs complete verify against the telephoneNumber index
- * after adding various errors in the id2entry file.
- *
- * @throws Exception if the error count is not equal to 3.
- */
- @Test
- public void testVerifyID2Entry() throws Exception {
- preTest(3);
- eContainer.sharedLock.lock();
- try
- {
- //Add entry with short id
- byte[] shortBytes = new byte[3];
- DatabaseEntry key= new DatabaseEntry(shortBytes);
- Entry testEntry = buildEntry(junkDN);
- DataConfig dataConfig = new DataConfig(false, false, null);
- ByteString entryBytes = ID2Entry.entryToDatabase(testEntry, dataConfig);
- DatabaseEntry data= new DatabaseEntry(entryBytes.toByteArray());
- assertEquals(id2entry.put(txn, key, data), OperationStatus.SUCCESS);
-
- // add entry with random bytes
- DatabaseEntry key1= new EntryID(4).getDatabaseEntry();
- byte []eBytes = new byte[459];
- for(int i=0;i<459;i++) {
- eBytes[i]=(byte) (i*2);
- }
- //set version correctly
- eBytes[0]=0x01;
- DatabaseEntry data1= new DatabaseEntry(eBytes);
- assertEquals(id2entry.put(txn, key1, data1), OperationStatus.SUCCESS);
- performBECompleteVerify("telephoneNumber", 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- *
- * Runs complete verify against the dn2id index
- * after adding various errors in the dn2id file.
- *
- * @throws Exception if the error count is not equal to 3.
- */
- @Test
- public void testVerifyDN2ID() throws Exception {
- preTest(9);
- eContainer.sharedLock.lock();
- try
- {
- //add entry but no corresponding dn2id key
- addID2EntryReturnKey(junkDN, 10, false);
- //entry has dn2id key but its entryID -- don't need key
- addID2EntryReturnKey(junkDN1, 11, false);
- //insert key with bad entry id (45 instead of 10)
- DN testDN=DN.valueOf(junkDN1);
- EntryID id=new EntryID(45);
- assertTrue(dn2id.insert(txn, testDN, id));
- //entry has no parent in dn2id
- addID2EntryReturnKey(noParentDN, 12, false);
- //add the key/id
- testDN=DN.valueOf(noParentDN);
- id=new EntryID(12);
- assertTrue(dn2id.insert(txn, testDN, id));
- performBECompleteVerify("dn2id", 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- *
- * Runs complete verify against the id2children index
- * after adding various errors in the id2children file.
- *
- * @throws Exception if the error count is not equal to 3.
- */
- @Test
- public void testVerifyID2Children() throws Exception {
- preTest(9);
- eContainer.sharedLock.lock();
- try
- {
- //Add dn with no parent
- DatabaseEntry key=addID2EntryReturnKey(noParentDN, 10, false);
- byte[] idBytes=new byte[16];
- idBytes[7]=(byte) 0x0A;
- EntryIDSet idSet = new EntryIDSet(null, idBytes);
- id2child.writeKey(txn, key, idSet);
- //Add child entry - don't worry about key
- addID2EntryReturnKey(cDN, 11, false);
- //Add its parent entry -- need the key
- DatabaseEntry keyp=addID2EntryReturnKey(pDN, 12, false);
- //add parent key/IDSet with bad IDset id
- byte[] idBytesp=new byte[16];
- idBytesp[7]=(byte) 0xFF;
- EntryIDSet idSetp = new EntryIDSet(null, idBytesp);
- id2child.writeKey(txn, keyp, idSetp);
- performBECompleteVerify("id2children", 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- *
- * Runs complete verify against the id2children index
- * after adding various errors in the id2children file.
- * This is a second test because the key needed to have
- * null idlist. This test is really just for coverage and
- * should have a 0 error count.
- *
- * @throws Exception if the error count is not equal to 0.
- */
- @Test
- public void testVerifyID2Children1() throws Exception {
- preTest(2);
- eContainer.sharedLock.lock();
- try
- {
- //Add child entry - don't worry about key
- addID2EntryReturnKey(pDN, 10, false);
- //add parent key/IDSet with null keyset
- EntryIDSet idSetp=new EntryIDSet();
- DatabaseEntry key= new EntryID(2).getDatabaseEntry();
- id2child.writeKey(txn, key, idSetp);
- performBECompleteVerify("id2children", 0);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- *
- * Runs complete verify against the id2subtree index
- * after adding various errors in the id2subtree file.
- *
- * @throws Exception if the error count is not equal to 3.
- */
- @Test
- public void testVerifyID2Subtree() throws Exception {
- preTest(2);
- eContainer.sharedLock.lock();
- try
- {
- //Add entry with no parent
- addID2EntryReturnKey(noParentDN, 3, false);
- performBECompleteVerify("id2subtree", 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- *
- * Runs complete verify against the id2subtree index
- * after adding various errors in the id2subtree file.
- * This is a second test because the key needed to have
- * null idlist.
- *
- * @throws Exception if the error count is not equal to 1.
- */
- @Test
- public void testVerifyID2Subtree1() throws Exception {
- preTest(2);
- eContainer.sharedLock.lock();
- try
- {
- //Add child entry - don't worry about key
- addID2EntryReturnKey(pDN, 3, false);
- //add parent key/IDSet with null keyset
- EntryIDSet idSet=new EntryIDSet();
- DatabaseEntry key= new EntryID(2).getDatabaseEntry();
- id2subtree.writeKey(txn, key, idSet);
- performBECompleteVerify("id2subtree", 1);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs complete verify against the mail indexes
- * (equality, presence, substring, ordering)
- * after adding various errors to each of these index files.
- * @throws Exception if the error count is not equal to 6.
- */
- @Test
- public void testVerifyAttribute() throws Exception {
- String mailType="mail";
- preTest(4);
- eContainer.sharedLock.lock();
- try
- {
- AttributeType attributeType = DirectoryServer.getAttributeTypeOrNull(mailType);
- //Get db handles to each index.
- AttributeIndex attributeIndex = eContainer.getAttributeIndex(attributeType);
- Index eqIndex = attributeIndex.getIndex(EQUALITY_CASE_IGNORE);
- Index presIndex = attributeIndex.getIndex("presence");
- Index subIndex = attributeIndex.getIndex(SUBSTRING_CASE_IGNORE_IA5 + ":6");
- // Ordering is processed by equality since OPENDJ-1864
- assertNull(attributeIndex.getIndex(ORDERING_CASE_IGNORE));
-
- //Add invalid idlist ids to both equality and ordering indexes.
- DatabaseEntry key=
- new DatabaseEntry(StaticUtils.getBytes("user.0@example.com"));
- byte[] dataBytes=new byte[16];
- //put duplicate ids in list
- dataBytes[7] = (byte)0xff;
- dataBytes[15] = (byte)0xfe;
- DatabaseEntry data= new DatabaseEntry(dataBytes);
- OperationStatus status = eqIndex.put(txn, key, data);
- assertEquals(status, OperationStatus.SUCCESS);
- //Add null idlist to equality index.
- key = new DatabaseEntry(StaticUtils.getBytes("user.1@example.com"));
- data= new DatabaseEntry(new EntryIDSet().toDatabase());
- status = eqIndex.put(txn, key, data);
- assertEquals(status, OperationStatus.SUCCESS);
- //Add invalid idlist ids to presence index.
- key = new DatabaseEntry(StaticUtils.getBytes("+"));
- data = new DatabaseEntry(dataBytes);
- status = presIndex.put(txn, key, data);
- assertEquals(status, OperationStatus.SUCCESS);
- //Add invalid idlist ids to substring index.
- key = new DatabaseEntry(StaticUtils.getBytes("@examp"));
- data = new DatabaseEntry(dataBytes);
- status = subIndex.put(txn, key, data);
- assertEquals(status, OperationStatus.SUCCESS);
- performBECompleteVerify(mailType, 5);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- /**
- * Runs complete verify against the testvlvindex VLV index
- * after adding various errors to each of these index files.
- * @throws Exception if the error count is not equal to 6.
- */
- @Test
- public void testVerifyVLV() throws Exception {
- String indexName = "testvlvindex";
- preTest(4);
- eContainer.sharedLock.lock();
- try
- {
- VLVIndex vlvIndex = eContainer.getVLVIndex(indexName);
- AttributeType[] types = vlvIndex.getSortTypes();
-
- // Remove an ID
- SortValuesSet svs = vlvIndex.getSortValuesSet(null, 0, new ByteString[3], types);
- long id = svs.getEntryIDs()[0];
- Entry entry = eContainer.getID2Entry().get(null, new EntryID(id), LockMode.DEFAULT);
- remove(svs, id, vlvIndex.getSortValues(entry));
-
- // Add an incorrectly ordered values.
- SortValuesSet svs2 = svs.split(2);
- svs2.add(1000, vlvIndex.getSortValues(entry), types);
-
- // Muck up the values of another ID
- id = svs.getEntryIDs()[0];
- entry = eContainer.getID2Entry().get(null, new EntryID(id), LockMode.DEFAULT);
- ByteString[] values = vlvIndex.getSortValues(entry);
- ByteString[] badValues = new ByteString[values.length];
- System.arraycopy(values, 1, badValues, 0, values.length - 1);
- badValues[badValues.length-1] = values[0];
- remove(svs, id, values);
- svs.add(id, badValues, types);
-
- putSortValuesSet(vlvIndex, svs);
- putSortValuesSet(vlvIndex, svs2);
- performBECompleteVerify("vlv." + indexName, 3);
- }
- finally
- {
- eContainer.sharedLock.unlock();
- }
- }
-
- private void remove(SortValuesSet svs, long id, ByteString[] values) throws DirectoryException
- {
- svs.remove(new SortValues(new EntryID(id), values, new SortOrder()));
- }
-
- /**
- * Put a sort values set in this VLV index.
- *
- * @param txn
- * The transaction to use when retrieving the set or NULL if it is
- * not required.
- * @param sortValuesSet
- * The SortValuesSet to put.
- * @return True if the sortValuesSet was put successfully or False otherwise.
- * @throws JebException
- * If an error occurs during an operation on a JE database.
- * @throws DatabaseException
- * If an error occurs during an operation on a JE database.
- * @throws DirectoryException
- * If a Directory Server error occurs.
- */
- private void putSortValuesSet(VLVIndex vlvIndex, SortValuesSet sortValuesSet) throws JebException, DirectoryException
- {
- DatabaseEntry key = new DatabaseEntry(sortValuesSet.getKeyBytes());
- DatabaseEntry data = new DatabaseEntry(sortValuesSet.toDatabase());
- vlvIndex.put(null, key, data);
- }
-
- /* Various tests not either clean or complete */
-
-
- /**
- * Try to verify a non-indexed attribute.
- * @throws Exception if error count is not equal to 0.
- */
- @Test(expectedExceptions=Exception.class)
- public void testVerifyNotIndexed() throws Exception {
- cleanAndLoad(2);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- verifyConfig.addCleanIndex("userPassword");
- backend = DirectoryServer.getBackend(backendID);
- assertEquals(backend.verifyBackend(verifyConfig), 0);
- }
-
- /**
- * Try to verify an nonexistent attribute.
- * @throws Exception if verify backend fails.
- */
- @Test(expectedExceptions=Exception.class)
- public void testInvalidIndex() throws Exception {
- cleanAndLoad(2);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- verifyConfig.addCleanIndex(badIndexName);
- backend = DirectoryServer.getBackend(backendID);
- backend.verifyBackend(verifyConfig);
- }
-
- /* end tests */
-
- /**
- * Adds an entry to the id2entry database with a dn and id passed into the
- * method. Optional flag to set the Jeb version byte for those types of tests.
- * @param dn the dn string to put in the entry.
- * @param id to use as the id2entry key,
- * @param trashFormat true if first byte should be changed to invalid value.
- * @return Database entry key of the entry.
- * @throws Exception if the entry is not added to the id2entry database.
- */
- private DatabaseEntry addID2EntryReturnKey(String dn, long id, boolean trashFormat)
- throws Exception {
- DatabaseEntry key= new EntryID(id).getDatabaseEntry();
- Entry testEntry = buildEntry(dn);
- DataConfig dataConfig = new DataConfig(false, false, null);
- byte []entryBytes = ID2Entry.entryToDatabase(testEntry, dataConfig).toByteArray();
- if(trashFormat)
- {
- entryBytes[0] = 0x67;
- }
- DatabaseEntry data= new DatabaseEntry(entryBytes);
- assertEquals(id2entry.put(txn, key, data), OperationStatus.SUCCESS);
- return key;
- }
-
- /**
- * Wrapper to do a clean verify.
- * @param indexToDo index file to run verify against.
- * @param expectedErrors number of errors expected for this test.
- * @throws Exception if the verify fails.
- */
- private void performBECleanVerify(String indexToDo,
- int expectedErrors) throws Exception {
- performBEVerify(indexToDo, expectedErrors, true);
- }
-
- /**
- * Wrapper to do a complete verify.
- * @param indexToDo index file to run verify against.
- * @param expectedErrors number of errors expected for this test.
- * @throws Exception if the verify fails.
- */
- private void performBECompleteVerify(String indexToDo,
- int expectedErrors) throws Exception {
- performBEVerify(indexToDo, expectedErrors, false);
- }
-
- /**
- * Performs either a clean or complete verify depending on
- * flag passed in.
- *
- * @param indexToDo index file to run verify against.
- * @param expectedErrors number of errors expected for this test.
- * @param clean do clean verify if true.
- * @throws Exception if the verify fails.
- */
- private void performBEVerify(String indexToDo,
- int expectedErrors, boolean clean) throws Exception {
- EntryContainer.transactionCommit(txn);
- VerifyConfig verifyConfig = new VerifyConfig();
- verifyConfig.setBaseDN(baseDNs[0]);
- if(!clean)
- {
- verifyConfig.addCompleteIndex(indexToDo);
- }
- else
- {
- verifyConfig.addCleanIndex(indexToDo);
- }
- assertEquals(backend.verifyBackend(verifyConfig), expectedErrors);
- }
-
-
- /**
- * Does a pretest setup. Creates some number of entries, gets
- * backend, rootcontainer, entryContainer objects, as well as
- * various index objects.
- * Also starts a transaction.
- * @param numEntries number of entries to add to the verify backend.
- * @throws Exception if entries cannot be loaded.
- */
- private void preTest(int numEntries) throws Exception {
- cleanAndLoad(numEntries);
- backend = DirectoryServer.getBackend(backendID);
- RootContainer rContainer = ((BackendImpl) backend).getRootContainer();
- eContainer= rContainer.getEntryContainer(DN.valueOf(suffix));
- id2child=eContainer.getID2Children();
- id2entry=eContainer.getID2Entry();
- id2subtree=eContainer.getID2Subtree();
- dn2id=eContainer.getDN2ID();
- txn = eContainer.beginTransaction();
- }
-
- /**
- * Cleans verify backend and loads some number of entries.
- * @param numEntries number of entries to load into the backend.
- * @throws Exception if the entries are not loaded or created.
- */
- private void cleanAndLoad(int numEntries) throws Exception {
- TestCaseUtils.clearJEBackend(backendID);
- template[2]=numUsersLine;
- template[2]=
- template[2].replaceAll("#numEntries#", String.valueOf(numEntries));
- createLoadEntries(template, numEntries);
- }
-
- /**
- * Builds an entry.
- *
- * @param dn to put into the entry.
- * @return a new entry.
- * @throws DirectoryException if the entry cannot be created.
- */
- private Entry buildEntry(String dn) throws DirectoryException {
- DN entryDN = DN.valueOf(dn);
- HashMap<ObjectClass, String> ocs = new HashMap<>(2);
- ObjectClass topOC = DirectoryServer.getObjectClass(OC_TOP);
- if (topOC == null) {
- topOC = DirectoryServer.getDefaultObjectClass(OC_TOP);
- }
- ocs.put(topOC, OC_TOP);
- ObjectClass extensibleObjectOC = DirectoryServer
- .getObjectClass(OC_EXTENSIBLE_OBJECT);
- if (extensibleObjectOC == null) {
- extensibleObjectOC = DirectoryServer
- .getDefaultObjectClass(OC_EXTENSIBLE_OBJECT);
- }
- ocs.put(extensibleObjectOC, OC_EXTENSIBLE_OBJECT);
- return new Entry(entryDN, ocs,
- new LinkedHashMap<AttributeType, List<Attribute>>(0),
- new HashMap<AttributeType, List<Attribute>>(0));
- }
-}
--
Gitblit v1.10.0