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/10/25 02:49:31 UTC

svn commit: r1188470 - in /oodt/branches/cas-cl/src: main/java/org/apache/oodt/cas/cl/ main/java/org/apache/oodt/cas/cl/option/validator/ test/org/apache/oodt/cas/cl/ test/org/apache/oodt/cas/cl/test/util/

Author: bfoster
Date: Tue Oct 25 00:49:31 2011
New Revision: 1188470

URL: http://svn.apache.org/viewvc?rev=1188470&view=rev
Log:
- unit tested and added javadoc for CmdLineArgs

Added:
    oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java   (with props)
Modified:
    oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
    oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java
    oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java

Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java?rev=1188470&r1=1188469&r2=1188470&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/CmdLineArgs.java Tue Oct 25 00:49:31 2011
@@ -1,14 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.oodt.cas.cl;
 
+//OODT static imports
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.findAction;
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.findActionOption;
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.findHelpOption;
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.findPrintSupportedActionsOption;
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.findSpecifiedOption;
 
+//JDK imports
 import java.util.HashSet;
 import java.util.Set;
 
+//OODT imports
+import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cl.action.CmdLineAction;
 import org.apache.oodt.cas.cl.option.ActionCmdLineOption;
 import org.apache.oodt.cas.cl.option.CmdLineOption;
@@ -16,6 +36,12 @@ import org.apache.oodt.cas.cl.option.Cmd
 import org.apache.oodt.cas.cl.option.HelpCmdLineOption;
 import org.apache.oodt.cas.cl.option.PrintSupportedActionsCmdLineOption;
 
+/**
+ * A convenience class for {@link CmdLineUtility} for helping use already parsed
+ * Command-Line arguments.
+ * 
+ * @author bfoster (Brian Foster)
+ */
 public class CmdLineArgs {
 
 	private CmdLineAction specifiedAction;
@@ -32,7 +58,13 @@ public class CmdLineArgs {
 	private Set<CmdLineOptionInstance> specifiedOptions;
 	private Set<CmdLineOptionInstance> customSpecifiedOptions;
 
-	CmdLineArgs(Set<CmdLineAction> supportedActions, Set<CmdLineOption> supportedOptions, Set<CmdLineOptionInstance> specifiedOptions) {
+	/* package */ CmdLineArgs(Set<CmdLineAction> supportedActions,
+			Set<CmdLineOption> supportedOptions,
+			Set<CmdLineOptionInstance> specifiedOptions) {
+		Validate.notNull(supportedActions);
+		Validate.notNull(supportedOptions);
+		Validate.notNull(specifiedOptions);
+
 		helpOption = findHelpOption(supportedOptions);
 		helpOptionInst = findSpecifiedOption(helpOption, specifiedOptions);
 		actionOption = findActionOption(supportedOptions);
@@ -49,7 +81,8 @@ public class CmdLineArgs {
 
 		this.specifiedOptions = new HashSet<CmdLineOptionInstance>(specifiedOptions);
 
-		customSpecifiedOptions = new HashSet<CmdLineOptionInstance>(specifiedOptions);
+		customSpecifiedOptions = new HashSet<CmdLineOptionInstance>(
+				specifiedOptions);
 		if (helpOptionInst != null) {
 			customSpecifiedOptions.remove(helpOptionInst);
 		}
@@ -61,55 +94,97 @@ public class CmdLineArgs {
 		}
 
 		this.supportedActions = supportedActions;
-		if(actionOptionInst != null) {
+		if (actionOptionInst != null) {
 			specifiedAction = findAction(actionOptionInst, supportedActions);
 		}
 	}
 
+	/**
+	 * @return The {@link HelpCmdLineOption}
+	 */
 	public HelpCmdLineOption getHelpOption() {
 		return helpOption;
 	}
 
+	/**
+	 * @return The {@link CmdLineOptionInstance} which is the specified
+	 *         {@link HelpCmdLineOption}, or null if it was not specified
+	 */
 	public CmdLineOptionInstance getHelpOptionInst() {
 		return helpOptionInst;
 	}
 
+	/**
+	 * @return The {@link ActionCmdLineOption}
+	 */
 	public ActionCmdLineOption getActionOption() {
 		return actionOption;
 	}
 
+	/**
+	 * @return The {@link CmdLineOptionInstance} which is the specified
+	 *         {@link ActionCmdLineOption}, or null if it was not specified
+	 */
 	public CmdLineOptionInstance getActionOptionInst() {
 		return actionOptionInst;
 	}
 
+	/**
+	 * @return The {@link PrintSupportedActionsCmdLineOption}
+	 */
 	public PrintSupportedActionsCmdLineOption getPrintSupportedActionsOption() {
 		return psaOption;
 	}
 
+	/**
+	 * @return The {@link CmdLineOptionInstance} which is the specified
+	 *         {@link PrintSupportedActionsCmdLineOption}, or null if it was not
+	 *         specified
+	 */
 	public CmdLineOptionInstance getPrintSupportedActionsOptionInst() {
 		return psaOptionInst;
 	}
 
+	/**
+	 * @return All supported {@link CmdLineOption}s
+	 */
 	public Set<CmdLineOption> getSupportedOptions() {
 		return supportedOptions;
 	}
 
+	/**
+	 * @return Supported {@link CmdLineOption}s less Help, Action,
+	 *         PrintSupportActions options
+	 */
 	public Set<CmdLineOption> getCustomSupportedOptions() {
 		return customSupportedOptions;
 	}
 
+	/**
+	 * @return All specified {@link CmdLineOptionInstance}s
+	 */
 	public Set<CmdLineOptionInstance> getSpecifiedOptions() {
 		return specifiedOptions;
 	}
 
+	/**
+	 * @return Specified {@link CmdLineOptionInstance}s less Help, Action,
+	 *         PrintSupportedActions option instances
+	 */
 	public Set<CmdLineOptionInstance> getCustomSpecifiedOptions() {
 		return customSpecifiedOptions;
 	}
 
+	/**
+	 * @return All supported {@link CmdLineAction}s
+	 */
 	public Set<CmdLineAction> getSupportedActions() {
 		return supportedActions;
 	}
 
+	/**
+	 * @return The {@link CmdLineAction} which was specified
+	 */
 	public CmdLineAction getSpecifiedAction() {
 		return specifiedAction;
 	}

Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java?rev=1188470&r1=1188469&r2=1188470&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java Tue Oct 25 00:49:31 2011
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.oodt.cas.cl.option.validator;
 
 //JDK imports
@@ -26,8 +25,10 @@ import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
 
 /**
- * @author bfoster
- * @version $Revision$
+ * A {@link CmdLineOptionValidator} which check args against a supplied list of
+ * valid allowed arguments.
+ *
+ * @author bfoster (Brian Foster)
  */
 public class AllowedArgsCmdLineOptionValidator implements
 		CmdLineOptionValidator {

Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java?rev=1188470&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java Tue Oct 25 00:49:31 2011
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.cl;
+
+//Google static imports
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Sets.newHashSet;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createAction;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createActionOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
+//JDK imports
+import java.util.HashSet;
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.cl.action.CmdLineAction;
+import org.apache.oodt.cas.cl.option.ActionCmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cl.option.HelpCmdLineOption;
+import org.apache.oodt.cas.cl.option.PrintSupportedActionsCmdLineOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link CmdLineArgs}.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public class TestCmdLineArgs extends TestCase {
+
+	private final static CmdLineAction TEST_ACTION_1 = createAction("TestAction1");
+	private final static CmdLineAction TEST_ACTION_2 = createAction("TestAction2");
+	private final static CmdLineAction TEST_ACTION_3 = createAction("TestAction3");
+	
+	private final static ActionCmdLineOption ACTION_OPTION = createActionOption("operation");
+	private final static HelpCmdLineOption HELP_OPTION = new HelpCmdLineOption();
+	private final static PrintSupportedActionsCmdLineOption PSA_ACTION = new PrintSupportedActionsCmdLineOption();
+
+	private final static Set<CmdLineAction> SUPPORTED_ACTIONS
+			= newHashSet(TEST_ACTION_1, TEST_ACTION_2, TEST_ACTION_3);
+	private final static Set<CmdLineOption> SUPPORTED_OPTIONS = newHashSet((CmdLineOption) ACTION_OPTION,
+			(CmdLineOption) HELP_OPTION, (CmdLineOption) PSA_ACTION);
+
+	public void testBaseCase() {
+		CmdLineOptionInstance specifiedAction = createOptionInstance(ACTION_OPTION, TEST_ACTION_1.getName());
+		Set<CmdLineOptionInstance> specifiedOptions = newHashSet(specifiedAction);
+		CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, SUPPORTED_OPTIONS,
+				specifiedOptions);
+		assertEquals(TEST_ACTION_1, args.getSpecifiedAction());
+		assertEquals(ACTION_OPTION, args.getActionOption());
+		assertEquals(args.getActionOptionInst(), specifiedAction);
+		assertEquals(HELP_OPTION, args.getHelpOption());
+		assertNull(args.getHelpOptionInst());
+		assertEquals(PSA_ACTION, args.getPrintSupportedActionsOption());
+		assertNull(args.getPrintSupportedActionsOptionInst());
+	}
+
+	public void testCaseActionNotSupported() {
+		CmdLineOptionInstance specifiedAction = createOptionInstance(
+				ACTION_OPTION, "NotSupportedActionName");
+		Set<CmdLineOptionInstance> specifiedOptions = newHashSet(specifiedAction);
+		CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, SUPPORTED_OPTIONS,
+				specifiedOptions);
+
+		// Verify that CmdLineAction is null since it was not able to be located in set of supported actions.
+		assertNull(args.getSpecifiedAction());
+		// Verify that if did find the action option.
+		assertEquals(specifiedAction.getOption(), args.getActionOption());
+		// Verify that if found the specified action even though it is not supported.
+		assertEquals(newArrayList("NotSupportedActionName"), args.getActionOptionInst().getValues());
+	}
+
+	public void testGetCustomOptions() {
+		CmdLineOption customOption = createSimpleOption("test", false);
+		Set<CmdLineOption> options = newHashSet(SUPPORTED_OPTIONS);
+		options.add(customOption);
+		CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
+				new HashSet<CmdLineOptionInstance>());
+
+		// Test that custom supported options only contains the custom option.
+		assertEquals(newHashSet(customOption), args.getCustomSupportedOptions());
+	}
+
+	public void testGetCustomSpecifiedOptions() {
+		CmdLineOption customOption = createSimpleOption("test", false);
+		Set<CmdLineOption> options = newHashSet(SUPPORTED_OPTIONS);
+		options.add(customOption);
+		CmdLineOptionInstance specifiedOptions = createOptionInstance(customOption, "test-values");
+		CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
+				newHashSet(specifiedOptions));
+
+		// Test that custom specified options only contains the custom option.
+		assertEquals(newHashSet(specifiedOptions), args.getCustomSpecifiedOptions());
+
+		args = new CmdLineArgs(SUPPORTED_ACTIONS, options,
+				new HashSet<CmdLineOptionInstance>());
+
+		// Test that custom specified options is empty since custom option was not specified.
+		assertTrue(args.getCustomSpecifiedOptions().isEmpty());
+	}
+}

Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineArgs.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java?rev=1188470&r1=1188469&r2=1188470&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java (original)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java Tue Oct 25 00:49:31 2011
@@ -36,9 +36,6 @@ import org.apache.oodt.cas.cl.option.val
 //Google imports
 import com.google.common.collect.Lists;
 
-//JUnit imports
-import junit.framework.TestCase;
-
 /**
  * Base Test case for CAS-CL unit tests.
  *