CsvBulkLoadTool extends Configured implements Tool { CommandLine parseOptions(String[] args) { Options options = getOptions(); CommandLineParser parser = new PosixParser(); CommandLine cmdLine = null; try { cmdLine = parser.parse(options, args); } catch (ParseException e) { printHelpAndExit("Error parsing command line options: " + e.getMessage(), options); } if (cmdLine.hasOption(HELP_OPT.getOpt())) { printHelpAndExit(options, 0); } if (!cmdLine.hasOption(TABLE_NAME_OPT.getOpt())) { throw new IllegalStateException(TABLE_NAME_OPT.getLongOpt() + " is a mandatory " + "parameter"); } if (!cmdLine.getArgList().isEmpty()) { throw new IllegalStateException("Got unexpected extra parameters: " + cmdLine.getArgList()); } if (!cmdLine.hasOption(INPUT_PATH_OPT.getOpt())) { throw new IllegalStateException(INPUT_PATH_OPT.getLongOpt() + " is a mandatory " + "parameter"); } return cmdLine; }  static void main(String[] args); @Override int run(String[] args);  }
@Test public void testParseOptions() { CommandLine cmdLine = bulkLoadTool.parseOptions(new String[] { "--input", "/input", "--table", "mytable" }); assertEquals("mytable", cmdLine.getOptionValue(CsvBulkLoadTool.TABLE_NAME_OPT.getOpt())); assertEquals("/input", cmdLine.getOptionValue(CsvBulkLoadTool.INPUT_PATH_OPT.getOpt())); }
@Test(expected=IllegalStateException.class) public void testParseOptions_ExtraArguments() { bulkLoadTool.parseOptions(new String[] { "--input", "/input", "--table", "mytable", "these", "shouldnt", "be", "here" }); }
@Test(expected=IllegalStateException.class) public void testParseOptions_NoInput() { bulkLoadTool.parseOptions(new String[] { "--table", "mytable" }); }
@Test(expected=IllegalStateException.class) public void testParseOptions_NoTable() { bulkLoadTool.parseOptions(new String[] { "--input", "/input" }); }