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

Jean-Noel Rouvignac
08.20.2013 bfe2373a3d91c2957b82e30a30dc288903d58eee
OPENDJ-803 (CR-1380) ldapsearch exits with wrong return code when server is down 

LDAPConnection.java:
In connectToHost(), protected LDAPConnectionException from the general catch(Exception) which made our error code disappear.

LDAPSearchTestCase.java:
In getInvalidArgumentLists(), removed very easily 100 lines of code.
Properly used assertEquals() instead of assertTrue().

LDAPSearchNoServerTestCase.java: ADDED
1 files added
2 files modified
236 ■■■■■ changed files
opends/src/server/org/opends/server/tools/LDAPConnection.java 3 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchNoServerTestCase.java 63 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java 170 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/LDAPConnection.java
@@ -271,6 +271,9 @@
      Message msg = INFO_RESULT_CLIENT_SIDE_CONNECT_ERROR.get();
      throw new LDAPConnectionException(msg, CLIENT_SIDE_CONNECT_ERROR, null,
                                        ce);
    } catch (LDAPConnectionException e)
    {
      throw e;
    } catch(Exception ex2)
    {
      if (debugEnabled())
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchNoServerTestCase.java
New file
@@ -0,0 +1,63 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.server.tools;
import static org.testng.Assert.*;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.testng.annotations.Test;
/**
 * A set of test cases for the LDAPSearch tool.
 */
public class LDAPSearchNoServerTestCase
       extends ToolsTestCase
{
  /**
   * Tests a simple search with the server down, we should get error code 91.
   */
  @Test
  public void testSearchWithServerDown()
  {
    String[] args =
    {
      "-h", "127.0.0.1",
      "-p", "1389",
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-b", "",
      "-s", "base",
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err),
        LDAPResultCode.CLIENT_SIDE_CONNECT_ERROR);
  }
}
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
@@ -23,15 +23,15 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.tools;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -46,7 +46,6 @@
import org.opends.server.types.ResultCode;
import static org.testng.Assert.*;
import static org.opends.server.util.ServerConstants.*;
@@ -124,159 +123,16 @@
    argLists.add(args);
    reasonList.add("No arguments");
    args = new String[]
    List<String> options =
        Arrays.asList("-b", "-D", "-w", "-j", "-Y", "-i", "-K", "-P", "-W",
            "-h", "-p", "-V", "-f", "-J", "-z", "-l", "-s", "-a", "-o", "-c",
            "--assertionFilter", "--matchedValuesFilter");
    for (String option : options)
    {
      "-b"
    };
      args = new String[] { option };
    argLists.add(args);
    reasonList.add("No value for '-b' argument");
    args = new String[]
    {
      "-D"
    };
    argLists.add(args);
    reasonList.add("No value for '-D' argument");
    args = new String[]
    {
      "-w"
    };
    argLists.add(args);
    reasonList.add("No value for '-w' argument");
    args = new String[]
    {
      "-j"
    };
    argLists.add(args);
    reasonList.add("No value for '-j' argument");
    args = new String[]
    {
      "-Y"
    };
    argLists.add(args);
    reasonList.add("No value for '-Y' argument");
    args = new String[]
    {
      "-i"
    };
    argLists.add(args);
    reasonList.add("No value for '-i' argument");
    args = new String[]
    {
      "-K"
    };
    argLists.add(args);
    reasonList.add("No value for '-K' argument");
    args = new String[]
    {
      "-P"
    };
    argLists.add(args);
    reasonList.add("No value for '-P' argument");
    args = new String[]
    {
      "-W"
    };
    argLists.add(args);
    reasonList.add("No value for '-W' argument");
    args = new String[]
    {
      "-h"
    };
    argLists.add(args);
    reasonList.add("No value for '-h' argument");
    args = new String[]
    {
      "-p"
    };
    argLists.add(args);
    reasonList.add("No value for '-p' argument");
    args = new String[]
    {
      "-V"
    };
    argLists.add(args);
    reasonList.add("No value for '-V' argument");
    args = new String[]
    {
      "-f"
    };
    argLists.add(args);
    reasonList.add("No value for '-f' argument");
    args = new String[]
    {
      "-J"
    };
    argLists.add(args);
    reasonList.add("No value for '-J' argument");
    args = new String[]
    {
      "-z"
    };
    argLists.add(args);
    reasonList.add("No value for '-z' argument");
    args = new String[]
    {
      "-l"
    };
    argLists.add(args);
    reasonList.add("No value for '-l' argument");
    args = new String[]
    {
      "-s"
    };
    argLists.add(args);
    reasonList.add("No value for '-s' argument");
    args = new String[]
    {
      "-a"
    };
    argLists.add(args);
    reasonList.add("No value for '-a' argument");
    args = new String[]
    {
      "-o"
    };
    argLists.add(args);
    reasonList.add("No value for '-o' argument");
    args = new String[]
    {
      "-c"
    };
    argLists.add(args);
    reasonList.add("No value for '-c' argument");
    args = new String[]
    {
      "--assertionFilter"
    };
    argLists.add(args);
    reasonList.add("No value for '--assertionFilter' argument");
    args = new String[]
    {
      "--matchedValuesFilter"
    };
    argLists.add(args);
    reasonList.add("No value for '--matchedValuesFilter' argument");
      reasonList.add("No value for '" + option + "' argument");
    }
    args = new String[]
    {
@@ -2325,7 +2181,7 @@
      "(objectClass=*)"
    };
    assertTrue(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0);
  }
@@ -2384,7 +2240,7 @@
      "dn"
    };
    assertTrue(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0);
  }