ExecuteScriptCommand extends MultiClusterCommandBase { public static ExecuteScriptCommand parse(List<String> optionList, ExecutionContext sessionContext) throws ODPSConsoleException { String option = "-s"; if (optionList.contains(option)) { if (optionList.indexOf(option) + 1 < optionList.size()) { int index = optionList.indexOf(option); String filename = optionList.get(index + 1); optionList.remove(optionList.indexOf(option)); optionList.remove(optionList.indexOf(filename)); String cmd = FileUtil.getStringFromFile(filename); if (!cmd.trim().equals("")) { return new ExecuteScriptCommand(cmd, sessionContext, new File(filename).getAbsolutePath()); } } } return null; } ExecuteScriptCommand(String commandText, ExecutionContext context, String filename); String getFilename(); @Override void run(); static ExecuteScriptCommand parse(List<String> optionList, ExecutionContext sessionContext);  }
@Test public void testNegative() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); ExecuteScriptCommand command = null; List<String> options = new ArrayList<String>(); options.add("-f"); options.add(ODPSConsoleUtils.getConfigFilePath()); command = ExecuteScriptCommand.parse(options, context); Assert.assertNull(command); }
@Test(expected = ODPSConsoleException.class) public void testFileNotExsit() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); ExecuteScriptCommand command = null; List<String> options = new ArrayList<String>(); options.add("-s"); options.add("test_file"); ExecuteScriptCommand.parse(options, context); }