[ldap-sdk-commits] SF.net SVN: ldap-sdk:[1577] trunk
A Java-based LDAP API
Brought to you by:
dirmgr,
kennethleo
From: <di...@us...> - 2022-11-28 20:14:14
|
Revision: 1577 http://sourceforge.net/p/ldap-sdk/code/1577 Author: dirmgr Date: 2022-11-28 20:14:12 +0000 (Mon, 28 Nov 2022) Log Message: ----------- Fix an issue with mutually dependent arguments Fixed a bug in the argument parser's support for mutually dependent arguments. In a mutually dependent argument set, if any one of the arguments is provided, then all of the other arguments in the set must also be provided, but there was a problem with support for sets containing three or more elements. In such cases, the argument parser would only enforce that at least two arguments from the set were present. Modified Paths: -------------- trunk/docs/release-notes.html trunk/src/com/unboundid/util/args/ArgumentParser.java trunk/tests/unit/src/com/unboundid/util/args/ArgumentParserTestCase.java Modified: trunk/docs/release-notes.html =================================================================== --- trunk/docs/release-notes.html 2022-11-07 15:25:49 UTC (rev 1576) +++ trunk/docs/release-notes.html 2022-11-28 20:14:12 UTC (rev 1577) @@ -28,6 +28,16 @@ </li> <li> + Fixed a bug in the argument parser's support for mutually dependent arguments. + In a mutually dependent argument set, if any one of the arguments is provided, + then all of the other arguments in the set must also be provided, but there was + a problem with support for sets containing three or more elements. In such + cases, the argument parser would only enforce that at least two arguments from + the set were present. + <br><br> + </li> + + <li> Added JSONObject methods for retrieving fields by name using case-insensitive matching. By default, JSON field names are treated in a case-sensitive manner, but new methods allow them to be retrieved in a case-insensitive manner. Modified: trunk/src/com/unboundid/util/args/ArgumentParser.java =================================================================== --- trunk/src/com/unboundid/util/args/ArgumentParser.java 2022-11-07 15:25:49 UTC (rev 1576) +++ trunk/src/com/unboundid/util/args/ArgumentParser.java 2022-11-28 20:14:12 UTC (rev 1577) @@ -55,7 +55,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedHashMap; @@ -1488,12 +1487,14 @@ " that is not registered with the argument parser."); } - final Set<Argument> allArgsSet = new HashSet<>(arguments); - for (final Argument a : allArgsSet) + final List<Argument> allArgsList = new ArrayList<>(arguments); + for (int i=0; i < allArgsList.size(); i++) { - final Set<Argument> dependentArgs = new HashSet<>(allArgsSet); - dependentArgs.remove(a); - addDependentArgumentSet(a, dependentArgs); + for (int j=(i+1); j < allArgsList.size(); j++) + { + addDependentArgumentSet(allArgsList.get(i), allArgsList.get(j)); + addDependentArgumentSet(allArgsList.get(j), allArgsList.get(i)); + } } } Modified: trunk/tests/unit/src/com/unboundid/util/args/ArgumentParserTestCase.java =================================================================== --- trunk/tests/unit/src/com/unboundid/util/args/ArgumentParserTestCase.java 2022-11-07 15:25:49 UTC (rev 1576) +++ trunk/tests/unit/src/com/unboundid/util/args/ArgumentParserTestCase.java 2022-11-28 20:14:12 UTC (rev 1577) @@ -604,13 +604,15 @@ assertNotNull(p.getDependentArgumentSets()); assertFalse(p.getDependentArgumentSets().isEmpty()); - assertEquals(p.getDependentArgumentSets().size(), 2); + assertEquals(p.getDependentArgumentSets().size(), 2, + String.valueOf(p.getDependentArgumentSets())); p.addMutuallyDependentArgumentSet(c, d, e); assertNotNull(p.getDependentArgumentSets()); assertFalse(p.getDependentArgumentSets().isEmpty()); - assertEquals(p.getDependentArgumentSets().size(), 5); + assertEquals(p.getDependentArgumentSets().size(), 8, + String.valueOf(p.getDependentArgumentSets())); try { @@ -702,6 +704,104 @@ { // This was expected. } + + + // Make sure that the parser properly rejects attempts to use mutually + // dependent arguments without each other. + try + { + p.reset(); + p.parse(new String[] { "-a" }); + fail("Expected an exception when providing a but not b"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-b" }); + fail("Expected an exception when providing b but not a"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + p.reset(); + p.parse(new String[] { "-a", "-b" }); + + + try + { + p.reset(); + p.parse(new String[] { "-c" }); + fail("Expected an exception when providing c but not d or e"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-d" }); + fail("Expected an exception when providing d but not c or e"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-e" }); + fail("Expected an exception when providing e but not c or d"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-c", "-d" }); + fail("Expected an exception when providing c and d but not e"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-c", "-e" }); + fail("Expected an exception when providing c and e but not d"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + try + { + p.reset(); + p.parse(new String[] { "-d", "-e" }); + fail("Expected an exception when providing d and e but not c"); + } + catch (final ArgumentException ex) + { + // This was expected. + } + + p.reset(); + p.parse(new String[] { "-c", "-d", "-e" }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |