DescribeProjectCommand extends AbstractCommand { public static AbstractCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; } String[] tokens = new AntlrObject(cmd).getTokenStringArray(); if (tokens.length < 2) { return null; } if (!("DESC".equalsIgnoreCase(tokens[0]) || "DESCRIBE".equalsIgnoreCase(tokens[0]))) { return null; } if (!("PROJECT".equalsIgnoreCase(tokens[1]))) { return null; } CommandLine parser = null; try { parser = new GnuParser().parse(getOptions(), tokens); } catch (ParseException e) { throw new ODPSConsoleException(e.getMessage(), e); } boolean extended = parser.hasOption("extended"); if (parser.getArgList().size() != 3) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } String projectName = parser.getArgs()[2]; return new DescribeProjectCommand(projectName, extended, cmd, ctx); } DescribeProjectCommand(
      String projectName, boolean extended, String cmd, ExecutionContext ctx); static void printUsage(PrintStream stream); static AbstractCommand parse(String cmd, ExecutionContext ctx); @Override void run(); static final String[] HELP_TAGS; }
@Test(expected = ODPSConsoleException.class) public void testDescribeProjectCommandNeg() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); Odps odps = OdpsConnectionFactory.createOdps(context); AbstractCommand command = DescribeProjectCommand.parse("Desc project", context); }
@Test public void testDescribeProjectExtendedCommand() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); Odps odps = OdpsConnectionFactory.createOdps(context); AbstractCommand command = DescribeProjectCommand.parse("Desc project -extended " + odps.getDefaultProject(), context); assertTrue(command instanceof DescribeProjectCommand); command.execute(); }
@Test public void testDescribeProjectExtendedAfterCommand() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); Odps odps = OdpsConnectionFactory.createOdps(context); AbstractCommand command = DescribeProjectCommand.parse("Desc project " + odps.getDefaultProject() + " -extended ", context); assertTrue(command instanceof DescribeProjectCommand); command.execute(); }
@Test(expected = ODPSConsoleException.class) public void testDescribeProjectExtendedNegCommand() throws ODPSConsoleException, OdpsException { ExecutionContext context = ExecutionContext.init(); Odps odps = OdpsConnectionFactory.createOdps(context); AbstractCommand command = DescribeProjectCommand.parse("Desc project " + odps.getDefaultProject() + " -abcd ", context); }