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

Ludovic Poitou
28.03.2011 955aa04202762358d83b2356d1394d712cf306ee
Fix for OPENDJ-255: Incorrect dsconfig usage for setting multiple property values at once.
Contribution by German Parente (cgp).
Both --set prop:value1 --set prop:value2 AND --set prop:value1 --add prop:value2 are accepted to set/create multivalued properties with dsconfig. When adding to existing property, --add is to be used.
1 files added
1 files modified
143 ■■■■■ changed files
opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java 137 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/SetPropSubCommandHandler.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 */
package org.opends.server.tools.dsconfig;
@@ -823,11 +824,6 @@
      }
      // Apply the modification.
      if (lastModTypes.containsKey(propertyName) &&
        (lastModTypes.get(propertyName) == ModificationType.SET)) {
        throw ArgumentExceptionFactory.incompatiblePropertyModification(m);
      }
      if (lastModTypes.containsKey(propertyName)) {
        modifyPropertyValues(child, pd, changes, ModificationType.ADD, value);
      } else {
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/dsconfig/DsconfigOptionsTestCase.java
New file
@@ -0,0 +1,137 @@
/*
 * 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 2011 ForgeRock AS
 */
package org.opends.server.tools.dsconfig;
import java.io.File;
import java.io.FileWriter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.opends.server.TestCaseUtils;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.core.DirectoryServer;
import static org.testng.Assert.*;
import static org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.*;
/**
 * A set of test cases for the dsservice tool.
 */
public class DsconfigOptionsTestCase extends DirectoryServerTestCase {
  /**
   * Ensures that the Directory Server is running and performs other necessary
   * setup.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass()
  public void before()
         throws Exception
  {
    TestCaseUtils.startServer();
  }
  /**
   * Ensures ADS is removed.
   * @throws  Exception  If an unexpected problem occurs.
   */
  @AfterClass()
  public void afterClass()
         throws Exception
  {
  }
  /**
   * Tests that multiple  "--set" option cannot be used with a singlevalued
   * property
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testMultipleSetSingleValuedProperty()
         throws Exception
  {
    String[] args =
    {
          "set-global-configuration-prop",
          "-p",String.valueOf(TestCaseUtils.getServerAdminPort()),
          "--trustAll",
          "--bindDN","cn=Directory Manager",
          "--bindPassword" , "password",
          "--no-prompt",
          "--set", "idle-time-limit:10000ms",
          "--set", "idle-time-limit:1000ms"
    };
     assertFalse(DSConfig.main(args, false, System.out, System.err)
        == SUCCESSFUL.getReturnCode());
  }
  /**
   * Tests that multiple  "--set" option are allowed to be used with a multivalued
   * property (see OPENDJ-255)
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @Test()
  public void testMultipleSetMultiValuedProperty()
         throws Exception
  {
    String[] args =
    {
          "set-connection-handler-prop",
          "--handler-name", "LDAP Connection Handler",
          "-p",String.valueOf(TestCaseUtils.getServerAdminPort()),
          "--trustAll",
          "--bindDN","cn=Directory Manager",
          "--bindPassword" , "password",
          "--no-prompt",
          "--set", "denied-client:1.1.1.1",
          "--set", "denied-client:2.2.2.2"
    };
     assertEquals(DSConfig.main(args, false, System.out, System.err),
        SUCCESSFUL.getReturnCode());
  }
}