Utils { static IoTDBConnectionParams parseUrl(String url, Properties info) throws IoTDBURLException { IoTDBConnectionParams params = new IoTDBConnectionParams(url); if (url.trim().equalsIgnoreCase(Config.IOTDB_URL_PREFIX)) { return params; } boolean isUrlLegal = false; Matcher matcher = null; if (url.startsWith(Config.IOTDB_URL_PREFIX)) { String subURL = url.substring(Config.IOTDB_URL_PREFIX.length()); matcher = URL_PATTERN.matcher(subURL); if (matcher.matches()) { isUrlLegal = true; } } if (!isUrlLegal) { throw new IoTDBURLException("Error url format, url should be jdbc:iotdb: } params.setHost(matcher.group(1)); params.setPort(Integer.parseInt(matcher.group(2))); if (info.containsKey(Config.AUTH_USER)) { params.setUsername(info.getProperty(Config.AUTH_USER)); } if (info.containsKey(Config.AUTH_PASSWORD)) { params.setPassword(info.getProperty(Config.AUTH_PASSWORD)); } return params; }    }
@Test public void testParseURL() throws IoTDBURLException { String userName = "test"; String userPwd = "test"; String host1 = "localhost"; int port = 6667; Properties properties = new Properties(); properties.setProperty(Config.AUTH_USER, userName); properties.setProperty(Config.AUTH_PASSWORD, userPwd); IoTDBConnectionParams params = Utils .parseUrl(String.format(Config.IOTDB_URL_PREFIX + "%s:%s/", host1, port), properties); assertEquals(host1, params.getHost()); assertEquals(port, params.getPort()); assertEquals(userName, params.getUsername()); assertEquals(userPwd, params.getPassword()); params = Utils.parseUrl(String.format(Config.IOTDB_URL_PREFIX + "%s:%s", host1, port), properties); assertEquals(params.getHost(), host1); assertEquals(params.getPort(), port); assertEquals(params.getUsername(), userName); assertEquals(params.getPassword(), userPwd); }
@Test(expected = IoTDBURLException.class) public void testParseWrongUrl1() throws IoTDBURLException { Properties properties = new Properties(); Utils.parseUrl("jdbc:iotdb }
@Test public void testParseDomainName() throws IoTDBURLException { Properties properties = new Properties(); final IoTDBConnectionParams params = Utils.parseUrl("jdbc:iotdb: assertEquals("test", params.getHost()); assertEquals(6667, params.getPort()); }
@Test(expected = IoTDBURLException.class) public void testParseWrongUrl2() throws IoTDBURLException { Properties properties = new Properties(); Utils.parseUrl("jdbc:iotdb }
@Test(expected = IoTDBURLException.class) public void testParseWrongPort() throws IoTDBURLException { String userName = "test"; String userPwd = "test"; String host = "localhost"; int port = 66699999; Properties properties = new Properties(); properties.setProperty(Config.AUTH_USER, userName); properties.setProperty(Config.AUTH_PASSWORD, userPwd); IoTDBConnectionParams params = Utils .parseUrl(String.format(Config.IOTDB_URL_PREFIX + "%s:%s/", host, port), properties); }