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/21 07:57:15 UTC
svn commit: r1187187 - in /oodt/branches/cas-cl/src:
main/java/org/apache/oodt/cas/cl/option/validator/
test/org/apache/oodt/cas/cl/option/
test/org/apache/oodt/cas/cl/option/validator/
test/org/apache/oodt/cas/cl/test/ test/org/apache/oodt/cas/cl/test...
Author: bfoster
Date: Fri Oct 21 05:57:14 2011
New Revision: 1187187
URL: http://svn.apache.org/viewvc?rev=1187187&view=rev
Log:
- Added unit tests for CmdLineOptionValidators
- Factored out helper methods in TestCmdLineUtils into a TestUtils helper class
Added:
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java (with props)
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java (with props)
Modified:
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/AllowedArgsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java
oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java
oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java
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=1187187&r1=1187186&r2=1187187&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 Fri Oct 21 05:57:14 2011
@@ -22,6 +22,7 @@ import java.util.LinkedList;
import java.util.List;
//OODT imports
+import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
@@ -38,6 +39,8 @@ public class AllowedArgsCmdLineOptionVal
}
public boolean validate(CmdLineOptionInstance optionInst) {
+ Validate.notNull(optionInst);
+
for (String value : optionInst.getValues()) {
if (!allowedArgs.contains(value)) {
LOG.severe("Option value " + value + " is not allowed for option "
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java?rev=1187187&r1=1187186&r2=1187187&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ArgRegExpCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -14,32 +14,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.cl.option.validator;
//JDK imports
import java.util.regex.Pattern;
//OODT imports
+import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- * @author bfoster
- * @version $Revision$
+ * Performs validation on option instances via allowed args which are regular
+ * expressions for allowed argument values.
+ *
+ * @author bfoster (Brian Foster)
*/
public class ArgRegExpCmdLineOptionValidator extends
AllowedArgsCmdLineOptionValidator {
@Override
public boolean validate(CmdLineOptionInstance optionInst) {
- TOP: for (String value : optionInst.getValues()) {
- for (String regex : this.getAllowedArgs()) {
- if (Pattern.matches(regex, value))
+ Validate.notNull(optionInst);
+
+ TOP:
+ for (String value : optionInst.getValues()) {
+ for (String regex : getAllowedArgs()) {
+ if (Pattern.matches(regex, value)) {
continue TOP;
+ }
}
- LOG.severe("Option value " + value + " is not allowed for option "
+ LOG.severe("Option1 value " + value + " is not allowed for option "
+ optionInst.getOption().getLongOption() + " - Allowed values = "
- + this.getAllowedArgs());
+ + getAllowedArgs());
return false;
}
return true;
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java?rev=1187187&r1=1187186&r2=1187187&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/ClassExistsCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -14,20 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.cl.option.validator;
//OODT imports
+import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- * @author bfoster
- * @version $Revision$
+ * Validates arguments which are checked to see if they are valid classpaths.
+ *
+ * @author bfoster (Brian Foster)
*/
public class ClassExistsCmdLineOptionValidator implements
CmdLineOptionValidator {
public boolean validate(CmdLineOptionInstance optionInst) {
+ Validate.notNull(optionInst);
+
for (String value : optionInst.getValues()) {
try {
Class.forName(value);
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java?rev=1187187&r1=1187186&r2=1187187&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/FileExistCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -14,22 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.oodt.cas.cl.option.validator;
//JDK imports
import java.io.File;
//OODT imports
+import org.apache.commons.lang.Validate;
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- * @author bfoster
- * @version $Revision$
+ * A {@link CmdLineOptionValidator} which checks args if they are existing files.
+ *
+ * @author bfoster (Brian Foster)
*/
public class FileExistCmdLineOptionValidator implements CmdLineOptionValidator {
public boolean validate(CmdLineOptionInstance optionInst) {
+ Validate.notNull(optionInst);
+
for (String value : optionInst.getValues()) {
if (!new File(value).exists()) {
LOG.severe("Option value " + value + " for option "
Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java?rev=1187187&r1=1187186&r2=1187187&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/validator/NoRestrictionsCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -20,9 +20,9 @@ package org.apache.oodt.cas.cl.option.va
import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
/**
- *
- * @author bfoster
- * @version $Revision$
+ * A {@link CmdLineOptionValidator} which always returns true.
+ *
+ * @author bfoster (Brian Foster)
*/
public class NoRestrictionsCmdLineOptionValidator implements
CmdLineOptionValidator {
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java?rev=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.validator;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * Test class for {@link AllowedArgsCmdLineOptionValidator}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestAllowedArgsCmdLineOptionValidator extends TestCase {
+
+ public void testIntialState() {
+ // Test no null option instance allowed.
+ try {
+ new AllowedArgsCmdLineOptionValidator().validate(null);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Test no allowed args set and valid option instance
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "value");
+ assertFalse(new AllowedArgsCmdLineOptionValidator().validate(instance));
+ }
+
+ public void testValidate() {
+ AllowedArgsCmdLineOptionValidator validator = new AllowedArgsCmdLineOptionValidator();
+ validator.setAllowedArgs(Lists.newArrayList("value1", "value2"));
+
+ // Test no null option instance allowed.
+ try {
+ validator.validate(null);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Test should fail case.
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "value");
+ assertFalse(validator.validate(instance));
+
+ // Test should pass case.
+ instance = createOptionInstance(createSimpleOption("test", false), "value1");
+ assertTrue(validator.validate(instance));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestAllowedArgsCmdLineOptionValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java?rev=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -0,0 +1,71 @@
+/*
+ * 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.validator;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * Test class for {@link ArgRegExpCmdLineOptionValidator}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestArgRegExpCmdLineOptionValidator extends TestCase {
+
+ public void testInitialCase() {
+ // Test null option instancd not allowed.
+ try {
+ new ArgRegExpCmdLineOptionValidator().validate(null);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Test no allowed args set and valid option instance
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "value");
+ assertFalse(new AllowedArgsCmdLineOptionValidator().validate(instance));
+ }
+
+ public void testValidate() {
+ ArgRegExpCmdLineOptionValidator validator = new ArgRegExpCmdLineOptionValidator();
+ validator.setAllowedArgs(Lists.newArrayList("v.*?1", "v.*?2"));
+
+ // Test no null option instance allowed.
+ try {
+ validator.validate(null);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Test should fail case.
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "value");
+ assertFalse(validator.validate(instance));
+
+ // Test should pass case.
+ instance = createOptionInstance(createSimpleOption("test", false), "value1");
+ assertTrue(validator.validate(instance));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestArgRegExpCmdLineOptionValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java?rev=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.validator;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+/**
+ * Test class for {@link ClassExistsCmdLineOptionValidator}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestClassExistsCmdLineOptionValidator extends TestCase {
+
+ public void testValidate() {
+ // Check null option instance not allowed.
+ try {
+ new ClassExistsCmdLineOptionValidator().validate(null);
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Check fail case.
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "bogus");
+ assertFalse(new ClassExistsCmdLineOptionValidator().validate(instance));
+
+ // Check pass case.
+ instance = createOptionInstance(
+ createSimpleOption("test", false), "java.lang.String");
+ assertTrue(new ClassExistsCmdLineOptionValidator().validate(instance));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestClassExistsCmdLineOptionValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java?rev=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java Fri Oct 21 05:57:14 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.validator;
+
+//OODT static imports
+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.io.File;
+import java.io.IOException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+/**
+ * Test class for {@link FileExistCmdLineOptionValidator}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestFileExistCmdLineOptionValidator extends TestCase {
+
+ public void testValidate() throws IOException {
+ // Test null option instance not allowed.
+ try {
+ new FileExistCmdLineOptionValidator().validate(null);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ignore) { /* expect throw */ }
+
+ // Test fail case.
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "bogus");
+ assertFalse(new FileExistCmdLineOptionValidator().validate(instance));
+
+ // Test pass case.
+ File tempFile = File.createTempFile("bogus", "bogus");
+ tempFile.deleteOnExit();
+ instance = createOptionInstance(
+ createSimpleOption("test", false), tempFile.getAbsolutePath());
+ assertTrue(new FileExistCmdLineOptionValidator().validate(instance));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestFileExistCmdLineOptionValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java?rev=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java Fri Oct 21 05:57:14 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.validator;
+
+//OODT static imports
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+
+/**
+ * Test class for {@link NoRestrictionsCmdLineOptionValidator}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestNoRestrictionsCmdLineOptionValidator extends TestCase {
+
+ public void testValidate() {
+ // Test pass for null option instance.
+ assertTrue(new NoRestrictionsCmdLineOptionValidator().validate(null));
+
+ // Test pass for not null option instance.
+ CmdLineOptionInstance instance = createOptionInstance(
+ createSimpleOption("test", false), "bogus");
+ assertTrue(new NoRestrictionsCmdLineOptionValidator().validate(instance));
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/option/validator/TestNoRestrictionsCmdLineOptionValidator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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=1187187&view=auto
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java (added)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java Fri Oct 21 05:57:14 2011
@@ -0,0 +1,132 @@
+/*
+ * 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.test.util;
+
+//JDK imports
+import java.util.Collections;
+
+//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.AdvancedCmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
+import org.apache.oodt.cas.cl.option.GroupCmdLineOption;
+import org.apache.oodt.cas.cl.option.SimpleCmdLineOption;
+import org.apache.oodt.cas.cl.option.require.ActionDependency;
+import org.apache.oodt.cas.cl.option.require.RequirementRule;
+import org.apache.oodt.cas.cl.option.require.StdRequirementRule;
+import org.apache.oodt.cas.cl.option.require.RequirementRule.Relation;
+import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Base Test case for CAS-CL unit tests.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestUtils {
+
+ public static CmdLineAction createAction(String name) {
+ return new CmdLineAction(name, "This is an action description") {
+
+ @Override
+ public void execute() {
+ // do nothing
+ }
+
+ };
+ }
+
+ public static GroupCmdLineOption createGroupOption(String longName,
+ boolean required) {
+ GroupCmdLineOption option = new GroupCmdLineOption();
+ option.setLongOption(longName);
+ option.setShortOption(longName);
+ option.setRequired(required);
+ return option;
+ }
+
+ public static SimpleCmdLineOption createSimpleOption(String longName,
+ boolean required) {
+ return createSimpleOption(longName, longName, required);
+ }
+
+ public static SimpleCmdLineOption createSimpleOption(String shortName,
+ String longName, boolean required) {
+ SimpleCmdLineOption option = new SimpleCmdLineOption();
+ option.setShortOption(shortName);
+ option.setLongOption(longName);
+ option.setRequired(required);
+ return option;
+ }
+
+ public static SimpleCmdLineOption createSimpleOption(String longName,
+ RequirementRule rule) {
+ return createSimpleOption(longName, longName, rule);
+ }
+
+ public static SimpleCmdLineOption createSimpleOption(String shortName,
+ String longName, RequirementRule rule) {
+ SimpleCmdLineOption option = new SimpleCmdLineOption();
+ option.setShortOption(shortName);
+ option.setLongOption(longName);
+ option.setRequirementRules(Collections.singletonList(rule));
+ return option;
+ }
+
+ public static AdvancedCmdLineOption createValidationOption(String longName, CmdLineOptionValidator... validators) {
+ AdvancedCmdLineOption option = new AdvancedCmdLineOption();
+ option.setLongOption(longName);
+ option.setShortOption(longName);
+ option.setValidators(Lists.newArrayList(validators));
+ return option;
+ }
+
+ public static ActionCmdLineOption createActionOption(String longName) {
+ ActionCmdLineOption option = new ActionCmdLineOption();
+ option.setLongOption(longName);
+ option.setShortOption(longName);
+ return option;
+ }
+
+ public static CmdLineOptionInstance createOptionInstance(
+ CmdLineOption option, String... values) {
+ return new CmdLineOptionInstance(option, Lists.newArrayList(values));
+ }
+
+ public static RequirementRule createRequiredRequirementRule(
+ CmdLineAction action) {
+ StdRequirementRule rule = new StdRequirementRule();
+ rule.addActionDependency(new ActionDependency(action.getName(),
+ Relation.REQUIRED));
+ return rule;
+ }
+
+ public static RequirementRule createOptionalRequirementRule(
+ CmdLineAction action) {
+ StdRequirementRule rule = new StdRequirementRule();
+ rule.addActionDependency(new ActionDependency(action.getName(),
+ Relation.OPTIONAL));
+ return rule;
+ }
+}
Propchange: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/test/util/TestUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java?rev=1187187&r1=1187186&r2=1187187&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java (original)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java Fri Oct 21 05:57:14 2011
@@ -16,9 +16,17 @@
*/
package org.apache.oodt.cas.cl.util;
+//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.createGroupOption;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionInstance;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createOptionalRequirementRule;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createRequiredRequirementRule;
+import static org.apache.oodt.cas.cl.test.util.TestUtils.createSimpleOption;
+
//JDK imports
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -38,10 +46,6 @@ import org.apache.oodt.cas.cl.option.Hel
import org.apache.oodt.cas.cl.option.PrintSupportedActionsCmdLineOption;
import org.apache.oodt.cas.cl.option.SimpleCmdLineOption;
import org.apache.oodt.cas.cl.option.handler.CmdLineOptionHandler;
-import org.apache.oodt.cas.cl.option.require.RequirementRule;
-import org.apache.oodt.cas.cl.option.require.RequirementRule.Relation;
-import org.apache.oodt.cas.cl.option.require.StdRequirementRule;
-import org.apache.oodt.cas.cl.option.require.ActionDependency;
import org.apache.oodt.cas.cl.option.validator.AllowedArgsCmdLineOptionValidator;
import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
import org.apache.oodt.cas.cl.util.CmdLineUtils;
@@ -448,80 +452,4 @@ public class TestCmdLineUtils extends Te
assertNull(CmdLineUtils.findAction(createOptionInstance(createActionOption("action"), "TestAction"), actions));
assertEquals(action, CmdLineUtils.findAction(createOptionInstance(createActionOption("action"), "TestAction1"), actions));
}
-
- private static CmdLineAction createAction(String name) {
- return new CmdLineAction(name, "This is an action description") {
-
- @Override
- public void execute() {
- // do nothing
- }
-
- };
- }
-
- private static GroupCmdLineOption createGroupOption(String longName,
- boolean required) {
- GroupCmdLineOption option = new GroupCmdLineOption();
- option.setLongOption(longName);
- option.setShortOption(longName);
- option.setRequired(required);
- return option;
- }
-
- private static SimpleCmdLineOption createSimpleOption(String longName,
- boolean required) {
- return createSimpleOption(longName, longName, required);
- }
-
- private static SimpleCmdLineOption createSimpleOption(String shortName,
- String longName, boolean required) {
- SimpleCmdLineOption option = new SimpleCmdLineOption();
- option.setShortOption(shortName);
- option.setLongOption(longName);
- option.setRequired(required);
- return option;
- }
-
- private static SimpleCmdLineOption createSimpleOption(String longName,
- RequirementRule rule) {
- return createSimpleOption(longName, longName, rule);
- }
-
- private static SimpleCmdLineOption createSimpleOption(String shortName,
- String longName, RequirementRule rule) {
- SimpleCmdLineOption option = new SimpleCmdLineOption();
- option.setShortOption(shortName);
- option.setLongOption(longName);
- option.setRequirementRules(Collections.singletonList(rule));
- return option;
- }
-
- public static ActionCmdLineOption createActionOption(String longName) {
- ActionCmdLineOption option = new ActionCmdLineOption();
- option.setLongOption(longName);
- option.setShortOption(longName);
- return option;
- }
-
- public static CmdLineOptionInstance createOptionInstance(
- CmdLineOption option, String... values) {
- return new CmdLineOptionInstance(option, Lists.newArrayList(values));
- }
-
- private static RequirementRule createRequiredRequirementRule(
- CmdLineAction action) {
- StdRequirementRule rule = new StdRequirementRule();
- rule.addActionDependency(new ActionDependency(action.getName(),
- Relation.REQUIRED));
- return rule;
- }
-
- private static RequirementRule createOptionalRequirementRule(
- CmdLineAction action) {
- StdRequirementRule rule = new StdRequirementRule();
- rule.addActionDependency(new ActionDependency(action.getName(),
- Relation.OPTIONAL));
- return rule;
- }
}