Package org.apache.oodt.cas.cli.option

Examples of org.apache.oodt.cas.cli.option.AdvancedCmdLineOption


      return createAdvancedOption(longName, longName, handler);
   }

   public static AdvancedCmdLineOption createAdvancedOption(String shortName,
         String longName, CmdLineOptionHandler handler) {
      AdvancedCmdLineOption option = new AdvancedCmdLineOption();
      option.setShortOption(shortName);
      option.setLongOption(longName);
      option.setHandler(handler);
      return option;
   }
View Full Code Here


      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;
   }
View Full Code Here

      PrintMessageAction action = new PrintMessageAction();
      action.setName("PrintMessageAction");

      assertNull(action.getMessage());

      AdvancedCmdLineOption option = new AdvancedCmdLineOption();
      option.setLongOption("message");
      option.setHandler(handler);
      option.getHandler().handleOption(action,
            createOptionInstance(option, "Howdy"));

      assertEquals("Howdy", action.getMessage());
   }
View Full Code Here

   }

   public void testApplyToActionsMapping() {
      PrintMessageAction action = new PrintMessageAction();
      action.setName("PrintMessageAction");
      AdvancedCmdLineOption option = createAdvancedOption("printMessage",
            createApplyToActionHandler(action.getName(), "setMessage"));
      option.getHandler().handleOption(action,
            createOptionInstance(option, "Howdy"));

      assertEquals("Howdy", action.getMessage());
   }
View Full Code Here

   }

   public void testSetOrAddInvoke() {
      TestCmdLineAction action = new TestCmdLineAction();
      action.setName("TestAction");
      AdvancedCmdLineOption option = createAdvancedOption("message",
            createApplyToActionHandler(action.getName(), null));

      // Test that default isRepeating() is false.
      option.getHandler().handleOption(action,
            createOptionInstance(option, "Howdy"));
      assertEquals(TestCmdLineAction.CallType.SET, action.getCallType());

      // Test when isRepeating() is set to false.
      option.setRepeating(false);
      option.getHandler().handleOption(action,
            createOptionInstance(option, "Howdy"));
      assertEquals(TestCmdLineAction.CallType.SET, action.getCallType());

      // Test when isRepeating() is set to true.
      option.setRepeating(true);
      option.getHandler().handleOption(action,
            createOptionInstance(option, "Howdy"));
      assertEquals(TestCmdLineAction.CallType.ADD, action.getCallType());
   }
View Full Code Here

      assertEquals(2, options.size());

      // Load and verify printHelloWorld was loaded correctly.
      CmdLineOption option = getOptionByName("printHelloWorld", options);
      assertTrue(option instanceof AdvancedCmdLineOption);
      AdvancedCmdLineOption advancedOption = (AdvancedCmdLineOption) option;
      assertEquals("phw", advancedOption.getShortOption());
      assertEquals("printHelloWorld", advancedOption.getLongOption());
      assertEquals("Print Hello World", advancedOption.getDescription());
      assertFalse(advancedOption.hasArgs());
      assertEquals(1, advancedOption.getStaticArgs().size());
      assertEquals("Hello World!", advancedOption.getStaticArgs().get(0));
      assertEquals(1, advancedOption.getRequirementRules().size());
      assertEquals("PrintMessageAction", ((ActionDependencyRule) advancedOption
            .getRequirementRules().get(0)).getActionName());
      assertEquals(Relation.OPTIONAL, ((ActionDependencyRule) advancedOption
            .getRequirementRules().get(0)).getRelation());

      // Load and verify printMessage was loaded correctly.
      option = getOptionByName("printMessage", options);
      assertTrue(option instanceof AdvancedCmdLineOption);
      advancedOption = (AdvancedCmdLineOption) option;
      assertEquals("pm", advancedOption.getShortOption());
      assertEquals("printMessage", advancedOption.getLongOption());
      assertEquals("Message to print out", advancedOption.getDescription());
      assertEquals(true, advancedOption.hasArgs());
      assertEquals("message", advancedOption.getArgsDescription());
      assertEquals(1, advancedOption.getRequirementRules().size());
      assertEquals("PrintMessageAction", ((ActionDependencyRule) advancedOption
            .getRequirementRules().get(0)).getActionName());
      assertEquals(Relation.REQUIRED, ((ActionDependencyRule) advancedOption
            .getRequirementRules().get(0)).getRelation());
      assertNotNull(advancedOption.getHandler());
      assertTrue(advancedOption.getHandler() instanceof ApplyToActionHandler);
      assertEquals(1, ((ApplyToActionHandler) advancedOption.getHandler())
            .getApplyToActions().size());
      assertEquals(findAction("PrintMessageAction", actions).getName(),
            ((ApplyToActionHandler) advancedOption.getHandler())
                  .getApplyToActions().get(0).getActionName());
      assertEquals("setMessage",
            ((ApplyToActionHandler) advancedOption.getHandler())
                  .getApplyToActions().get(0).getMethodName());
   }
View Full Code Here

      Set<CmdLineAction> actions = actionStore.loadSupportedActions();

      // Load PrintHelloWorldAction
      PrintMessageAction printHelloWorldAction = (PrintMessageAction) findAction(
            "PrintMessageAction", actions);
      AdvancedCmdLineOption printHelloWorldOption = (AdvancedCmdLineOption) getOptionByName(
            "printHelloWorld", options);
      printHelloWorldOption.getHandler().handleOption(printHelloWorldAction,
            createOptionInstance(printHelloWorldOption));
      ActionMessagePrinter printer = new ActionMessagePrinter();
      printHelloWorldAction.execute(printer);
      assertEquals(1, printer.getPrintedMessages().size());
      assertEquals("Hello World!", printer.getPrintedMessages().get(0));
View Full Code Here

      assertEquals(1, CmdLineUtility.validate(args).size());
      assertEquals(Result.Grade.PASS, CmdLineUtility.validate(args).get(0)
            .getGrade());

      // 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.
      assertFalse(determineFailedValidation(validate(args)).isEmpty());
   }
View Full Code Here

      // 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"));
View Full Code Here

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

   public void testHandleOption() {
      AdvancedCmdLineOption option = new AdvancedCmdLineOption();
      option.setShortOption("t");
      option.setLongOption("test");
      option.setHasArgs(true);

      // Test 1 value specified.
      CmdLineOptionInstance instance = new CmdLineOptionInstance(
            option, Lists.newArrayList("value"));
      CrawlerBeansPropHandler handler = new CrawlerBeansPropHandler();
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.cli.option.AdvancedCmdLineOption

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.