@Test public void testGetPropertiesNonDefault() throws ParseException { String agentId = "agentId"; String zoneUrl = "http: String zoneId = "MyZone"; String script = "step1,step2,step3"; long waitTime = 9999; String messageFile = "path/to/file"; String eventAction = "DELETE"; String[] args = {"-a", agentId, "-u", zoneUrl, "-z", zoneId, "-s", script, "-w", String.valueOf(waitTime), "-f", messageFile, "-e", eventAction}; Properties props = PropertyUtils.getProperties(args); Assert.assertEquals(agentId, props.getProperty(PropertyUtils.KEY_AGENT_ID)); Assert.assertEquals(zoneUrl, props.getProperty(PropertyUtils.KEY_ZONE_URL)); Assert.assertEquals(zoneId, props.getProperty(PropertyUtils.KEY_ZONE_ID)); Assert.assertEquals(script, props.getProperty(PropertyUtils.KEY_SCRIPT)); Assert.assertEquals(waitTime, ((Long) props.get(PropertyUtils.KEY_WAIT_TIME)).longValue()); Assert.assertEquals(messageFile, props.getProperty(PropertyUtils.KEY_MESSAGE_FILE)); Assert.assertEquals(eventAction, props.getProperty(PropertyUtils.KEY_EVENT_ACTION)); }
public static Properties getProperties(String[] args) throws ParseException { Properties props = new Properties(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(OPTIONS, args); String zoneUrl = cmd.getOptionValue(FLAG_ZONE_URL, DEFAULT_ZONE_URL); String zoneId = cmd.getOptionValue(FLAG_ZONE_ID, DEFAULT_ZONE_ID); String agentId = cmd.getOptionValue(FLAG_AGENT_ID, DEFAULT_AGENT_ID); String script = cmd.getOptionValue(FLAG_SCRIPT, DEFAULT_SCRIPT); String waitTimeStr = cmd.getOptionValue(FLAG_WAIT_TIME, "DEFAULT_WAIT_TIME"); long waitTime; try { waitTime = Long.parseLong(waitTimeStr); } catch (NumberFormatException e) { waitTime = Long.parseLong(DEFAULT_WAIT_TIME); } props.put(KEY_ZONE_URL, zoneUrl); props.put(KEY_ZONE_ID, zoneId); props.put(KEY_AGENT_ID, agentId); props.put(KEY_SCRIPT, script); props.put(KEY_WAIT_TIME, waitTime); String messageFile = cmd.getOptionValue(FLAG_MESSAGE_FILE, DEFAULT_MESSAGE_FILE); props.put(KEY_MESSAGE_FILE, messageFile); String eventAction = cmd.getOptionValue(FLAG_EVENT_ACTION, DEFAULT_EVENT_ACTION); props.put(KEY_EVENT_ACTION, eventAction); return props; }
PropertyUtils { public static Properties getProperties(String[] args) throws ParseException { Properties props = new Properties(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(OPTIONS, args); String zoneUrl = cmd.getOptionValue(FLAG_ZONE_URL, DEFAULT_ZONE_URL); String zoneId = cmd.getOptionValue(FLAG_ZONE_ID, DEFAULT_ZONE_ID); String agentId = cmd.getOptionValue(FLAG_AGENT_ID, DEFAULT_AGENT_ID); String script = cmd.getOptionValue(FLAG_SCRIPT, DEFAULT_SCRIPT); String waitTimeStr = cmd.getOptionValue(FLAG_WAIT_TIME, "DEFAULT_WAIT_TIME"); long waitTime; try { waitTime = Long.parseLong(waitTimeStr); } catch (NumberFormatException e) { waitTime = Long.parseLong(DEFAULT_WAIT_TIME); } props.put(KEY_ZONE_URL, zoneUrl); props.put(KEY_ZONE_ID, zoneId); props.put(KEY_AGENT_ID, agentId); props.put(KEY_SCRIPT, script); props.put(KEY_WAIT_TIME, waitTime); String messageFile = cmd.getOptionValue(FLAG_MESSAGE_FILE, DEFAULT_MESSAGE_FILE); props.put(KEY_MESSAGE_FILE, messageFile); String eventAction = cmd.getOptionValue(FLAG_EVENT_ACTION, DEFAULT_EVENT_ACTION); props.put(KEY_EVENT_ACTION, eventAction); return props; } }
PropertyUtils { public static Properties getProperties(String[] args) throws ParseException { Properties props = new Properties(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(OPTIONS, args); String zoneUrl = cmd.getOptionValue(FLAG_ZONE_URL, DEFAULT_ZONE_URL); String zoneId = cmd.getOptionValue(FLAG_ZONE_ID, DEFAULT_ZONE_ID); String agentId = cmd.getOptionValue(FLAG_AGENT_ID, DEFAULT_AGENT_ID); String script = cmd.getOptionValue(FLAG_SCRIPT, DEFAULT_SCRIPT); String waitTimeStr = cmd.getOptionValue(FLAG_WAIT_TIME, "DEFAULT_WAIT_TIME"); long waitTime; try { waitTime = Long.parseLong(waitTimeStr); } catch (NumberFormatException e) { waitTime = Long.parseLong(DEFAULT_WAIT_TIME); } props.put(KEY_ZONE_URL, zoneUrl); props.put(KEY_ZONE_ID, zoneId); props.put(KEY_AGENT_ID, agentId); props.put(KEY_SCRIPT, script); props.put(KEY_WAIT_TIME, waitTime); String messageFile = cmd.getOptionValue(FLAG_MESSAGE_FILE, DEFAULT_MESSAGE_FILE); props.put(KEY_MESSAGE_FILE, messageFile); String eventAction = cmd.getOptionValue(FLAG_EVENT_ACTION, DEFAULT_EVENT_ACTION); props.put(KEY_EVENT_ACTION, eventAction); return props; }  }
PropertyUtils { public static Properties getProperties(String[] args) throws ParseException { Properties props = new Properties(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(OPTIONS, args); String zoneUrl = cmd.getOptionValue(FLAG_ZONE_URL, DEFAULT_ZONE_URL); String zoneId = cmd.getOptionValue(FLAG_ZONE_ID, DEFAULT_ZONE_ID); String agentId = cmd.getOptionValue(FLAG_AGENT_ID, DEFAULT_AGENT_ID); String script = cmd.getOptionValue(FLAG_SCRIPT, DEFAULT_SCRIPT); String waitTimeStr = cmd.getOptionValue(FLAG_WAIT_TIME, "DEFAULT_WAIT_TIME"); long waitTime; try { waitTime = Long.parseLong(waitTimeStr); } catch (NumberFormatException e) { waitTime = Long.parseLong(DEFAULT_WAIT_TIME); } props.put(KEY_ZONE_URL, zoneUrl); props.put(KEY_ZONE_ID, zoneId); props.put(KEY_AGENT_ID, agentId); props.put(KEY_SCRIPT, script); props.put(KEY_WAIT_TIME, waitTime); String messageFile = cmd.getOptionValue(FLAG_MESSAGE_FILE, DEFAULT_MESSAGE_FILE); props.put(KEY_MESSAGE_FILE, messageFile); String eventAction = cmd.getOptionValue(FLAG_EVENT_ACTION, DEFAULT_EVENT_ACTION); props.put(KEY_EVENT_ACTION, eventAction); return props; }  static Properties getProperties(String[] args); }
PropertyUtils { public static Properties getProperties(String[] args) throws ParseException { Properties props = new Properties(); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(OPTIONS, args); String zoneUrl = cmd.getOptionValue(FLAG_ZONE_URL, DEFAULT_ZONE_URL); String zoneId = cmd.getOptionValue(FLAG_ZONE_ID, DEFAULT_ZONE_ID); String agentId = cmd.getOptionValue(FLAG_AGENT_ID, DEFAULT_AGENT_ID); String script = cmd.getOptionValue(FLAG_SCRIPT, DEFAULT_SCRIPT); String waitTimeStr = cmd.getOptionValue(FLAG_WAIT_TIME, "DEFAULT_WAIT_TIME"); long waitTime; try { waitTime = Long.parseLong(waitTimeStr); } catch (NumberFormatException e) { waitTime = Long.parseLong(DEFAULT_WAIT_TIME); } props.put(KEY_ZONE_URL, zoneUrl); props.put(KEY_ZONE_ID, zoneId); props.put(KEY_AGENT_ID, agentId); props.put(KEY_SCRIPT, script); props.put(KEY_WAIT_TIME, waitTime); String messageFile = cmd.getOptionValue(FLAG_MESSAGE_FILE, DEFAULT_MESSAGE_FILE); props.put(KEY_MESSAGE_FILE, messageFile); String eventAction = cmd.getOptionValue(FLAG_EVENT_ACTION, DEFAULT_EVENT_ACTION); props.put(KEY_EVENT_ACTION, eventAction); return props; }  static Properties getProperties(String[] args); static final String KEY_ZONE_URL; static final String KEY_ZONE_ID; static final String KEY_AGENT_ID; static final String KEY_SCRIPT; static final String KEY_WAIT_TIME; static final String KEY_MESSAGE_FILE; static final String KEY_EVENT_ACTION; static final Options OPTIONS; }