From e80072d823b3a54984176c8deff89b6f943d0cc8 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 04 May 2012 11:18:11 +0000
Subject: [PATCH] Fix OPENDJ-476: Manage Account fails with NPE if target DN does not exist Fix precommit tests failure.
---
opends/src/server/org/opends/server/tools/ManageAccount.java | 20 +++++++++++++-------
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java | 39 +++++++++++++++++++++------------------
2 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/opends/src/server/org/opends/server/tools/ManageAccount.java b/opends/src/server/org/opends/server/tools/ManageAccount.java
index a0d55eb..c9f12fc 100644
--- a/opends/src/server/org/opends/server/tools/ManageAccount.java
+++ b/opends/src/server/org/opends/server/tools/ManageAccount.java
@@ -512,7 +512,7 @@
*/
public static void main(String[] args)
{
- int returnCode = main(args, System.out, System.err);
+ int returnCode = main(args, true, System.out, System.err);
if (returnCode != 0)
{
System.exit(filterExitCode(returnCode));
@@ -526,6 +526,7 @@
* appropriate processing.
*
* @param args The command-line arguments provided to this program.
+ * @param initServer Indicates whether to initialize the server.
* @param outStream The output stream to use for standard output, or
* {@code null} if standard output is not needed.
* @param errStream The output stream to use for standard error, or
@@ -533,9 +534,10 @@
*
* @return A result code indicating whether the processing was successful.
*/
- public static int main(String[] args, OutputStream outStream,
- OutputStream errStream)
+ public static int main(String[] args, Boolean initServer,
+ OutputStream outStream, OutputStream errStream)
{
+
if (outStream == null)
{
out = NullOutputStream.printStream();
@@ -558,7 +560,7 @@
// Parse the command-line arguments provided to the program.
- int result = parseArgsAndConnect(args);
+ int result = parseArgsAndConnect(args, initServer);
if (result < 0)
{
// This should only happen if we're only displaying usage information or
@@ -832,12 +834,14 @@
* Initializes the argument parser for this tool, parses the provided
* arguments, and establishes a connection to the server.
*
+ * @param args Command arguments to parse.
+ * @param initServer Indicates whether to initialize the server.
* @return A result code that indicates the result of the processing. A
* value of zero indicates that all processing completed
* successfully. A value of -1 indicates that only the usage
* information was displayed and no further action is required.
*/
- private static int parseArgsAndConnect(String[] args)
+ private static int parseArgsAndConnect(String[] args, Boolean initServer)
{
argParser = new SubCommandArgumentParser(
CLASS_NAME, INFO_PWPSTATE_TOOL_DESCRIPTION.get(),
@@ -1248,8 +1252,10 @@
targetDNString = targetDN.getValue();
// Bootstrap and initialize directory data structures.
- EmbeddedUtils.initializeForClientUse();
-
+ if (initServer)
+ {
+ EmbeddedUtils.initializeForClientUse();
+ }
// Create the LDAP connection options object, which will be used to
// customize the way that we connect to the server and specify a set of
// basic defaults.
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java
index 381e392..be42a34 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
+ * Portions Copyright 2012 ForgeRock AS
*/
package org.opends.server.tools;
@@ -237,12 +238,14 @@
@Test()
public void testHelpNoSubCommand()
{
- assertEquals(ManageAccount.main(new String[] { "-H" }, null, System.err),
+ assertEquals(ManageAccount.main(new String[] { "-H" },
+ false, null, System.err),
0);
- assertEquals(ManageAccount.main(new String[] { "--help" }, null,
+ assertEquals(ManageAccount.main(new String[] { "--help" }, false, null,
System.err),
0);
- assertEquals(ManageAccount.main(new String[] { "-?" }, null, System.err),
+ assertEquals(ManageAccount.main(new String[] { "-?" }, false,
+ null, System.err),
0);
}
@@ -263,7 +266,7 @@
"--help"
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -284,7 +287,7 @@
"-b", "uid=test.user,o=test"
};
- assertFalse(ManageAccount.main(args, null, null) == 0);
+ assertFalse(ManageAccount.main(args, false, null, null) == 0);
}
@@ -306,7 +309,7 @@
"-b", "uid=test.user,o=test"
};
- assertFalse(ManageAccount.main(args, null, null) == 0);
+ assertFalse(ManageAccount.main(args, false, null, null) == 0);
}
@@ -345,7 +348,7 @@
"-b", "uid=test.user,o=test"
};
- assertFalse(ManageAccount.main(args, null, System.err) == 0);
+ assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
}
@@ -384,7 +387,7 @@
"-b", "uid=test.user,o=test"
};
- assertFalse(ManageAccount.main(args, null, System.err) == 0);
+ assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
}
@@ -425,7 +428,7 @@
"-b", "uid=test.user,o=test"
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -467,7 +470,7 @@
"-b", "uid=test.user,o=test",
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -510,7 +513,7 @@
"-O", "not-appropriate-for-this-subcommand"
};
- assertFalse(ManageAccount.main(args, null, System.err) == 0);
+ assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
}
@@ -553,7 +556,7 @@
"-O", "true"
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -596,7 +599,7 @@
"-O", "false"
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -639,7 +642,7 @@
"-O", "nonboolean"
};
- assertFalse(ManageAccount.main(args, null, System.err) == 0);
+ assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
}
@@ -681,7 +684,7 @@
"-b", "uid=test.user,o=test"
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -724,7 +727,7 @@
"-O", GeneralizedTimeSyntax.format(System.currentTimeMillis())
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
@@ -767,7 +770,7 @@
"-O", "invalid"
};
- assertFalse(ManageAccount.main(args, null, System.err) == 0);
+ assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
}
@@ -809,7 +812,7 @@
"-b", "uid=test.user,o=test",
};
- assertEquals(ManageAccount.main(args, null, System.err), 0);
+ assertEquals(ManageAccount.main(args, false, null, System.err), 0);
}
}
--
Gitblit v1.10.0