You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/11/02 08:07:42 UTC
svn commit: r1196475 - in /oodt/trunk/cli/src:
main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
Author: bfoster
Date: Wed Nov 2 07:07:41 2011
New Revision: 1196475
URL: http://svn.apache.org/viewvc?rev=1196475&view=rev
Log:
- added check to make sure that only 1 help, 1 action, 1 psa can be specified at the same time... (i.e. if 2 actions are specified, this results in a IllegalArgumentException now)
Modified:
oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
Modified: oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java?rev=1196475&r1=1196474&r2=1196475&view=diff
==============================================================================
--- oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java (original)
+++ oodt/trunk/cli/src/main/java/org/apache/oodt/cas/cli/util/CmdLineUtils.java Wed Nov 2 07:07:41 2011
@@ -442,6 +442,8 @@ public class CmdLineUtils {
* The {@link Set} of {@link CmdLineOptionInstance} to find the
* {@link CmdLineOptionInstance} whose {@link CmdLineOption} is of
* type {@link PrintSupportedActionsCmdLineOption} in
+ * @throws IllegalArgumentException
+ * If more than one print supported actions option is specified
* @return The found {@link CmdLineOptionInstance} whose
* {@link CmdLineOption} is of type
* {@link PrintSupportedActionsCmdLineOption}, or null if not found.
@@ -450,12 +452,17 @@ public class CmdLineUtils {
Set<CmdLineOptionInstance> options) {
Validate.notNull(options);
+ CmdLineOptionInstance specifiedPsa = null;
for (CmdLineOptionInstance option : options) {
if (isPrintSupportedActionsOption(option.getOption())) {
- return option;
+ if (specifiedPsa != null) {
+ throw new IllegalArgumentException(
+ "Only on print supported actions option can be specified!");
+ }
+ specifiedPsa = option;
}
}
- return null;
+ return specifiedPsa;
}
/**
@@ -526,18 +533,25 @@ public class CmdLineUtils {
* @param options
* The {@link Set} of {@link CmdLineOption} to search through for a
* {@link ActionCmdLineOption}
+ * @throws IllegalArgumentException
+ * If more than one action option has be specified
* @return The found {@link ActionCmdLineOption}, or null if not found
*/
public static CmdLineOptionInstance findSpecifiedActionOption(
Set<CmdLineOptionInstance> options) {
Validate.notNull(options);
+ CmdLineOptionInstance specifiedAction = null;
for (CmdLineOptionInstance option : options) {
if (isActionOption(option.getOption())) {
- return option;
+ if (specifiedAction != null) {
+ throw new IllegalArgumentException(
+ "Only one action may be specified!");
+ }
+ specifiedAction = option;
}
}
- return null;
+ return specifiedAction;
}
/**
@@ -625,18 +639,25 @@ public class CmdLineUtils {
* The {@link Set} of {@link CmdLineOptionInstance}s to search
* through for the {@link CmdLineOptionInstance} whose
* {@link CmdLineOption} is of type {@link HelpCmdLineOption}
+ * @throws IllegalArgumentException
+ * If more than one help option is specified
* @return The found {@link CmdLineOptionInstance}, null if not found
*/
public static CmdLineOptionInstance findSpecifiedHelpOption(
Set<CmdLineOptionInstance> options) {
Validate.notNull(options);
+ CmdLineOptionInstance specifiedHelp = null;
for (CmdLineOptionInstance option : options) {
if (isHelpOption(option.getOption())) {
- return option;
+ if (specifiedHelp != null) {
+ throw new IllegalArgumentException(
+ "Help can only be specified once!");
+ }
+ specifiedHelp = option;
}
}
- return null;
+ return specifiedHelp;
}
/**
Modified: oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java?rev=1196475&r1=1196474&r2=1196475&view=diff
==============================================================================
--- oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java (original)
+++ oodt/trunk/cli/src/test/org/apache/oodt/cas/cli/util/TestCmdLineUtils.java Wed Nov 2 07:07:41 2011
@@ -24,6 +24,9 @@ import static org.apache.oodt.cas.cli.te
import static org.apache.oodt.cas.cli.test.util.TestUtils.createOptionalRequirementRule;
import static org.apache.oodt.cas.cli.test.util.TestUtils.createRequiredRequirementRule;
import static org.apache.oodt.cas.cli.test.util.TestUtils.createSimpleOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedActionOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedHelpOption;
+import static org.apache.oodt.cas.cli.util.CmdLineUtils.findSpecifiedPrintSupportedActionsOption;
//JDK imports
import java.util.ArrayList;
@@ -325,15 +328,22 @@ public class TestCmdLineUtils extends Te
}
public void testFindSpecifiedPrintSupportedActionsOption() {
- CmdLineOptionInstance psaAction = createOptionInstance(new PrintSupportedActionsCmdLineOption());
+ CmdLineOptionInstance psaAction = createOptionInstance(
+ new PrintSupportedActionsCmdLineOption());
Set<CmdLineOptionInstance> options = Sets.newHashSet(
createOptionInstance(createSimpleOption("test", false)),
createOptionInstance(createSimpleOption("test2", false)));
- assertNull(CmdLineUtils.findSpecifiedPrintSupportedActionsOption(options));
+ assertNull(findSpecifiedPrintSupportedActionsOption(options));
options.add(psaAction);
assertEquals(psaAction,
- CmdLineUtils.findSpecifiedPrintSupportedActionsOption(options));
+ findSpecifiedPrintSupportedActionsOption(options));
+ options.add(createOptionInstance(new PrintSupportedActionsCmdLineOption(
+ "psa2", "PrintSupportedActions2", "Print Actions 2", false)));
+ try {
+ findSpecifiedPrintSupportedActionsOption(options);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
}
public void testIsSimpleOption() {
@@ -365,10 +375,16 @@ public class TestCmdLineUtils extends Te
createOptionInstance(createSimpleOption("test", false)),
createOptionInstance(createSimpleOption("test", false)));
- assertNull(CmdLineUtils.findSpecifiedActionOption(options));
+ assertNull(findSpecifiedActionOption(options));
options.add(actionOption);
assertEquals(actionOption,
- CmdLineUtils.findSpecifiedActionOption(options));
+ findSpecifiedActionOption(options));
+ options.add(createOptionInstance(createActionOption("action2")));
+ try {
+ findSpecifiedActionOption(options);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
}
public void testIsGroupOption() {
@@ -394,8 +410,7 @@ public class TestCmdLineUtils extends Te
try {
CmdLineUtils.asHelpOption(createSimpleOption("test", false));
fail("Should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException ignore) { /* expect throw */
- }
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
CmdLineUtils.asHelpOption(new HelpCmdLineOption());
}
@@ -416,9 +431,14 @@ public class TestCmdLineUtils extends Te
createOptionInstance(createSimpleOption("test", false)),
createOptionInstance(createSimpleOption("test", false)));
- assertNull(CmdLineUtils.findSpecifiedHelpOption(options));
+ assertNull(findSpecifiedHelpOption(options));
options.add(helpOption);
- assertEquals(helpOption, CmdLineUtils.findSpecifiedHelpOption(options));
+ assertEquals(helpOption, findSpecifiedHelpOption(options));
+ options.add(createOptionInstance(new HelpCmdLineOption("h2", "help2", "Second Help Option", true)));
+ try {
+ findSpecifiedHelpOption(options);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
}
public void testValidate() {