GetJobViewCommand extends AbstractCommand { public static GetJobViewCommand parse(String cmd, ExecutionContext cxt) throws ODPSConsoleException { String regstr = "\\s*wait\\s+jobview([\\s\\S]*)"; Pattern pattern = Pattern.compile(regstr, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(cmd); if (matcher.matches()) { String args = matcher.group(1).replaceAll("\\s+", " ").trim(); return new GetJobViewCommand(cmd, cxt, args.split(" ")); } return null; } GetJobViewCommand(String commandText, ExecutionContext context, String[] args); static void printUsage(PrintStream stream); static GetJobViewCommand parse(String cmd, ExecutionContext cxt); @Override void run(); static final String[] HELP_TAGS; }
@Test public void testParse() { ExecutionContext cxt = new ExecutionContext(); String[] cmds = {"wait 123"}; GetJobViewCommand result; for (String cmd : cmds) { try { result = GetJobViewCommand.parse(cmd, cxt); Assert.assertNull(result); } catch (ODPSConsoleException e) { e.printStackTrace(); System.err.println("should be null. "); } } cmds = new String[]{"wait jobview -i 123"}; result = null; for (String cmd : cmds) { try { result = GetJobViewCommand.parse(cmd, cxt); } catch (ODPSConsoleException e) { e.printStackTrace(); } Assert.assertNotNull(result); } cmds = new String[]{"wait jobview ", "wait jobview -i 123 -wrong wrong"}; for (String cmd : cmds) { try { GetJobViewCommand.parse(cmd, cxt); Assert.fail(cmd + " failed."); } catch (ODPSConsoleException e) { } } result = null; try { String cmd = " wait jobview -i 123"; result = GetJobViewCommand.parse(cmd, cxt); } catch (ODPSConsoleException e) { e.printStackTrace(); } assert result != null; Assert.assertEquals("123", result.getInstanceID()); System.out.println("Pass all tests. "); }