ZooKeeperUtils { public static String normalizePath(String path) { String normalizedPath = path.replaceAll(" PathUtils.validatePath(normalizedPath); return normalizedPath; } private  ZooKeeperUtils(); static boolean isRetryable(KeeperException e); static void ensurePath(ZooKeeperClient zkClient, List<ACL> acl, String path); static String normalizePath(String path); static final Amount<Integer,Time> DEFAULT_ZK_SESSION_TIMEOUT; static final int ANY_VERSION; static final ImmutableList<ACL> OPEN_ACL_UNSAFE; static final ImmutableList<ACL> EVERYONE_READ_CREATOR_ALL; }
@Test public void testNormalizingPath() throws Exception { assertEquals("/", ZooKeeperUtils.normalizePath("/")); assertEquals("/foo", ZooKeeperUtils.normalizePath("/foo/")); assertEquals("/foo/bar", ZooKeeperUtils.normalizePath("/foo assertEquals("/foo/bar", ZooKeeperUtils.normalizePath(" assertEquals("/foo/bar", ZooKeeperUtils.normalizePath("/foo/bar/")); assertEquals("/foo/bar", ZooKeeperUtils.normalizePath("/foo/bar assertEquals("/foo/bar", ZooKeeperUtils.normalizePath("/foo/bar")); }
@Test public void testLenientPaths() { assertEquals("/", ZooKeeperUtils.normalizePath(" assertEquals("/a/group", ZooKeeperUtils.normalizePath("/a/group")); assertEquals("/a/group", ZooKeeperUtils.normalizePath("/a/group/")); assertEquals("/a/group", ZooKeeperUtils.normalizePath("/a assertEquals("/a/group", ZooKeeperUtils.normalizePath("/a try { ZooKeeperUtils.normalizePath("a/group"); fail("Relative paths should not be allowed."); } catch (IllegalArgumentException e) { } try { ZooKeeperUtils.normalizePath("/a/./group"); fail("Relative paths should not be allowed."); } catch (IllegalArgumentException e) { } try { ZooKeeperUtils.normalizePath("/a/../group"); fail("Relative paths should not be allowed."); } catch (IllegalArgumentException e) { } }