Package org.apache.oodt.cas.cli.action

Examples of org.apache.oodt.cas.cli.action.CmdLineAction


* @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(ActionMessagePrinter printer) {
            // do nothing
         }
View Full Code Here


      // Check that all actions were loaded.
      assertEquals(3, actions.size());

      // Load and verify PrintMessageAction was loaded correctly.
      CmdLineAction action = findAction("PrintMessageAction", actions);
      assertTrue(action instanceof PrintMessageAction);
      PrintMessageAction pma = (PrintMessageAction) action;
      assertEquals("Prints out a given message", pma.getDescription());
      ActionMessagePrinter printer = new ActionMessagePrinter();
      try {
View Full Code Here

* @author bfoster (Brian Foster)
*/
public class TestCmdLineUtils extends TestCase {

   public void testDetermineRequired() {
      CmdLineAction action = createAction("TestAction");
      CmdLineOption urlOption, passOption, actionOption;

      HashSet<CmdLineOption> options = Sets.newHashSet(
            urlOption = createSimpleOption("url",
                  createRequiredRequirementRule(action)),
View Full Code Here

      assertEquals(Sets.newHashSet(urlOption, passOption, actionOption),
            requiredOptions);
   }

   public void testIsRequired() {
      CmdLineAction action = createAction("TestAction");
      assertTrue(CmdLineUtils.isRequired(action,
            createSimpleOption("url", createRequiredRequirementRule(action))));
      assertTrue(CmdLineUtils.isRequired(action,
            createSimpleOption("url", true)));
      assertFalse(CmdLineUtils.isRequired(action,
View Full Code Here

      assertFalse(CmdLineUtils.isRequired(action,
            createSimpleOption("url", false)));
   }

   public void testDetermineOptional() {
      CmdLineAction action = createAction("TestAction");
      CmdLineOption actionOption = new ActionCmdLineOption();
      CmdLineOption passOption, userOption;

      HashSet<CmdLineOption> options = Sets.newHashSet(
            createSimpleOption("url", createRequiredRequirementRule(action)),
View Full Code Here

      optionalOptions = CmdLineUtils.determineOptional(action, options);
      assertEquals(Sets.newHashSet(passOption, userOption), optionalOptions);
   }

   public void testIsOptional() {
      CmdLineAction action = createAction("TestAction");
      assertTrue(CmdLineUtils.isOptional(action,
            createSimpleOption("url", createOptionalRequirementRule(action))));
      assertFalse(CmdLineUtils.isOptional(action,
            createSimpleOption("url", true)));
      assertTrue(CmdLineUtils.isOptional(action,
View Full Code Here

      assertEquals(Sets.newHashSet(actionOption, urlOption),
            CmdLineUtils.getRequiredOptions(options, false));
   }

   public void testSortOptionsByRequiredStatus() {
      CmdLineAction action = createAction("action");
      CmdLineOption userOption, urlOption, passOption, actionOption;
      HashSet<CmdLineOption> options = Sets.newHashSet(
            userOption = createSimpleOption("user", false),
            urlOption = createSimpleOption("url",
                  createRequiredRequirementRule(action)),
View Full Code Here

      assertEquals("Tom", sortedActions.get(2).getName());
      assertEquals("Young", sortedActions.get(3).getName());
   }

   public void testGetOptionByName() {
      CmdLineAction action = createAction("action");
      CmdLineOption userOption, urlOption, passOption, actionOption;
      HashSet<CmdLineOption> options = Sets.newHashSet(
            userOption = createSimpleOption("user", "username", false),
            urlOption = createSimpleOption("u", "url",
                  createRequiredRequirementRule(action)),
View Full Code Here

      assertEquals(actionOption,
            CmdLineUtils.getOptionByName(actionOption.getLongOption(), options));
   }

   public void testGetOptionInstanceByName() {
      CmdLineAction action = createAction("action");
      CmdLineOptionInstance userOptionInst, urlOptionInst, passOptionInst, actionOptionInst;
      HashSet<CmdLineOptionInstance> optionInsts = Sets.newHashSet(
            userOptionInst = new CmdLineOptionInstance(createSimpleOption(
                  "user", "username", false), new ArrayList<String>()),
            urlOptionInst = new CmdLineOptionInstance(createSimpleOption("u",
View Full Code Here

      // Test case pass.
      assertTrue(determineFailedValidation(validate(createOptionInstance(option, "value"))).isEmpty());
   }

   public void testHandle() {
      CmdLineAction action = createAction("testAction");
      action.setDescription("test description");
      AdvancedCmdLineOption option = new AdvancedCmdLineOption("t", "test", "",
            true);
      // Insure runs with no errors when action doesn't have a handler.
      CmdLineUtils.handle(action, createOptionInstance(option));

      // Test case when option has a handler.
      option.setHandler(new CmdLineOptionHandler() {
         @Override
         public void initialize(CmdLineOption option) {}

         @Override
         public void handleOption(CmdLineAction selectedAction,
               CmdLineOptionInstance optionInstance) {
            selectedAction.setDescription("handler modified description");
         }

         @Override
         public String getHelp(CmdLineOption option) {
            return null;
         }

         @Override
         public String getArgDescription(CmdLineAction action,
               CmdLineOption option) {
            return null;
         }
      });
      CmdLineUtils.handle(action, createOptionInstance(option));
      assertEquals("handler modified description", action.getDescription());
   }
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.cli.action.CmdLineAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.