@Test public void testGetHostAndPortFromProperty() { String value = null; HostAndPort hp = HTTPUtils.getHostAndPortFromProperty(value); Assert.assertNull(hp); value = ""; hp = HTTPUtils.getHostAndPortFromProperty(value); Assert.assertNull(hp); value = "c6401.ambari.apache.org"; hp = HTTPUtils.getHostAndPortFromProperty(value); Assert.assertNull(hp); value = "c6401.ambari.apache.org:"; hp = HTTPUtils.getHostAndPortFromProperty(value); Assert.assertNull(hp); value = "c6401.ambari.apache.org:50070"; hp = HTTPUtils.getHostAndPortFromProperty(value); Assert.assertEquals(hp.host, "c6401.ambari.apache.org"); Assert.assertEquals(hp.port, 50070); value = " c6401.ambari.apache.org:50070 "; Assert.assertEquals(hp.host, "c6401.ambari.apache.org"); Assert.assertEquals(hp.port, 50070); }
public static HostAndPort getHostAndPortFromProperty(String value) { if (value == null || value.isEmpty()) return null; value = value.trim(); int colonIndex = value.indexOf(":"); if (colonIndex > 0 && colonIndex < value.length() - 1) { String host = value.substring(0, colonIndex); int port = Integer.parseInt(value.substring(colonIndex + 1, value.length())); return new HostAndPort(host, port); } return null; }
HTTPUtils { public static HostAndPort getHostAndPortFromProperty(String value) { if (value == null || value.isEmpty()) return null; value = value.trim(); int colonIndex = value.indexOf(":"); if (colonIndex > 0 && colonIndex < value.length() - 1) { String host = value.substring(0, colonIndex); int port = Integer.parseInt(value.substring(colonIndex + 1, value.length())); return new HostAndPort(host, port); } return null; } }
HTTPUtils { public static HostAndPort getHostAndPortFromProperty(String value) { if (value == null || value.isEmpty()) return null; value = value.trim(); int colonIndex = value.indexOf(":"); if (colonIndex > 0 && colonIndex < value.length() - 1) { String host = value.substring(0, colonIndex); int port = Integer.parseInt(value.substring(colonIndex + 1, value.length())); return new HostAndPort(host, port); } return null; }  }
HTTPUtils { public static HostAndPort getHostAndPortFromProperty(String value) { if (value == null || value.isEmpty()) return null; value = value.trim(); int colonIndex = value.indexOf(":"); if (colonIndex > 0 && colonIndex < value.length() - 1) { String host = value.substring(0, colonIndex); int port = Integer.parseInt(value.substring(colonIndex + 1, value.length())); return new HostAndPort(host, port); } return null; }  static String requestURL(String urlToRead); static HostAndPort getHostAndPortFromProperty(String value); }
HTTPUtils { public static HostAndPort getHostAndPortFromProperty(String value) { if (value == null || value.isEmpty()) return null; value = value.trim(); int colonIndex = value.indexOf(":"); if (colonIndex > 0 && colonIndex < value.length() - 1) { String host = value.substring(0, colonIndex); int port = Integer.parseInt(value.substring(colonIndex + 1, value.length())); return new HostAndPort(host, port); } return null; }  static String requestURL(String urlToRead); static HostAndPort getHostAndPortFromProperty(String value);  }