CugUtil implements CugConstants { static Set<String> getSupportedPaths(@NotNull ConfigurationParameters params, @NotNull MountInfoProvider mountInfoProvider) { Set<String> supportedPaths = params.getConfigValue(CugConstants.PARAM_CUG_SUPPORTED_PATHS, ImmutableSet.of()); if (!supportedPaths.isEmpty() && mountInfoProvider.hasNonDefaultMounts()) { for (Mount mount : mountInfoProvider.getNonDefaultMounts()) { for (String path : supportedPaths) { if (mount.isUnder(path)) { log.error("Configured supported CUG path '{}' includes node store mount '{}'.", path, mount.getName()); throw new IllegalStateException(); } else if (mount.isMounted(path)) { log.error("Configured supported CUG path '{}' is part of node store mount '{}'.", path, mount.getName()); throw new IllegalStateException(); } } } } return supportedPaths; } private  CugUtil();   }
@Test public void testGetSupportedPathsDefaultMountInfoProvider() { Set<String> expected = CUG_CONFIG.getConfigValue(PARAM_CUG_SUPPORTED_PATHS, ImmutableSet.of()); assertEquals(expected, CugUtil.getSupportedPaths(CUG_CONFIG, Mounts.defaultMountInfoProvider())); }
@Test public void testGetSupportedPathsWithDifferentMounts() { Set<String> expected = CUG_CONFIG.getConfigValue(PARAM_CUG_SUPPORTED_PATHS, ImmutableSet.of()); MountInfoProvider mip = Mounts.newBuilder().mount("private", "/libs", "/apps", "/nonCugPath").build(); assertNotSame(expected, CugUtil.getSupportedPaths(CUG_CONFIG, mip)); assertEquals(expected, CugUtil.getSupportedPaths(CUG_CONFIG, mip)); }
@Test(expected = IllegalStateException.class) public void testGetSupportedPathsMountsAtSupportedPath() { MountInfoProvider mip = Mounts.newBuilder().mount("private", "/libs", SUPPORTED_PATH3).build(); CugUtil.getSupportedPaths(CUG_CONFIG, mip); }
@Test(expected = IllegalStateException.class) public void testGetSupportedPathsMountsBelowSupportedPath() { MountInfoProvider mip = Mounts.newBuilder().mount("private", "/libs", "/apps" ).build(); CugUtil.getSupportedPaths(ConfigurationParameters.of(PARAM_CUG_SUPPORTED_PATHS, new String[] {"/"}), mip); }
@Test(expected = IllegalStateException.class) public void testGetSupportedPathsMountsBelowSupportedPath2() { MountInfoProvider mip = Mounts.newBuilder().mount("private", "/libs", SUPPORTED_PATH + "/any/path/below").build(); CugUtil.getSupportedPaths(CUG_CONFIG, mip); }
@Test(expected = IllegalStateException.class) public void testGetSupportedPathsMountsAboveSupportedPath() { MountInfoProvider mip = Mounts.newBuilder().mount("private", PathUtils.ROOT_PATH).build(); CugUtil.getSupportedPaths(CUG_CONFIG, mip); }
@Test(expected = IllegalStateException.class) public void testGetSupportedPathsMountsAboveSupportedPath2() { MountInfoProvider mip = Mounts.newBuilder().mount("private", PathUtils.getAncestorPath(SUPPORTED_PATH3, 2)).build(); CugUtil.getSupportedPaths(CUG_CONFIG, mip); }