ViewStatusOption { public static ViewStatusOption getViewStatusReporterOption(final CommandLine commandLine, final ToolContext toolContext) { ArgumentChecker.notNull(commandLine, "commandLine"); ArgumentChecker.notNull(toolContext, "toolContext"); String portfolioName = trimToNull(commandLine.getOptionValue(PORTFOLIO_NAME_OPT)); String userOption = trimToNull(commandLine.getOptionValue(USER_OPT)); UserPrincipal user = null; if (userOption == null) { user = DEFAULT_USER; } else { Matcher matcher = USER_OR_HISTORICAL_PATTERN.matcher(userOption); if (matcher.matches()) { String username = matcher.group(1); String ipaddress = matcher.group(2); user = new UserPrincipal(username, ipaddress); } else { throw new OpenGammaRuntimeException("Given user option [" + userOption + "] does not match expected format username/ipaddress"); } } String format = defaultString(trimToNull(commandLine.getOptionValue(FORMAT_TYPE_OPT)), DEFAULT_FORMAT); String aggregationOption = trimToNull(commandLine.getOptionValue(AGGREGATION_TYPE_OPT)); AggregateType aggregateType = null; if (aggregationOption != null) { aggregateType = AggregateType.of(aggregationOption); } else { aggregateType = AggregateType.NO_AGGREGATION; } String outputOption = trimToNull(commandLine.getOptionValue(OUTPUT_OPT)); File outputFile = null; if (outputOption != null) { outputFile = new File(outputOption); } else { outputFile = new File(DEFAULT_OUTPUT_NAME + "." + ResultFormat.of(format).getExtension()); } MarketDataSpecification marketDataSpec = getMarketDataSpecification(commandLine, toolContext); return new ViewStatusOption(portfolioName, format, user, aggregateType, outputFile, marketDataSpec); } private  ViewStatusOption(final String portfolioName, final String formatOption, final UserPrincipal user, 
      final AggregateType aggregateType, final File outputFile, final MarketDataSpecification marketDataSpecification); static Options createOptions(); static ViewStatusOption getViewStatusReporterOption(final CommandLine commandLine, final ToolContext toolContext); String getPortfolioName(); UserPrincipal getUser(); ResultFormat getFormat(); File getOutputFile(); AggregateType getAggregateType(); MarketDataSpecification getMarketDataSpecification(); static final String DEFAULT_OUTPUT_NAME; }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void invalidSeparatorForUserOption() throws Exception { String[] args = {"-n", PORTFOLIO_NAME, "-u", "test~127.0.0.1"}; ViewStatusOption.getViewStatusReporterOption(s_parser.parse(s_options, args), s_toolContext); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void blankUsernamePasswordForUserOption() throws Exception { String[] args = {"-n", PORTFOLIO_NAME, "-u", "/"}; ViewStatusOption.getViewStatusReporterOption(s_parser.parse(s_options, args), s_toolContext); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void invalidHistoricalMarketDataOption() throws Exception { String[] args = {"-n", PORTFOLIO_NAME, "--historical", "2013-06-20~timeSeriesResolverKey"}; ViewStatusOption.getViewStatusReporterOption(s_parser.parse(s_options, args), s_toolContext); }
@Test(expectedExceptions = OpenGammaRuntimeException.class) public void invalidDateHistoricalMarketDataOption() throws Exception { String[] args = {"-n", PORTFOLIO_NAME, "--historical", "xxxx/timeSeriesResolverKey"}; ViewStatusOption.getViewStatusReporterOption(s_parser.parse(s_options, args), s_toolContext); }