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
| | |
| | | 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()) |
| New file |
| | |
| | | /* |
| | | * 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); |
| | | } |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * 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; |
| | |
| | | import org.opends.server.types.ResultCode; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | |
| | |
| | | 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" |
| | | }; |
| | | 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"); |
| | | args = new String[] { option }; |
| | | argLists.add(args); |
| | | reasonList.add("No value for '" + option + "' argument"); |
| | | } |
| | | |
| | | args = new String[] |
| | | { |
| | |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.clearJEBackend(true, "userRoot", "dc=example,dc=com"); |
| | | |
| | | |
| | | String[] args = |
| | | { |
| | | "-h", "127.0.0.1", |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertTrue(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |
| | |
| | | "dn" |
| | | }; |
| | | |
| | | assertTrue(LDAPSearch.mainSearch(args, false, null, null) == 0); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0); |
| | | } |
| | | |
| | | |