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

Jean-Noël Rouvignac
16.54.2015 23de2bc1524fe169fcca2c4a39201db78f6c6b9a
Entry.getAttributes() never return null
4 files modified
113 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java 20 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/SearchResultEntry.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/core/SearchOperationTestCase.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java 88 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java
@@ -560,18 +560,12 @@
        final SearchResultEntry searchResultEntry =
                Responses.newSearchResultEntry(srvResultEntry.getName().toString());
        if (srvResultEntry.getAttributes() != null) {
            for (org.opends.server.types.Attribute a : srvResultEntry.getAttributes()) {
                searchResultEntry.addAttribute(from(a));
            }
        for (org.opends.server.types.Attribute a : srvResultEntry.getAttributes()) {
            searchResultEntry.addAttribute(from(a));
        }
        if (srvResultEntry.getControls() != null) {
            for (org.opends.server.types.Control c : srvResultEntry.getControls()) {
                searchResultEntry.addControl(from(c));
            }
        for (org.opends.server.types.Control c : srvResultEntry.getControls()) {
            searchResultEntry.addControl(from(c));
        }
        return searchResultEntry;
    }
@@ -588,10 +582,8 @@
        final org.opends.server.types.Entry srvResultEntry) {
        final org.forgerock.opendj.ldap.Entry entry = new LinkedHashMapEntry(srvResultEntry.getName().toString());
        if (srvResultEntry.getAttributes() != null) {
            for (org.opends.server.types.Attribute a : srvResultEntry.getAttributes()) {
                entry.addAttribute(from(a));
            }
        for (org.opends.server.types.Attribute a : srvResultEntry.getAttributes()) {
            entry.addAttribute(from(a));
        }
        return entry;
    }
opendj-server-legacy/src/main/java/org/opends/server/types/SearchResultEntry.java
@@ -51,7 +51,7 @@
       extends Entry
{
  /** The set of controls associated with this search result entry. */
  private List<Control> controls;
  private final List<Control> controls;
opendj-server-legacy/src/test/java/org/opends/server/core/SearchOperationTestCase.java
@@ -1163,9 +1163,8 @@
  private Set<String> getAttributeNames(Entry entry)
  {
    List<Attribute> attrList = entry.getAttributes();
    Set<String> actualNames = new HashSet<>();
    for (Attribute attribute : attrList)
    for (Attribute attribute : entry.getAttributes())
    {
      actualNames.add(attribute.getNameWithOptions());
    }
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java
@@ -26,6 +26,7 @@
 */
package org.opends.server.protocols.ldap;
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.*;
@@ -49,9 +50,13 @@
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.*;
import org.opends.server.types.Attribute;
import org.opends.server.types.ExistingFileBehavior;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.RawAttribute;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.Base64;
import org.opends.server.util.StaticUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -104,8 +109,7 @@
  /**
   * Test to verify an ADD of the binary attributes  using a V3
   * protocol.
   * Test to verify an ADD of the binary attributes  using a V3 protocol.
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
@@ -182,15 +186,14 @@
      "-f", filePath,
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    assertFalse(err==0);
    assertThat(err).isNotEqualTo(0);
  }
  /**
   * Test to verify a SEARCH using the ;binary transfer option using a V3
   * protocol.
   * Test to verify a SEARCH using the ;binary transfer option using a V3 protocol.
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test(dependsOnMethods = {"org.opends.server.protocols.ldap."+
@@ -225,8 +228,7 @@
    List<SearchResultEntry> entries = searchOperation.getSearchEntries();
    SearchResultEntry e = entries.get(0);
    assertNotNull(e);
    List<Attribute> list = e.getAttributes();
    assertEquals(list.size(), 0);
    assertThat(e.getAttributes()).isEmpty();
  }
@@ -240,11 +242,9 @@
  public void binaryOptionUsingV2() throws Exception
  {
    //Construct a V2 connection.
    Socket     s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
    org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s);
    org.opends.server.tools.LDAPWriter w = new org.opends.server.tools.LDAPWriter(s);
    try
    try (Socket s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
        org.opends.server.tools.LDAPReader r = new org.opends.server.tools.LDAPReader(s);
        org.opends.server.tools.LDAPWriter w = new org.opends.server.tools.LDAPWriter(s))
    {
      BindRequestProtocolOp bindRequest =
           new BindRequestProtocolOp(
@@ -329,11 +329,6 @@
      }
      assertTrue(snWithMultiVal && certWithNoOption);
    }
    finally
    {
      StaticUtils.close(r, w);
      StaticUtils.close(s);
    }
  }
@@ -383,25 +378,26 @@
    importLDIF();
    assertTrue(containsBinary());
    //Remove the binary option and re-import it.
    FileReader reader = new FileReader(ldif);
    BufferedReader buf = new BufferedReader(reader);
    StringBuilder builder = new StringBuilder();
    String userCert = "userCertificate;binary";
    String line = null;
    while((line=buf.readLine())!=null)
    try (FileReader reader = new FileReader(ldif);
        BufferedReader buf = new BufferedReader(reader))
    {
      if(line.startsWith(userCert))
      String userCert = "userCertificate;binary";
      String line = null;
      while ((line = buf.readLine()) != null)
      {
        builder.append("userCertificate:");
        builder.append(line, userCert.length()+1, line.length());
        if (line.startsWith(userCert))
        {
          builder.append("userCertificate:");
          builder.append(line, userCert.length() + 1, line.length());
        }
        else
        {
          builder.append(line);
        }
        builder.append("\n");
      }
      else
      {
        builder.append(line);
      }
      builder.append("\n");
    }
    buf.close();
    ldif.delete();
    ldif = new File(TestCaseUtils.createTempFile(builder.toString()));
    importLDIF();
@@ -414,8 +410,7 @@
  /**
   * Test to verify a MODIFY using the ;binary transfer option using V3
   * protocol.
   * Test to verify a MODIFY using the ;binary transfer option using V3 protocol.
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test
@@ -455,32 +450,31 @@
    };
    err = LDAPModify.mainModify(args, false, null,null);
    assertEquals(err,0);
  }
  /**
   * Utility method to verify if the LDIF file contains binary option.
   * @return  {@code true} if binary option is found in the LDIF
   *           , or {@code false} if not.
   * @return  {@code true} if binary option is found in the LDIF, or {@code false} if not.
   * @throws  Exception  If an unexpected problem occurs.
   */
  private boolean containsBinary() throws Exception
  {
    FileReader reader = new FileReader(ldif);
    BufferedReader buf = new BufferedReader(reader);
    String line = null;
    boolean found=false;
    while((line=buf.readLine())!=null)
    try (FileReader reader = new FileReader(ldif);
        BufferedReader buf = new BufferedReader(reader))
    {
      if(line.startsWith("userCertificate;binary"))
      String line = null;
      boolean found = false;
      while ((line = buf.readLine()) != null)
      {
        found = true;
        if (line.startsWith("userCertificate;binary"))
        {
          found = true;
        }
      }
      return found;
    }
    buf.close();
    return found;
  }