Path { public static String getAbsoluteParent(@NotNull String path, int parentLevel, @NotNull ResourceResolver resourceResolver) { if (parentLevel < 0) { return ""; } int level = parentLevel + getAbsoluteLevelOffset(path, resourceResolver); return Text.getAbsoluteParent(path, level); } private  Path(); static String getAbsoluteParent(@NotNull String path, int parentLevel, @NotNull ResourceResolver resourceResolver); @SuppressWarnings("null") static Page getAbsoluteParent(@NotNull Page page, int parentLevel, @NotNull ResourceResolver resourceResolver); static int getAbsoluteLevel(@NotNull String path, @NotNull ResourceResolver resourceResolver); static String getOriginalPath(@NotNull String path, @NotNull ResourceResolver resourceResolver); static boolean isExperienceFragmentPath(@NotNull String path); static boolean isEditableTemplatePath(@NotNull String path);  }
@Test void testGetAbsoluteParent() { assertEquals("/content", Path.getAbsoluteParent("/content/a/b/c", 0, resolver)); assertEquals("/content/a", Path.getAbsoluteParent("/content/a/b/c", 1, resolver)); assertEquals("/content/a/b", Path.getAbsoluteParent("/content/a/b/c", 2, resolver)); assertEquals("/content/a/b/c", Path.getAbsoluteParent("/content/a/b/c", 3, resolver)); assertEquals("", Path.getAbsoluteParent("/content/a/b/c", 4, resolver)); assertEquals("", Path.getAbsoluteParent("/content/a/b/c", -1, resolver)); }
@Test void testGetAbsoluteParent_VersionHistory() { assertEquals("/tmp/versionhistory/user1/version1", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", 0, resolver)); assertEquals("/tmp/versionhistory/user1/version1/a", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", 1, resolver)); assertEquals("/tmp/versionhistory/user1/version1/a/b", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", 2, resolver)); assertEquals("/tmp/versionhistory/user1/version1/a/b/c", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", 3, resolver)); assertEquals("", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", 4, resolver)); assertEquals("", Path.getAbsoluteParent("/tmp/versionhistory/user1/version1/a/b/c", -1, resolver)); }
@Test void testGetAbsoluteParent_LegacyVersionHistory() { assertEquals("/content/versionhistory/user1", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", 0, resolver)); assertEquals("/content/versionhistory/user1/a", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", 1, resolver)); assertEquals("/content/versionhistory/user1/a/b", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", 2, resolver)); assertEquals("/content/versionhistory/user1/a/b/c", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", 3, resolver)); assertEquals("", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", 4, resolver)); assertEquals("", Path.getAbsoluteParent("/content/versionhistory/user1/a/b/c", -1, resolver)); }
@Test void testGetAbsoluteParent_LegacyVersionHistory_Tenant() { context.registerAdapter(ResourceResolver.class, Tenant.class, tenant); assertEquals("/content/versionhistory/tenant1/user1", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", 0, resolver)); assertEquals("/content/versionhistory/tenant1/user1/a", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", 1, resolver)); assertEquals("/content/versionhistory/tenant1/user1/a/b", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", 2, resolver)); assertEquals("/content/versionhistory/tenant1/user1/a/b/c", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", 3, resolver)); assertEquals("", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", 4, resolver)); assertEquals("", Path.getAbsoluteParent("/content/versionhistory/tenant1/user1/a/b/c", -1, resolver)); }
@Test void testGetAbsoluteParent_Launches() { assertEquals("/content/launches/2018/01/01/launch1/content", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", 0, resolver)); assertEquals("/content/launches/2018/01/01/launch1/content/a", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", 1, resolver)); assertEquals("/content/launches/2018/01/01/launch1/content/a/b", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", 2, resolver)); assertEquals("/content/launches/2018/01/01/launch1/content/a/b/c", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", 3, resolver)); assertEquals("", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", 4, resolver)); assertEquals("", Path.getAbsoluteParent("/content/launches/2018/01/01/launch1/content/a/b/c", -1, resolver)); }
@Test void testGetAbsoluteParent_Page() { context.create().page("/content/a"); context.create().page("/content/a/b"); Page pageC = context.create().page("/content/a/b/c"); assertEquals("/content", Path.getAbsoluteParent(pageC, 0, resolver).getPath()); assertEquals("/content/a", Path.getAbsoluteParent(pageC, 1, resolver).getPath()); assertEquals("/content/a/b", Path.getAbsoluteParent(pageC, 2, resolver).getPath()); assertEquals("/content/a/b/c", Path.getAbsoluteParent(pageC, 3, resolver).getPath()); assertNull(Path.getAbsoluteParent(pageC, 4, resolver)); assertNull(Path.getAbsoluteParent(pageC, -1, resolver)); }
@Test void testGetAbsoluteParent_Page_VersionHistory() { context.create().page("/tmp/versionhistory/user1/version1/a"); context.create().page("/tmp/versionhistory/user1/version1/a/b"); Page pageC = context.create().page("/tmp/versionhistory/user1/version1/a/b/c"); assertEquals("/tmp/versionhistory/user1/version1", Path.getAbsoluteParent(pageC, 0, resolver).getPath()); assertEquals("/tmp/versionhistory/user1/version1/a", Path.getAbsoluteParent(pageC, 1, resolver).getPath()); assertEquals("/tmp/versionhistory/user1/version1/a/b", Path.getAbsoluteParent(pageC, 2, resolver).getPath()); assertEquals("/tmp/versionhistory/user1/version1/a/b/c", Path.getAbsoluteParent(pageC, 3, resolver).getPath()); }
@Test void testGetAbsoluteParent_Page_LegacyVersionHistory() { context.create().page("/content/versionhistory/user1/a"); context.create().page("/content/versionhistory/user1/a/b"); Page pageC = context.create().page("/content/versionhistory/user1/a/b/c"); assertEquals("/content/versionhistory/user1", Path.getAbsoluteParent(pageC, 0, resolver).getPath()); assertEquals("/content/versionhistory/user1/a", Path.getAbsoluteParent(pageC, 1, resolver).getPath()); assertEquals("/content/versionhistory/user1/a/b", Path.getAbsoluteParent(pageC, 2, resolver).getPath()); assertEquals("/content/versionhistory/user1/a/b/c", Path.getAbsoluteParent(pageC, 3, resolver).getPath()); }
@Test void testGetAbsoluteParent_Page_LegacyVersionHistory_Tenant() { context.registerAdapter(ResourceResolver.class, Tenant.class, tenant); context.create().page("/content/versionhistory/tenant1/user1/a"); context.create().page("/content/versionhistory/tenant1/user1/a/b"); Page pageC = context.create().page("/content/versionhistory/tenant1/user1/a/b/c"); assertEquals("/content/versionhistory/tenant1/user1", Path.getAbsoluteParent(pageC, 0, resolver).getPath()); assertEquals("/content/versionhistory/tenant1/user1/a", Path.getAbsoluteParent(pageC, 1, resolver).getPath()); assertEquals("/content/versionhistory/tenant1/user1/a/b", Path.getAbsoluteParent(pageC, 2, resolver).getPath()); assertEquals("/content/versionhistory/tenant1/user1/a/b/c", Path.getAbsoluteParent(pageC, 3, resolver).getPath()); }
@Test void testGetAbsoluteParent_Page_Launches() { context.create().page("/content/launches/2018/01/01/launch1/content"); context.create().page("/content/launches/2018/01/01/launch1/content/a"); context.create().page("/content/launches/2018/01/01/launch1/content/a/b"); Page pageC = context.create().page("/content/launches/2018/01/01/launch1/content/a/b/c"); assertEquals("/content/launches/2018/01/01/launch1/content", Path.getAbsoluteParent(pageC, 0, resolver).getPath()); assertEquals("/content/launches/2018/01/01/launch1/content/a", Path.getAbsoluteParent(pageC, 1, resolver).getPath()); assertEquals("/content/launches/2018/01/01/launch1/content/a/b", Path.getAbsoluteParent(pageC, 2, resolver).getPath()); assertEquals("/content/launches/2018/01/01/launch1/content/a/b/c", Path.getAbsoluteParent(pageC, 3, resolver).getPath()); }