Fix for issue 2764 (ldapsearch: "--countEntries" option, the number of matching entries should not be used as return code)
--This line, and th se below, will be ignored--
M tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
M src/server/org/opends/server/tools/LDAPSearch.java
| | |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainSearch(args, true, System.out, System.err); |
| | | int retCode = mainSearch(args, true, false, System.out, System.err); |
| | | |
| | | if(retCode != 0) |
| | | { |
| | |
| | | |
| | | public static int mainSearch(String[] args) |
| | | { |
| | | return mainSearch(args, true, System.out, System.err); |
| | | return mainSearch(args, true, true, System.out, System.err); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return The error code. |
| | | */ |
| | | |
| | | public static int mainSearch(String[] args, boolean initializeServer, |
| | | OutputStream outStream, OutputStream errStream) |
| | | { |
| | | return mainSearch(args, initializeServer, true, outStream, errStream); |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to |
| | | * run the ldapsearch tool. |
| | | * |
| | | * @param args The command-line arguments provided to this |
| | | * program. |
| | | * @param initializeServer Indicates whether to initialize the server. |
| | | * @param returnMatchingEntries whether when the option --countEntries is |
| | | * specified, the number of matching entries should |
| | | * be returned or not. |
| | | * @param outStream The output stream to use for standard output, or |
| | | * <CODE>null</CODE> if standard output is not |
| | | * needed. |
| | | * @param errStream The output stream to use for standard error, or |
| | | * <CODE>null</CODE> if standard error is not |
| | | * needed. |
| | | * |
| | | * @return The error code. |
| | | */ |
| | | |
| | | public static int mainSearch(String[] args, boolean initializeServer, |
| | | boolean returnMatchingEntries, OutputStream outStream, |
| | | OutputStream errStream) |
| | | { |
| | | PrintStream out; |
| | | if (outStream == null) |
| | | { |
| | |
| | | searchOptions, wrapColumn); |
| | | } |
| | | |
| | | if (countEntries.isPresent()) |
| | | if (countEntries.isPresent() && returnMatchingEntries) |
| | | { |
| | | return matchingEntries; |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | |
| | | throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | |
| | | |
| | | TestCaseUtils.dsconfig( |
| | | "set-sasl-mechanism-handler-prop", |
| | | "--handler-name", "DIGEST-MD5", |
| | | "--set", "server-fqdn:" + "127.0.0.1"); |
| | | |
| | | |
| | | File pwFile = File.createTempFile("valid-bind-password-", ".txt"); |
| | | pwFile.deleteOnExit(); |
| | | FileWriter fileWriter = new FileWriter(pwFile); |
| | |
| | | |
| | | @AfterClass |
| | | public void tearDown() throws Exception { |
| | | |
| | | |
| | | TestCaseUtils.dsconfig( |
| | | "set-sasl-mechanism-handler-prop", |
| | | "--handler-name", "DIGEST-MD5", |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 1); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 1); |
| | | |
| | | args = new String[] |
| | | { |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 2); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 2); |
| | | |
| | | args = new String[] |
| | | { |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 2); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 2); |
| | | } |
| | | |
| | | |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 5); |
| | | assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 5); |
| | | } |
| | | |
| | | |
| | |
| | | "(objectClass=*)" |
| | | }; |
| | | |
| | | assertEquals(LDAPSearch.mainSearch(pagedArgs, false, null, System.err), |
| | | LDAPSearch.mainSearch(unpagedArgs, false, null, System.err)); |
| | | assertEquals( |
| | | LDAPSearch.mainSearch(pagedArgs, false, true, null, System.err), |
| | | LDAPSearch.mainSearch(unpagedArgs, false, true, null, System.err)); |
| | | } |
| | | |
| | | |