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/31 23:05:12 UTC
svn commit: r1195696 - in /oodt/branches/cas-cl/src:
main/java/org/apache/oodt/cas/cl/option/
main/java/org/apache/oodt/cas/cl/option/handler/
test/org/apache/oodt/cas/cl/ test/org/apache/oodt/cas/cl/option/handler/
Author: bfoster
Date: Mon Oct 31 22:05:11 2011
New Revision: 1195696
URL: http://svn.apache.org/viewvc?rev=1195696&view=rev
Log:
- last few changes and unit-test additions before changing to cas-cli
Added:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java (with props)
Modified:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java?rev=1195696&r1=1195695&r2=1195696&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/AdvancedCmdLineOption.java Mon Oct 31 22:05:11 2011
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.List;
//OODT imports
+import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.handler.CmdLineOptionHandler;
import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
@@ -72,7 +73,15 @@ public class AdvancedCmdLineOption exten
return this.validators;
}
+ public void addValidator(CmdLineOptionValidator validator) {
+ Validate.notNull(validator);
+
+ validators.add(validator);
+ }
+
public void setValidators(List<CmdLineOptionValidator> validators) {
+ Validate.notNull(validators);
+
this.validators = validators;
}
Added: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java?rev=1195696&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java (added)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java Mon Oct 31 22:05:11 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.option.handler;
+
+//JDK imports
+import java.util.List;
+
+//Apache imports
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
+
+//OODT imports
+import org.apache.oodt.cas.cl.action.CmdLineAction;
+import org.apache.oodt.cas.cl.option.CmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+/**
+ * {@link CmdLineOptionHandler} which sets Java Properties equals to the
+ * values specified by the {@link CmdLineOption} this handler is attached
+ * to.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class SetJavaPropertiesHandler implements CmdLineOptionHandler {
+
+ private List<String> propertyNames;
+
+ public void handleOption(CmdLineAction selectedAction,
+ CmdLineOptionInstance optionInstance) {
+ Validate.notNull(propertyNames);
+
+ for (String propertyName : propertyNames) {
+ System.setProperty(propertyName,
+ StringUtils.join(optionInstance.getValues(),
+ optionInstance.getOption().getType().equals(List.class) ?
+ "," : " "));
+ }
+ }
+
+ public String getHelp(CmdLineOption option) {
+ return "Sets the following Java Properties: " + this.propertyNames;
+ }
+
+ public void setPropertyNames(List<String> propertyNames) {
+ this.propertyNames = propertyNames;
+ }
+
+ public List<String> getPropertyNames() {
+ return propertyNames;
+ }
+}
Propchange: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/SetJavaPropertiesHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java?rev=1195696&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java Mon Oct 31 22:05:11 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;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createActionOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createAdvancedOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createApplyToActionHandler;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.util.CmdLineUtils.getOptionByName;
+
+//JDK imports
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.cl.action.CmdLineAction;
+import org.apache.oodt.cas.cl.action.PrintMessageAction;
+import org.apache.oodt.cas.cl.option.AdvancedCmdLineOption;
+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;
+import org.apache.oodt.cas.cl.option.validator.ArgRegExpCmdLineOptionValidator;
+import org.apache.oodt.cas.cl.test.util.TestUtils;
+
+//Google imports
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link CmdLineUtility}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestCmdLineUtility extends TestCase {
+
+ public void testCheck() {
+ CmdLineArgs args = getArgs();
+
+ // Expect pass.
+ assertEquals(0, CmdLineUtility.check(args).size());
+
+ // Expect fail.
+ args.getCustomSupportedOptions().add(
+ TestUtils.createSimpleOption("ReqTestAction", true));
+ assertEquals(1, CmdLineUtility.check(args).size());
+ }
+
+ public void testValidate() {
+ CmdLineArgs args = getArgs();
+
+ // Expect pass.
+ assertEquals(0, CmdLineUtility.validate(args).size());
+
+ // Add validator which will cause fail.
+ AdvancedCmdLineOption option = (AdvancedCmdLineOption) getOptionByName("message", args.getSupportedOptions());
+ ArgRegExpCmdLineOptionValidator validator = new ArgRegExpCmdLineOptionValidator();
+ validator.setAllowedArgs(Lists.newArrayList("\\d{1,2}"));
+ option.addValidator(validator);
+
+ // Expect fail.
+ assertEquals(1, CmdLineUtility.validate(args).size());
+ }
+
+ public void testHandle() {
+ CmdLineArgs args = getArgs();
+
+ // Verify handling works.
+ PrintMessageAction action = (PrintMessageAction) args
+ .getSpecifiedAction();
+ assertNull(action.getMessage());
+ CmdLineUtility.handle(args);
+ assertEquals("Test Message", action.getMessage());
+ }
+
+ private CmdLineArgs getArgs() {
+ // Setup Supported Actions.
+ String actionName = "TestAction";
+ PrintMessageAction action = new PrintMessageAction();
+ action.setName(actionName);
+ Set<CmdLineAction> actions = Sets.newHashSet((CmdLineAction) action);
+
+ // Setup Supported Options.
+ Set<CmdLineOption> options = Sets.newHashSet();
+ options.add(new HelpCmdLineOption());
+ options.add(new PrintSupportedActionsCmdLineOption());
+ options.add(createActionOption("action"));
+ AdvancedCmdLineOption option = createAdvancedOption("message",
+ createApplyToActionHandler(actionName, "setMessage"));
+ ArgRegExpCmdLineOptionValidator validator = new ArgRegExpCmdLineOptionValidator();
+ validator.setAllowedArgs(Lists.newArrayList(".*"));
+ option.addValidator(validator);
+ options.add(option);
+
+ // Setup Specified Options.
+ Set<CmdLineOptionInstance> specifiedOptions = Sets.newHashSet();
+ specifiedOptions.add(createOptionInstance(option, "Test Message"));
+ specifiedOptions.add(createOptionInstance(createActionOption("action"),
+ "TestAction"));
+
+ // Setup CmdLineArgs.
+ return new CmdLineArgs(actions, options, specifiedOptions);
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/TestCmdLineUtility.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java?rev=1195696&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java Mon Oct 31 22:05:11 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.option.handler;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createAdvancedOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+
+//JDK imports
+import java.util.List;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * Test class for {@link SetJavaPropertiesHandler}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestSetJavaPropertiesHandler extends TestCase {
+
+ public void testSettingOfProperties() {
+ String property = "test.property";
+ SetJavaPropertiesHandler handler = new SetJavaPropertiesHandler();
+ handler.setPropertyNames(Lists.newArrayList(property));
+ CmdLineOption option = createAdvancedOption("testOption", handler);
+ CmdLineOptionInstance optionInstance = createOptionInstance(option, "Hello", "World");
+
+ assertNull(System.getProperty(property));
+
+ handler.handleOption(null, optionInstance);
+ assertEquals("Hello World", System.getProperty(property));
+
+ option.setType(List.class);
+ handler.handleOption(null, optionInstance);
+ assertEquals("Hello,World", System.getProperty(property));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/handler/TestSetJavaPropertiesHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain