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

Jean-Noël Rouvignac
06.14.2016 5e0a551935151242e4308053617c2f487a60d5f0
Partial OPENDJ-3106 Migrate Entry

Entry.java:
getAllAttributes(String) now returns Iterable<Attribute>.
24 files modified
390 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java 28 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java 6 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java 6 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java 10 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java 30 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java 10 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/ModifyOperationTestCase.java 36 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/SearchOperationTestCase.java 37 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/SubentryManagerTestCase.java 22 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/extensions/PasswordExpirationTimeVirtualAttributeProviderTestCase.java 16 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java 34 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/UpdateOperationTest.java 24 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java 22 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java 12 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/schema/LDAPSyntaxTest.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/tools/makeldif/MakeLDIFTestCase.java 19 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
@@ -63,6 +63,7 @@
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.server.config.server.TrustStoreBackendCfg;
import org.forgerock.util.Reject;
import org.opends.server.api.Backend;
@@ -86,7 +87,6 @@
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.LDIFImportResult;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.opends.server.types.RestoreConfig;
import org.opends.server.types.SearchFilter;
import org.opends.server.util.CertificateManager;
@@ -1077,16 +1077,16 @@
      }
      else
      {
        List<Attribute> certAttrs = entry.getAllAttributes(
             ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE);
        if (certAttrs.isEmpty())
        Iterator<Attribute> certAttrs = entry.getAllAttributes(ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE).iterator();
        if (!certAttrs.hasNext())
        {
          LocalizableMessage message =
               ERR_TRUSTSTORE_ENTRY_MISSING_CERT_ATTR.get(entryDN, ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE);
          throw new DirectoryException(
               DirectoryServer.getServerErrorResultCode(), message);
        }
        if (certAttrs.size() != 1)
        Attribute certAttr = certAttrs.next();
        if (certAttrs.hasNext())
        {
          LocalizableMessage message =
               ERR_TRUSTSTORE_ENTRY_HAS_MULTIPLE_CERT_ATTRS.get(entryDN, ATTR_CRYPTO_PUBLIC_KEY_CERTIFICATE);
@@ -1094,7 +1094,6 @@
               DirectoryServer.getServerErrorResultCode(), message);
        }
        Attribute certAttr = certAttrs.get(0);
        Iterator<ByteString> i = certAttr.iterator();
        if (!i.hasNext())
opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java
@@ -311,8 +311,8 @@
  private String getAttributeValue(String attributeName, boolean isRequired)
          throws InitializationException
  {
    List<Attribute> attrList = taskEntry.getAllAttributes(attributeName);
    if (attrList.isEmpty())
    Iterator<Attribute> attrList = taskEntry.getAllAttributes(attributeName).iterator();
    if (!attrList.hasNext())
    {
      if (isRequired)
      {
@@ -321,13 +321,13 @@
      return null;
    }
    if (attrList.size() > 1)
    final Iterator<ByteString> values = attrList.next().iterator();
    if (attrList.hasNext())
    {
      throw new InitializationException(ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(attributeName, taskEntry.getName()));
    }
    Iterator<ByteString> iterator = attrList.get(0).iterator();
    if (! iterator.hasNext())
    if (!values.hasNext())
    {
      if (isRequired)
      {
@@ -336,8 +336,8 @@
      return null;
    }
    ByteString value = iterator.next();
    if (iterator.hasNext())
    ByteString value = values.next();
    if (values.hasNext())
    {
      throw new InitializationException(ERR_TASK_MULTIPLE_VALUES_FOR_ATTR.get(attributeName, taskEntry.getName()));
    }
@@ -359,21 +359,21 @@
   */
  private LinkedList<String> getAttributeValues(String attributeName) throws InitializationException
  {
    LinkedList<String> valueStrings = new LinkedList<>();
    List<Attribute> attrList = taskEntry.getAllAttributes(attributeName);
    if (attrList.isEmpty())
    final LinkedList<String> valueStrings = new LinkedList<>();
    final Iterator<Attribute> attrList = taskEntry.getAllAttributes(attributeName).iterator();
    if (!attrList.hasNext())
    {
      return valueStrings;
    }
    if (attrList.size() > 1)
    final Iterator<ByteString> values = attrList.next().iterator();
    if (attrList.hasNext())
    {
      throw new InitializationException(ERR_TASK_MULTIPLE_ATTRS_FOR_TYPE.get(attributeName, taskEntry.getName()));
    }
    Iterator<ByteString> iterator = attrList.get(0).iterator();
    while (iterator.hasNext())
    while (values.hasNext())
    {
      valueStrings.add(iterator.next().toString());
      valueStrings.add(values.next().toString());
    }
    return valueStrings;
  }
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java
@@ -19,6 +19,7 @@
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.replication.plugin.HistAttrModificationKey.*;
import static org.opends.server.util.CollectionUtils.*;
import java.util.HashMap;
import java.util.Iterator;
@@ -515,11 +516,11 @@
  public static EntryHistorical newInstanceFromEntry(Entry entry)
  {
    // Read the DB historical attribute from the entry
    List<Attribute> histAttrWithOptionsFromEntry = getHistoricalAttr(entry);
    Iterable<Attribute> histAttrWithOptionsFromEntry = getHistoricalAttr(entry);
    // Now we'll build the Historical object we want to construct
    final EntryHistorical newHistorical = new EntryHistorical();
    if (histAttrWithOptionsFromEntry.isEmpty())
    if (isEmpty(histAttrWithOptionsFromEntry))
    {
      // No historical attribute in the entry, return empty object
      return newHistorical;
@@ -660,7 +661,7 @@
   *          Several values on the list if several options for this attribute.
   *          Null if not present.
   */
  public static List<Attribute> getHistoricalAttr(Entry entry)
  public static Iterable<Attribute> getHistoricalAttr(Entry entry)
  {
    return entry.getAllAttributes(HISTORICAL_ATTRIBUTE_NAME);
  }
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -3287,10 +3287,10 @@
      SearchResultEntry resultEntry = result.get(0);
      if (resultEntry != null)
      {
        List<Attribute> attrs = resultEntry.getAllAttributes(REPLICATION_GENERATION_ID);
        if (!attrs.isEmpty())
        Iterator<Attribute> attrs = resultEntry.getAllAttributes(REPLICATION_GENERATION_ID).iterator();
        if (attrs.hasNext())
        {
          Attribute attr = attrs.get(0);
          Attribute attr = attrs.next();
          if (attr.size()>1)
          {
            String errorMsg = "#Values=" + attr.size() + " Must be exactly 1 in entry " + resultEntry.toLDIFString();
opendj-server-legacy/src/main/java/org/opends/server/tools/BackendToolUtils.java
@@ -17,6 +17,7 @@
package org.opends.server.tools;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -118,10 +119,10 @@
   */
  public static String getStringSingleValuedAttribute(Entry entry, String attrName)
  {
    List<Attribute> attributes = entry.getAllAttributes(attrName);
    if (!attributes.isEmpty())
    Iterator<Attribute> attributes = entry.getAllAttributes(attrName).iterator();
    if (attributes.hasNext())
    {
      Attribute attribute = attributes.get(0);
      Attribute attribute = attributes.next();
      for (ByteString byteString : attribute)
      {
        return byteString.toString();
@@ -134,10 +135,10 @@
  {
    try
    {
      List<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN);
      if (!attributes.isEmpty())
      Iterator<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN).iterator();
      if (attributes.hasNext())
      {
        Attribute attribute = attributes.get(0);
        Attribute attribute = attributes.next();
        List<DN> dns = new ArrayList<>();
        for (ByteString byteString : attribute)
        {
opendj-server-legacy/src/main/java/org/opends/server/tools/ListBackends.java
@@ -418,10 +418,10 @@
      Set<DN> baseDNs = new TreeSet<>();
      try
      {
        List<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN);
        if (!attributes.isEmpty())
        Iterator<Attribute> attributes = configEntry.getAllAttributes(ATTR_BACKEND_BASE_DN).iterator();
        if (attributes.hasNext())
        {
          Attribute attribute = attributes.get(0);
          Attribute attribute = attributes.next();
          for (ByteString byteString : attribute)
          {
            baseDNs.add(DN.valueOf(byteString.toString()));
opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
@@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -416,9 +417,12 @@
  }
  private String getSingleStringValue(Entry entry, String attrName) {
    List<Attribute> attrList = entry.getAllAttributes(attrName);
    if (attrList.size() == 1) {
      Attribute attr = attrList.get(0);
    Iterator<Attribute> attrs = entry.getAllAttributes(attrName).iterator();
    if (attrs.hasNext()) {
      Attribute attr = attrs.next();
      if (attrs.hasNext()) {
        return "";
      }
      if (!attr.isEmpty()) {
        return attr.iterator().next().toString();
      }
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -734,7 +734,7 @@
   *          attribute type, or an empty list if the specified
   *          attribute type is not present in this entry.
   */
  public List<Attribute> getAllAttributes(String nameOrOID)
  public Iterable<Attribute> getAllAttributes(String nameOrOID)
  {
    for (AttributeType attr : userAttributes.keySet())
    {
@@ -826,8 +826,9 @@
  public AttributeParser parseAttribute(String attributeDescription)
      throws LocalizedIllegalArgumentException, NullPointerException
  {
    final List<Attribute> attribute = getAllAttributes(attributeDescription);
    return AttributeParser.parseAttribute(!attribute.isEmpty() ? attribute.get(0) : null);
    final Iterable<Attribute> attribute = getAllAttributes(attributeDescription);
    Iterator<Attribute> it = attribute.iterator();
    return AttributeParser.parseAttribute(it.hasNext() ? it.next() : null);
  }
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java
@@ -16,8 +16,22 @@
 */
package org.opends.server.authorization.dseecompat;
import java.io.*;
import java.util.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.naming.NamingException;
import javax.naming.NoPermissionException;
@@ -26,6 +40,7 @@
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.DirectoryServerTestCase;
@@ -39,7 +54,6 @@
import org.opends.server.tools.LDAPPasswordModify;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.Attribute;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
import org.testng.Assert;
@@ -48,10 +62,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
@SuppressWarnings("javadoc")
@Test(groups = {"precommit", "dseecompat"}, sequential = true)
public abstract class  AciTestCase extends DirectoryServerTestCase {
@@ -69,12 +79,12 @@
    // Save Global ACI.
    Entry e = DirectoryServer.getEntry(DN.valueOf(ACCESS_HANDLER_DN));
    List<Attribute> attrs = e.getAllAttributes(ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI);
    if (!attrs.isEmpty())
    Iterator<Attribute> attrs = e.getAllAttributes(ConfigConstants.ATTR_AUTHZ_GLOBAL_ACI).iterator();
    if (attrs.hasNext())
    {
      Reporter.log("Saved global ACI attribute");
      globalACIAttribute = attrs.iterator().next();
      globalACIAttribute = attrs.next();
    }
  }
opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java
@@ -36,6 +36,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -943,7 +944,8 @@
  private String readCookieFromNthEntry(List<SearchResultEntry> entries, int i)
  {
    SearchResultEntry entry = entries.get(i);
    return entry.getAllAttributes("changelogcookie").get(0).iterator().next().toString();
    Attribute attr = entry.getAllAttributes("changelogcookie").iterator().next();
    return attr.iterator().next().toString();
  }
  private String assertEntriesContainsCSNsAndReadLastCookie(String test, List<SearchResultEntry> entries,
@@ -1479,12 +1481,12 @@
  private static String getAttributeValue(Entry entry, String attrName)
  {
    List<Attribute> attrs = entry.getAllAttributes(attrName);
    if (attrs.isEmpty())
    Iterator<Attribute> attrs = entry.getAllAttributes(attrName).iterator();
    if (!attrs.hasNext())
    {
      return null;
    }
    Attribute attr = attrs.iterator().next();
    Attribute attr = attrs.next();
    ByteString value = attr.iterator().next();
    return value.toString();
  }
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
@@ -793,7 +793,7 @@
    retrieveCompletedOperationElements(addOperation);
    Entry e = DirectoryServer.getEntry(DN.valueOf("ou=People,o=test"));
    List<Attribute> attrList = e.getAllAttributes("ou");
    Iterable<Attribute> attrList = e.getAllAttributes("ou");
    assertThat(attrList).isNotEmpty();
  }
opendj-server-legacy/src/test/java/org/opends/server/core/ModifyOperationTestCase.java
@@ -3242,10 +3242,11 @@
    // @formatter:on
    e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test"));
    List<Attribute> attrList = e.getAllAttributes("userpassword");
    assertThat(attrList).hasSize(1);
    assertFalse(attrList.get(0).getAttributeDescription().hasOptions());
    assertThat(attrList.get(0)).hasSize(1);
    Iterable<Attribute> attrs = e.getAllAttributes("userpassword");
    assertThat(attrs).hasSize(1);
    Attribute attr = attrs.iterator().next();
    assertFalse(attr.getAttributeDescription().hasOptions());
    assertThat(attr).hasSize(1);
  }
  /**
@@ -3282,10 +3283,11 @@
    // @formatter:on
    e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test"));
    List<Attribute> attrList = e.getAllAttributes("userpassword");
    assertThat(attrList).hasSize(1);
    assertFalse(attrList.get(0).getAttributeDescription().hasOptions());
    assertThat(attrList.get(0)).hasSize(1);
    Iterable<Attribute> attrs = e.getAllAttributes("userpassword");
    assertThat(attrs).hasSize(1);
    Attribute attr = attrs.iterator().next();
    assertFalse(attr.getAttributeDescription().hasOptions());
    assertThat(attr).hasSize(1);
  }
  /**
@@ -3318,10 +3320,11 @@
    // @formatter:on
    Entry e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test"));
    List<Attribute> attrList = e.getAllAttributes("userpassword");
    assertThat(attrList).hasSize(1);
    assertFalse(attrList.get(0).getAttributeDescription().hasOptions());
    assertThat(attrList.get(0)).hasSize(1);
    Iterable<Attribute> attrs = e.getAllAttributes("userpassword");
    assertThat(attrs).hasSize(1);
    Attribute attr = attrs.iterator().next();
    assertFalse(attr.getAttributeDescription().hasOptions());
    assertThat(attr).hasSize(1);
  }
  /**
@@ -3354,10 +3357,11 @@
    // @formatter:on
    Entry e = DirectoryServer.getEntry(DN.valueOf("cn=Test User,o=test"));
    List<Attribute> attrList = e.getAllAttributes("userpassword");
    assertThat(attrList).hasSize(1);
    assertFalse(attrList.get(0).getAttributeDescription().hasOptions());
    assertThat(attrList.get(0)).hasSize(1);
    Iterable<Attribute> attrs = e.getAllAttributes("userpassword");
    assertThat(attrs).hasSize(1);
    Attribute attr = attrs.iterator().next();
    assertFalse(attr.getAttributeDescription().hasOptions());
    assertThat(attr).hasSize(1);
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/core/SearchOperationTestCase.java
@@ -16,9 +16,17 @@
 */
package org.opends.server.core;
import static org.assertj.core.api.Assertions.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
@@ -63,13 +71,6 @@
import org.testng.annotations.DataProvider;
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.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@SuppressWarnings("javadoc")
public class SearchOperationTestCase extends OperationTestCase
{
@@ -980,18 +981,18 @@
  {
    for (String attrType : virtualAttrTypes)
    {
      List<Attribute> attrList = entry.getAllAttributes(attrType);
      Iterable<Attribute> attrs = entry.getAllAttributes(attrType);
      if (stripVirtualAttributes)
      {
        if (!attrList.isEmpty())
        if (!isEmpty(attrs))
        {
          messages.add("Unexpected virtual attribute: " + attrType);
        }
      }
      else if (filterType == AttributeFilterType.DEFAULT)
      {
        if (!attrList.isEmpty())
        if (!isEmpty(attrs))
        {
          messages.add("Unexpected operational attribute: " + attrType);
        }
@@ -999,20 +1000,21 @@
      else if ("ismemberof".equals(attrType))
      {
        // isMemberOf should never be returned as user is not in any groups.
        if (!attrList.isEmpty())
        if (!isEmpty(attrs))
        {
          messages.add("Unexpected isMemberOf attribute");
        }
      }
      else
      {
        if (attrList.isEmpty())
        Iterator<Attribute> attrsIt = attrs.iterator();
        if (!attrsIt.hasNext())
        {
          messages.add("Missing virtual attribute: " + attrType);
        }
        else
        {
          Attribute attr = attrList.get(0);
          Attribute attr = attrsIt.next();
          if (typesOnly)
          {
            if (!attr.isEmpty())
@@ -1037,24 +1039,25 @@
  {
    for (String attrType : realAttrTypes)
    {
      List<Attribute> attrList = entry.getAllAttributes(attrType);
      Iterable<Attribute> attrs = entry.getAllAttributes(attrType);
      if (stripRealAttributes)
      {
        if (!attrList.isEmpty())
        if (!isEmpty(attrs))
        {
          messages.add("Unexpected real attribute: " + attrType);
        }
      }
      else
      {
        if (attrList.isEmpty())
        Iterator<Attribute> attrsIt = attrs.iterator();
        if (!attrsIt.hasNext())
        {
          messages.add("Missing real attribute: " + attrType);
        }
        else
        {
          Attribute attr = attrList.get(0);
          Attribute attr = attrsIt.next();
          if (typesOnly)
          {
            if (!attr.isEmpty())
opendj-server-legacy/src/test/java/org/opends/server/core/SubentryManagerTestCase.java
@@ -17,6 +17,15 @@
package org.opends.server.core;
import static org.assertj.core.api.Assertions.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
import java.util.ArrayList;
import java.util.List;
@@ -44,15 +53,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@SuppressWarnings("javadoc")
public class SubentryManagerTestCase extends CoreTestCase
{
@@ -225,7 +225,7 @@
      Entry e = DirectoryServer.getEntry(DN.valueOf("uid=normal user,ou=people,o=test"));
      assertNotNull(e);
      List<Attribute> description = e.getAllAttributes("description");
      Iterable<Attribute> description = e.getAllAttributes("description");
      assertThat(description).isEmpty();
      // Collective user will inherit the collective description attribute.
@@ -234,7 +234,7 @@
      description = e.getAllAttributes("description");
      assertThat(description).hasSize(1);
      Attribute attribute = description.get(0);
      Attribute attribute = description.iterator().next();
      assertEquals(attribute.size(), 1);
      assertFalse(attribute.getAttributeDescription().hasOptions());
      assertTrue(attribute.contains(ByteString.valueOfUtf8("inherited description")));
opendj-server-legacy/src/test/java/org/opends/server/extensions/PasswordExpirationTimeVirtualAttributeProviderTestCase.java
@@ -16,9 +16,13 @@
 */
package org.opends.server.extensions;
import static org.assertj.core.api.Assertions.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
@@ -37,10 +41,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
@SuppressWarnings("javadoc")
public class PasswordExpirationTimeVirtualAttributeProviderTestCase
  extends ExtensionsTestCase
@@ -204,10 +204,10 @@
    SearchResultEntry entry = entries.get(0);
    assertNotNull(entry);
    List<Attribute> attrs = entry.getAllAttributes(attributeName);
    assertEquals(attrs.size(), 1);
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeName);
    assertThat(attrs).hasSize(1);
    Attribute attr = attrs.get(0);
    Attribute attr = attrs.iterator().next();
    assertNotNull(attr);
    Iterator<ByteString> it = attr.iterator();
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java
@@ -197,8 +197,7 @@
    List<SearchResultEntry> entries = searchOperation.getSearchEntries();
    SearchResultEntry e = entries.get(0);
    assertNotNull(e);
    List<Attribute> attrs = e.getAllAttributes("usercertificate");
    Attribute a = attrs.get(0);
    Attribute a = e.getAllAttributes("usercertificate").iterator().next();
    assertNotNull(a);
    assertThat(a.getAttributeDescription().getOptions()).contains("binary");
  }
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
@@ -16,6 +16,17 @@
 */
package org.opends.server.replication;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.opends.server.backends.task.TaskState.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -68,17 +79,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.opends.server.backends.task.TaskState.*;
import static org.opends.server.config.ConfigConstants.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
/** An abstract class that all Replication unit test should extend. */
@SuppressWarnings("javadoc")
@Test(groups = { "precommit", "replication" }, sequential = true)
@@ -524,9 +524,9 @@
      {
        final Entry newEntry = DirectoryServer.getEntry(dn);
        assertNotNull(newEntry);
        List<Attribute> attrList = newEntry.getAllAttributes(attrTypeStr);
        Assertions.assertThat(attrList).isNotEmpty();
        Attribute attr = attrList.get(0);
        Iterable<Attribute> attrs = newEntry.getAllAttributes(attrTypeStr);
        Assertions.assertThat(attrs).isNotEmpty();
        Attribute attr = attrs.iterator().next();
        boolean foundAttributeValue = attr.contains(ByteString.valueOfUtf8(valueString));
        assertEquals(foundAttributeValue, expectedAttributeValueFound, foundMsg);
        return null;
@@ -781,10 +781,10 @@
      {
        Entry newEntry = DirectoryServer.getEntry(dn);
        assertNotNull(newEntry);
        Attribute attribute = newEntry.getAllAttributes("entryuuid").get(0);
        String found = attribute.iterator().next().toString();
        Attribute attribute = newEntry.getAllAttributes("entryuuid").iterator().next();
        ByteString found = attribute.iterator().next();
        assertNotNull(found, "Entry: " + dn + " Could not be found.");
        return found;
        return found.toString();
      }
    });
  }
opendj-server-legacy/src/test/java/org/opends/server/replication/UpdateOperationTest.java
@@ -16,6 +16,17 @@
 */
package org.opends.server.replication;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.replication.plugin.LDAPReplicationDomain.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.List;
@@ -60,17 +71,6 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.replication.plugin.LDAPReplicationDomain.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
/**
 * Test synchronization of update operations on the directory server and through
 * the replication server broker interface.
@@ -1087,7 +1087,7 @@
   */
  private boolean assertConflictAttributeExists(Entry entry)
  {
    return !entry.getAllAttributes("ds-sync-confict").isEmpty();
    return !isEmpty(entry.getAllAttributes("ds-sync-confict"));
  }
  @DataProvider(name="assured")
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
@@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -1480,15 +1481,15 @@
        throw new Exception("Unknown assured type");
    }
    List<Attribute> attrs = entry.getAllAttributes(assuredAttr);
    if (attrs.isEmpty())
    Iterator<Attribute> attrs = entry.getAllAttributes(assuredAttr).iterator();
    if (!attrs.hasNext())
    {
      return Collections.emptyMap();
    }
    // Parse and store values
    Map<Integer,Integer> resultMap = new HashMap<>();
    for (ByteString val : attrs.get(0))
    for (ByteString val : attrs.next())
    {
      StringTokenizer strtok = new StringTokenizer(val.toString(), ":");
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/FractionalReplicationTest.java
@@ -139,12 +139,8 @@
    replServerPort = TestCaseUtils.findFreePort();
  }
  /**
   * Returns a bunch of single values for fractional-exclude configuration
   * attribute
   */
  @SuppressWarnings("unused")
  @DataProvider(name = "testExcludePrecommitProvider")
  /** Returns a bunch of single values for fractional-exclude configuration attribute. */
  @DataProvider
  private Object[][] testExcludePrecommitProvider()
  {
    return new Object[][]
@@ -753,9 +749,11 @@
   */
  private static void checkEntryAttributeValue(Entry entry, String attributeName, String attributeValue)
  {
    List<Attribute> attrs = entry.getAllAttributes(attributeName);
    assertThat(attrs).as("Was expecting attribute " + attributeName + "=" + attributeValue).hasSize(1);
    Attribute attr = attrs.get(0);
    Iterable<Attribute> attrs = entry.getAllAttributes(attributeName);
    assertThat(attrs)
        .as("Was expecting attribute " + attributeName + "=" + attributeValue)
        .hasSize(1);
    Attribute attr = attrs.iterator().next();
    Iterator<ByteString> attrValues = attr.iterator();
    assertTrue(attrValues.hasNext());
    ByteString attrValue = attrValues.next();
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
@@ -16,6 +16,15 @@
 */
package org.opends.server.replication.plugin;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
@@ -45,15 +54,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.ResultCode.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
/** Tests the Historical class. */
@SuppressWarnings("javadoc")
public class HistoricalTest extends ReplicationTestCase
@@ -172,8 +172,8 @@
    DN dn = DN.valueOf("uid=user.1," + TEST_ROOT_DN_STRING);
    Entry entry = DirectoryServer.getEntry(dn);
    List<Attribute> attrs = EntryHistorical.getHistoricalAttr(entry);
    Attribute before = attrs.get(0);
    Iterable<Attribute> attrs = EntryHistorical.getHistoricalAttr(entry);
    Attribute before = attrs.iterator().next();
    // Check that encoding and decoding preserves the history information.
    EntryHistorical hist = EntryHistorical.newInstanceFromEntry(entry);
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -648,7 +648,9 @@
    assertEquals(mod.getAttribute(), values3and4);
    // check that the entry now contains value1 and value2 and no other values.
    Attribute resultEntryAttr = entry.getAllAttributes(DESCRIPTION).get(0);
    Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION);
    assertThat(attrs).hasSize(1);
    Attribute resultEntryAttr = attrs.iterator().next();
    assertEquals(resultEntryAttr, values1and2);
    Attribute attr = buildSyncHist(DESCRIPTION,
@@ -1357,8 +1359,8 @@
    assertEquals(hist.encodeAndPurge(), attr);
    // The entry should have no value
    List<Attribute> attrs = entry.getAllAttributes(DESCRIPTION);
    assertEquals(attrs.get(0), Attributes.create(DESCRIPTION, "value2", "value3", "value4"));
    Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION);
    assertThat(attrs).containsOnly(Attributes.create(DESCRIPTION, "value2", "value3", "value4"));
  }
  /**
@@ -1404,8 +1406,8 @@
    assertEquals(hist.encodeAndPurge(), attr);
    // The entry should have no value
    List<Attribute> attrs = entry.getAllAttributes(DESCRIPTION);
    assertEquals(attrs.get(0), Attributes.create(DESCRIPTION, "value3", "value4"));
    Iterable<Attribute> attrs = entry.getAllAttributes(DESCRIPTION);
    assertThat(attrs).containsOnly(Attributes.create(DESCRIPTION, "value3", "value4"));
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/schema/LDAPSyntaxTest.java
@@ -16,6 +16,11 @@
 */
package org.opends.server.schema;
import static org.assertj.core.api.Assertions.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
import java.util.ArrayList;
import java.util.List;
@@ -35,11 +40,6 @@
import org.testng.annotations.DataProvider;
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.protocols.internal.Requests.*;
import static org.testng.Assert.*;
/** Test the LDAPSyntaxDescriptionSyntax. */
@RemoveOnceSDKSchemaIsUsed
@SuppressWarnings("javadoc")
@@ -215,7 +215,7 @@
      assertThat(entries).isNotEmpty();
      SearchResultEntry e = entries.get(0);
      assertNotNull(e);
      Attribute attr = e.getAllAttributes("ldapsyntaxes").get(0);
      Attribute attr = e.getAllAttributes("ldapsyntaxes").iterator().next();
      //There are other ways of doing it but we will extract the OID
      //from the attribute values and then check to see if our
opendj-server-legacy/src/test/java/org/opends/server/tools/makeldif/MakeLDIFTestCase.java
@@ -17,6 +17,10 @@
 */
package org.opends.server.tools.makeldif;
import static org.assertj.core.api.Assertions.*;
import static org.opends.messages.ToolMessages.*;
import static org.testng.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -39,9 +43,6 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.messages.ToolMessages.*;
import static org.testng.Assert.*;
/** A set of test cases for the MakeLDIF tool. */
@SuppressWarnings("javadoc")
public class MakeLDIFTestCase extends ToolsTestCase
@@ -316,9 +317,9 @@
    Entry e = readEntry(outLdifFilePath);
    assertNotNull(e);
    List<Attribute> attrs = e.getAllAttributes(attrName);
    assertFalse(attrs.isEmpty());
    Attribute a = attrs.get(0);
    Iterable<Attribute> attrs = e.getAllAttributes(attrName);
    assertThat(attrs).isNotEmpty();
    Attribute a = attrs.iterator().next();
    Attribute expectedRes = Attributes.create(attrName, expectedValue);
    assertEquals(a, expectedRes);
  }
@@ -365,9 +366,9 @@
    Entry e = readEntry(outLdifFilePath);
    assertNotNull(e);
    List<Attribute> attrs = e.getAllAttributes("cn");
    assertFalse(attrs.isEmpty());
    Attribute a = attrs.get(0);
    Iterable<Attribute> attrs = e.getAllAttributes("cn");
    assertThat(attrs).isNotEmpty();
    Attribute a = attrs.iterator().next();
    assertTrue(a.iterator().next().toString().matches("Foo <[A-Z]>\\{1\\}Bar"),
        "cn value doesn't match the expected value");
  }