ZKAddressParser { public List<ZKAddress> validateZkUrl(final String zkUrl) { final List<ZKAddress> zkList = new ArrayList<>(); Matcher matcher = Pattern.compile(ZK_PREFIX_REGEX).matcher(zkUrl); if (!matcher.matches()) { throw new ZKAddressException(zkUrl); } if (StringUtils.countMatches(zkUrl, '/') < 3) { throw new ZKAddressException(zkUrl); } String zkStripped = zkUrl.replace(ZKAddress.ZK_PREFIX, "").replace(" ", ""); String[] split = zkStripped.split(","); for (String s : split) { zkList.add(new ZKAddress(s)); } return zkList; }  List<ZKAddress> validateZkUrl(final String zkUrl); static final String ZK_PREFIX_REGEX; }
@Test(expected = ZKAddressException.class) public void shouldExceptionIfNoPort() { String add = "zk: new ZKAddressParser().validateZkUrl(add); }
@Test(expected = ZKAddressException.class) public void shouldExceptionWithMalformedAddress() { new ZKAddressParser().validateZkUrl("zk: }
@Test(expected = ZKAddressException.class) public void shouldExceptionWithMalformedPort() { new ZKAddressParser().validateZkUrl("zk: }
@Test(expected = ZKAddressException.class) public void shouldExceptionWithoutPath() { new ZKAddressParser().validateZkUrl("zk: }
@Test(expected = ZKAddressException.class) public void shouldExceptionWithMalformedPortOnSecond() { new ZKAddressParser().validateZkUrl("zk: }
@Test public void shouldAcceptIfSingleZKAddressWithPath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "mesos"); }
@Test public void shouldAcceptIfMultiZKAddressWithPath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", ""); assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos"); }
@Test public void shouldAcceptIfSingleZKAddressWithSubpath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "mesos/subpath"); }
@Test public void shouldAcceptIfMultiZKAddressWithSubpath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", ""); assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos/sub_path"); }
@Test public void shouldAcceptIfMultiZKAddressWithMultiSubpath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "mesos/sub_path1"); assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos/sub_path2"); }
@Test public void shouldAcceptIfSpacesInPath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", ""); assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos"); }
@Test public void shouldAcceptIfMultiZKAddressWithMultiPath() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "", "", "192.168.0.1", "2182", "somePath"); assertZKEquals(zk.get(1), "", "", "10.4.52.3", "1234", "mesos"); }
@Test public void shouldAcceptIfUserPass() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "bob", "pass", "192.168.0.1", "2182", "mesos"); }
@Test public void shouldAcceptIfMultiUserPassSpaces() { String add = "zk: List<ZKAddress> zk = new ZKAddressParser().validateZkUrl(add); assertZKEquals(zk.get(0), "bob", "pass", "192.168.0.1", "2182", ""); assertZKEquals(zk.get(1), "team", "dev", "10.4.52.3", "1234", "mesos"); }
@Test(expected = ZKAddressException.class) public void shouldExceptionIfInvalidZKAddress() { new ZKAddressParser().validateZkUrl("blah"); }
@Test(expected = ZKAddressException.class) public void shouldExceptionIfNoZKPrefix() { new ZKAddressParser().validateZkUrl("file: }
@Test(expected = ZKAddressException.class) public void shouldExceptionIfNoAddress() { new ZKAddressParser().validateZkUrl("zk: }