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

Jean-Noel Rouvignac
03.21.2015 e25fdd4dba837c79b4530c7a7db7c9e4abffd754
Fixing failing tests in Jenkins.

SubCommandArgumentParser.java:
After r11664, getUsage(Argument) should call setUsageOrVersionDisplayed() itself.

ManageAccountTestCase.java:
Extracted method manageAccountMain(), the change to SubCommandArgumentParser will fix the tests.

DsconfigOptionsTestCase.java:
For testGenerateDoc() failure, calling DSConfig with "-?" option and "org.forgerock.opendj.gendoc" property set now returns SUCCESS while it was not before. This is due to r11664 which stops dsconfig execution after generating the documentation. This test assertion did not make sense to me.

*.java:
Code cleanup
3 files modified
319 ■■■■ changed files
opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java 9 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java 238 ●●●● patch | view | raw | blame | history
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java 72 ●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/SubCommandArgumentParser.java
@@ -836,9 +836,9 @@
     */
    @Override
    public String getUsage() {
        final StringBuilder buffer = new StringBuilder();
        setUsageOrVersionDisplayed(true);
        final StringBuilder buffer = new StringBuilder();
        if (subCommand == null) {
            if (System.getProperty("org.forgerock.opendj.gendoc") != null) {
                generateReferenceDoc(buffer, subCommands.values());
@@ -853,7 +853,6 @@
        } else {
            getSubCommandUsage(buffer, subCommand);
        }
        return buffer.toString();
    }
@@ -885,8 +884,9 @@
    /** Get usage for a specific usage argument. */
    private void getUsage(Argument a) {
        final StringBuilder buffer = new StringBuilder();
        setUsageOrVersionDisplayed(true);
        final StringBuilder buffer = new StringBuilder();
        final boolean isUsageArgument = isUsageArgument(a);
        if (isUsageArgument && subCommand != null) {
            getSubCommandUsage(buffer, subCommand);
@@ -900,7 +900,6 @@
            // Requested help on specific group - don't display global options.
            getFullUsage(usageGroupArguments.get(a), false, buffer);
        }
        writeToUsageOutputStream(buffer);
    }
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/ManageAccountTestCase.java
@@ -22,22 +22,17 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2012 ForgeRock AS
 *      Portions Copyright 2012-2015 ForgeRock AS
 */
package org.opends.server.tools;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
import org.opends.server.TestCaseUtils;
import org.opends.server.schema.GeneralizedTimeSyntax;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
 * A set of test cases for the ManageAccount tool.
@@ -52,8 +47,7 @@
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass
  public void startServer()
         throws Exception
  public void startServer() throws Exception
  {
    TestCaseUtils.startServer();
  }
@@ -72,48 +66,48 @@
  {
    return new Object[][]
    {
      new Object[] { "get-all" },
      new Object[] { "get-password-policy-dn" },
      new Object[] { "get-account-is-disabled" },
      new Object[] { "set-account-is-disabled" },
      new Object[] { "clear-account-is-disabled" },
      new Object[] { "get-account-expiration-time" },
      new Object[] { "set-account-expiration-time" },
      new Object[] { "clear-account-expiration-time" },
      new Object[] { "get-seconds-until-account-expiration" },
      new Object[] { "get-password-changed-time" },
      new Object[] { "set-password-changed-time" },
      new Object[] { "clear-password-changed-time" },
      new Object[] { "get-password-expiration-warned-time" },
      new Object[] { "set-password-expiration-warned-time" },
      new Object[] { "clear-password-expiration-warned-time" },
      new Object[] { "get-seconds-until-password-expiration" },
      new Object[] { "get-seconds-until-password-expiration-warning" },
      new Object[] { "get-authentication-failure-times" },
      new Object[] { "add-authentication-failure-time" },
      new Object[] { "set-authentication-failure-times" },
      new Object[] { "clear-authentication-failure-times" },
      new Object[] { "get-seconds-until-authentication-failure-unlock" },
      new Object[] { "get-remaining-authentication-failure-count" },
      new Object[] { "get-last-login-time" },
      new Object[] { "set-last-login-time" },
      new Object[] { "clear-last-login-time" },
      new Object[] { "get-seconds-until-idle-lockout" },
      new Object[] { "get-password-is-reset" },
      new Object[] { "set-password-is-reset" },
      new Object[] { "clear-password-is-reset" },
      new Object[] { "get-seconds-until-password-reset-lockout" },
      new Object[] { "get-grace-login-use-times" },
      new Object[] { "add-grace-login-use-time" },
      new Object[] { "set-grace-login-use-times" },
      new Object[] { "clear-grace-login-use-times" },
      new Object[] { "get-remaining-grace-login-count" },
      new Object[] { "get-password-changed-by-required-time" },
      new Object[] { "set-password-changed-by-required-time" },
      new Object[] { "clear-password-changed-by-required-time" },
      new Object[] { "get-seconds-until-required-change-time" },
      new Object[] { "get-password-history" },
      new Object[] { "clear-password-history" }
      { "get-all" },
      { "get-password-policy-dn" },
      { "get-account-is-disabled" },
      { "set-account-is-disabled" },
      { "clear-account-is-disabled" },
      { "get-account-expiration-time" },
      { "set-account-expiration-time" },
      { "clear-account-expiration-time" },
      { "get-seconds-until-account-expiration" },
      { "get-password-changed-time" },
      { "set-password-changed-time" },
      { "clear-password-changed-time" },
      { "get-password-expiration-warned-time" },
      { "set-password-expiration-warned-time" },
      { "clear-password-expiration-warned-time" },
      { "get-seconds-until-password-expiration" },
      { "get-seconds-until-password-expiration-warning" },
      { "get-authentication-failure-times" },
      { "add-authentication-failure-time" },
      { "set-authentication-failure-times" },
      { "clear-authentication-failure-times" },
      { "get-seconds-until-authentication-failure-unlock" },
      { "get-remaining-authentication-failure-count" },
      { "get-last-login-time" },
      { "set-last-login-time" },
      { "clear-last-login-time" },
      { "get-seconds-until-idle-lockout" },
      { "get-password-is-reset" },
      { "set-password-is-reset" },
      { "clear-password-is-reset" },
      { "get-seconds-until-password-reset-lockout" },
      { "get-grace-login-use-times" },
      { "add-grace-login-use-time" },
      { "set-grace-login-use-times" },
      { "clear-grace-login-use-times" },
      { "get-remaining-grace-login-count" },
      { "get-password-changed-by-required-time" },
      { "set-password-changed-by-required-time" },
      { "clear-password-changed-by-required-time" },
      { "get-seconds-until-required-change-time" },
      { "get-password-history" },
      { "clear-password-history" }
    };
  }
@@ -131,27 +125,27 @@
  {
    return new Object[][]
    {
      new Object[] { "get-all" },
      new Object[] { "get-password-policy-dn" },
      new Object[] { "get-account-is-disabled" },
      new Object[] { "get-account-expiration-time" },
      new Object[] { "get-seconds-until-account-expiration" },
      new Object[] { "get-password-changed-time" },
      new Object[] { "get-password-expiration-warned-time" },
      new Object[] { "get-seconds-until-password-expiration" },
      new Object[] { "get-seconds-until-password-expiration-warning" },
      new Object[] { "get-authentication-failure-times" },
      new Object[] { "get-seconds-until-authentication-failure-unlock" },
      new Object[] { "get-remaining-authentication-failure-count" },
      new Object[] { "get-last-login-time" },
      new Object[] { "get-seconds-until-idle-lockout" },
      new Object[] { "get-password-is-reset" },
      new Object[] { "get-seconds-until-password-reset-lockout" },
      new Object[] { "get-grace-login-use-times" },
      new Object[] { "get-remaining-grace-login-count" },
      new Object[] { "get-password-changed-by-required-time" },
      new Object[] { "get-seconds-until-required-change-time" },
      new Object[] { "get-password-history" }
      { "get-all" },
      { "get-password-policy-dn" },
      { "get-account-is-disabled" },
      { "get-account-expiration-time" },
      { "get-seconds-until-account-expiration" },
      { "get-password-changed-time" },
      { "get-password-expiration-warned-time" },
      { "get-seconds-until-password-expiration" },
      { "get-seconds-until-password-expiration-warning" },
      { "get-authentication-failure-times" },
      { "get-seconds-until-authentication-failure-unlock" },
      { "get-remaining-authentication-failure-count" },
      { "get-last-login-time" },
      { "get-seconds-until-idle-lockout" },
      { "get-password-is-reset" },
      { "get-seconds-until-password-reset-lockout" },
      { "get-grace-login-use-times" },
      { "get-remaining-grace-login-count" },
      { "get-password-changed-by-required-time" },
      { "get-seconds-until-required-change-time" },
      { "get-password-history" }
    };
  }
@@ -169,8 +163,8 @@
  {
    return new Object[][]
    {
      new Object[] { "set-account-is-disabled" },
      new Object[] { "set-password-is-reset" },
      { "set-account-is-disabled" },
      { "set-password-is-reset" },
    };
  }
@@ -189,15 +183,15 @@
  {
    return new Object[][]
    {
      new Object[] { "set-account-expiration-time" },
      new Object[] { "set-password-changed-time" },
      new Object[] { "set-password-expiration-warned-time" },
      new Object[] { "set-authentication-failure-times" },
      new Object[] { "add-authentication-failure-time" },
      new Object[] { "set-last-login-time" },
      new Object[] { "set-grace-login-use-times" },
      new Object[] { "add-grace-login-use-time" },
      new Object[] { "set-password-changed-by-required-time" },
      { "set-account-expiration-time" },
      { "set-password-changed-time" },
      { "set-password-expiration-warned-time" },
      { "set-authentication-failure-times" },
      { "add-authentication-failure-time" },
      { "set-last-login-time" },
      { "set-grace-login-use-times" },
      { "add-grace-login-use-time" },
      { "set-password-changed-by-required-time" },
    };
  }
@@ -215,37 +209,34 @@
  {
    return new Object[][]
    {
      new Object[] { "clear-account-is-disabled" },
      new Object[] { "clear-account-expiration-time" },
      new Object[] { "clear-password-changed-time" },
      new Object[] { "clear-password-expiration-warned-time" },
      new Object[] { "clear-authentication-failure-times" },
      new Object[] { "clear-last-login-time" },
      new Object[] { "clear-password-is-reset" },
      new Object[] { "clear-grace-login-use-times" },
      new Object[] { "clear-password-changed-by-required-time" },
      new Object[] { "clear-password-history" }
      { "clear-account-is-disabled" },
      { "clear-account-expiration-time" },
      { "clear-password-changed-time" },
      { "clear-password-expiration-warned-time" },
      { "clear-authentication-failure-times" },
      { "clear-last-login-time" },
      { "clear-password-is-reset" },
      { "clear-grace-login-use-times" },
      { "clear-password-changed-by-required-time" },
      { "clear-password-history" }
    };
  }
  private int manageAccountMain(String... args)
  {
    return ManageAccount.main(args, false, null, System.err);
  }
  /**
   * Tests the various sets of arguments that may be used to get usage
   * information when no subcommand is given.
   */
  @Test()
  @Test
  public void testHelpNoSubCommand()
  {
    assertEquals(ManageAccount.main(new String[] { "-H" },
                                    false, null, System.err),
                 0);
    assertEquals(ManageAccount.main(new String[] { "--help" }, false, null,
                                    System.err),
                 0);
    assertEquals(ManageAccount.main(new String[] { "-?" }, false,
                                    null, System.err),
                 0);
    assertEquals(manageAccountMain("-H"), 0);
    assertEquals(manageAccountMain("--help"), 0);
    assertEquals(manageAccountMain("-?"), 0);
  }
@@ -265,15 +256,13 @@
      "--help"
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
  /**
   * Tests the manage-account tool without any subcommand.
   */
  @Test()
  @Test
  public void testNoSubCommand()
  {
    String[] args =
@@ -294,7 +283,7 @@
  /**
   * Tests the manage-account tool with an invalid subcommand.
   */
  @Test()
  @Test
  public void testInvalidSubCommand()
  {
    String[] args =
@@ -347,7 +336,7 @@
      "-b", "uid=test.user,o=test"
    };
    assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
    assertFalse(manageAccountMain(args) == 0);
  }
@@ -386,7 +375,7 @@
      "-b", "uid=test.user,o=test"
    };
    assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
    assertFalse(manageAccountMain(args) == 0);
  }
@@ -427,7 +416,7 @@
      "-b", "uid=test.user,o=test"
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -469,7 +458,7 @@
      "-b", "uid=test.user,o=test",
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -512,7 +501,7 @@
      "-O", "not-appropriate-for-this-subcommand"
    };
    assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
    assertFalse(manageAccountMain(args) == 0);
  }
@@ -555,7 +544,7 @@
      "-O", "true"
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -598,7 +587,7 @@
      "-O", "false"
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -641,7 +630,7 @@
      "-O", "nonboolean"
    };
    assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
    assertFalse(manageAccountMain(args) == 0);
  }
@@ -683,7 +672,7 @@
      "-b", "uid=test.user,o=test"
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -726,7 +715,7 @@
      "-O", GeneralizedTimeSyntax.format(System.currentTimeMillis())
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
@@ -769,7 +758,7 @@
      "-O", "invalid"
    };
    assertFalse(ManageAccount.main(args, false, null, System.err) == 0);
    assertFalse(manageAccountMain(args) == 0);
  }
@@ -811,7 +800,6 @@
      "-b", "uid=test.user,o=test",
    };
    assertEquals(ManageAccount.main(args, false, null, System.err), 0);
    assertEquals(manageAccountMain(args), 0);
  }
}
opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java
@@ -20,10 +20,14 @@
 *
 * CDDL HEADER END
 *
 *      Portions Copyright 2011-2014 ForgeRock AS
 *      Portions Copyright 2011-2015 ForgeRock AS
 */
package org.opends.server.tools.dsconfig;
import static com.forgerock.opendj.cli.ReturnCode.*;
import static org.testng.Assert.*;
import org.forgerock.opendj.config.dsconfig.DSConfig;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
@@ -31,9 +35,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static com.forgerock.opendj.cli.ReturnCode.*;
import static org.testng.Assert.*;
/**
 * A set of test cases for the dsconfig tool.
 */
@@ -44,24 +45,23 @@
   * Ensures that the Directory Server is running and performs other necessary
   * setup.
   */
  @BeforeClass()
  @BeforeClass
  public void before() throws Exception
  {
    TestCaseUtils.startServer();
  }
  @AfterClass(alwaysRun = true)
  public void tearDown() throws Exception {
    TestCaseUtils.dsconfig(
        "delete-connection-handler",
        "--handler-name", "HTTP Connection Handler",
        "-f");
   }
  @Test()
  }
  @Test
  public void testSetEnableHTTPConnectionHandler() {
    final String[] args =
    {
      "set-connection-handler-prop",
@@ -71,13 +71,13 @@
      "--bindPassword" , "password",
      "--no-prompt",
      "--handler-name", "HTTP Connection Handler",
      "--set", "authentication-required:false"
      "--set", "authentication-required:false"
    };
    assertTrue(dsconfigMain(args) == SUCCESS.get());
    assertEquals(dsconfigMain(args), SUCCESS.get());
  }
  @Test()
  public void testSetSASLHandler() {
  @Test
  public void testSetSASLHandler() {
    final String[] args =
    {
      "set-sasl-mechanism-handler-prop",
@@ -89,8 +89,8 @@
      "--handler-name", "DIGEST-MD5",
      "--set", "server-fqdn:" + "127.0.0.1"
    };
    assertTrue(dsconfigMain(args) == SUCCESS.get());
    assertEquals(dsconfigMain(args), SUCCESS.get());
    TestCaseUtils.dsconfig(
            "set-sasl-mechanism-handler-prop",
            "--handler-name", "DIGEST-MD5",
@@ -98,8 +98,8 @@
            "--reset", "quality-of-protection");
  }
  @Test()
  @Test
  public void testSetMaxAllowedClientConnections() {
    final String[] args =
    {
@@ -111,12 +111,12 @@
      "--no-prompt",
      "--set", "max-allowed-client-connections:32768"
    };
    assertTrue(dsconfigMain(args) == SUCCESS.get());
    assertEquals(dsconfigMain(args), SUCCESS.get());
  }
  @Test()
  @Test
  public void testSetReturnBindPassword() throws Exception
  {
  {
    final String[] args =
    {
      "set-global-configuration-prop",
@@ -127,15 +127,14 @@
      "--no-prompt",
      "--set", "return-bind-error-messages:true"
    };
    assertTrue(dsconfigMain(args) == SUCCESS.get());
    assertEquals(dsconfigMain(args), SUCCESS.get());
  }
  /**
   * Tests that multiple  "--set" option cannot be used with a single valued
   * property
   * Tests that multiple "--set" option cannot be used with a single valued property.
   */
  @Test()
  @Test
  public void testMultipleSetSingleValuedProperty() throws Exception
  {
    final String[] args =
@@ -151,12 +150,12 @@
    };
    assertTrue(dsconfigMain(args) != SUCCESS.get());
  }
  /**
   * Tests that multiple  "--set" option are allowed to be used with a multivalued
   * property (see OPENDJ-255)
   * Tests that multiple "--set" option are allowed to be used with a multivalued property (see
   * OPENDJ-255).
   */
  @Test()
  @Test
  public void testMultipleSetMultiValuedProperty() throws Exception
  {
    final String[] args =
@@ -173,18 +172,19 @@
    };
    assertEquals(dsconfigMain(args), SUCCESS.get());
  }
  @Test()
  @Test
  public void testGenerateDoc() throws Exception
  {
    System.setProperty("org.forgerock.opendj.gendoc", "true");
    System.setProperty("com.forgerock.opendj.ldap.tools.scriptName", "dsconfig");
    final String[] args = {
      "--no-prompt",
      "-?",
    };
    try
    {
      assertTrue(dsconfigMain(args) != SUCCESS.get());
      assertEquals(dsconfigMain(args), SUCCESS.get());
    }
    finally
    {