From 09ad1babd14d88fc424fb004d15eaf81eddd2f98 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 15 Mar 2007 18:13:30 +0000
Subject: [PATCH] Update the LDAPSearch tool so that the "--noop" option works as expected.  If it is provided, then the tool will verify that all of the arguments are valid but will not actually attempt any network communication.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java                                 |   10 ++++++++++
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
index c1e643b..d486fa2 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -1359,6 +1359,16 @@
         connectionOptions.setSSLConnectionFactory(sslConnectionFactory);
       }
 
+      if (noop.isPresent())
+      {
+        // We don't actually need to open a connection or perform the search,
+        // so we're done.  We should return 0 to either mean that the processing
+        // was successful or that there were no matching entries, based on
+        // countEntries.isPresent() (but in either case the return value should
+        // be zero).
+        return 0;
+      }
+
       AtomicInteger nextMessageID = new AtomicInteger(1);
       connection = new LDAPConnection(hostNameValue, portNumber,
                                       connectionOptions, out, err);
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
index 1b3a149..4521eed 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/LDAPSearchTestCase.java
@@ -566,6 +566,56 @@
 
 
   /**
+   * Tests a simple invocation using the "--noop" option with a valid argument
+   * set.
+   */
+  @Test()
+  public void testNoOpSearchValidArguments()
+  {
+    String[] args =
+    {
+      "-h", "doesnt.need.to.resolve",
+      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
+      "-V", "3",
+      "-D", "cn=Directory Manager",
+      "-w", "password",
+      "-b", "",
+      "-s", "base",
+      "--noop",
+      "(objectClass=*)"
+    };
+
+    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
+  }
+
+
+
+  /**
+   * Tests a simple invocation using the "--noop" option with an invalid
+   * argument set.
+   */
+  @Test()
+  public void testNoOpSearchInvalidArguments()
+  {
+    String[] args =
+    {
+      "-h", "doesnt.need.to.resolve",
+      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
+      "-V", "3",
+      "-D", "cn=Directory Manager",
+      "-w", "password",
+      "-b", "",
+      "-s", "invalid",
+      "--noop",
+      "(objectClass=*)"
+    };
+
+    assertFalse(LDAPSearch.mainSearch(args, false, null, System.err) == 0);
+  }
+
+
+
+  /**
    * Tests a simple LDAP search over SSL using blind trust.
    */
   @Test()

--
Gitblit v1.10.0