ExternalProjectCommand extends AbstractCommand { public static AbstractCommand parse(String cmd, ExecutionContext sessionContext) throws ODPSConsoleException { Matcher m = PATTERN.matcher(cmd); boolean match = m.matches(); if (!match) { return null; } String actionName = m.group(1); String input = m.group(2); String[] inputs = ODPSConsoleUtils.translateCommandline(input); Options options = new Options(); options.addOption(Option.builder(ExternalProjectCommand.NAME_OPTION) .hasArg().required().desc("Project name.").build()); options.addOption(COMMENT_OPTION, true, "Project description."); options.addOption(REF_OPTION, true,"Managed Project refs to."); options.addOption(NAMENODE_OPTION, true, "Hadoop namenode ip and ports."); options.addOption(HMS_OPTION, true,"Hive metastore ip and ports."); options.addOption(DATABASE_OPTION, true, "Hive database name."); options.addOption(VPC_OPTION, true, "Vpc id"); options.addOption(REGION_OPTION, true, "Vpc region."); options.addOption(ACCESS_IP_OPTION, true, "Additional vpc ip need to be accessed"); options.addOption(DFS_NS_OPTION, true, "Hive DFS nameservice."); try { CommandLineParser parser = new DefaultParser(); Action action = new Action(actionName, parser.parse(options, inputs, false)); return new ExternalProjectCommand(action, cmd, sessionContext); } catch (ParseException e) { throw new ODPSConsoleException("Error parsing command", e); } } private  ExternalProjectCommand(Action action, String commandText, ExecutionContext context); Action getAction(); static void printUsage(PrintStream stream); static AbstractCommand parse(String cmd, ExecutionContext sessionContext); static final String[] HELP_TAGS; }
@Test public void testInvalidCommand() { for (Map.Entry<String,String> cmd: invalidCommands.entrySet()) { try { ExternalProjectCommand.parse(cmd.getKey(), ExecutionContext.init()); Assert.fail("Exception expected for command: " + cmd.getKey()); } catch (IllegalArgumentException err) { Assert.assertTrue(err.getMessage().contains(cmd.getValue())); } catch (ODPSConsoleException conErr) { ParseException parseErr = (ParseException)(conErr.getCause()); Assert.assertTrue(parseErr.getMessage().contains(cmd.getValue())); } } }
@Test public void testNotExternalCommand() throws Exception { for (String cmd: nullCommands) { Assert.assertNull(ExternalProjectCommand.parse(cmd, ExecutionContext.init())); } }