AllowedComponentsProviderImpl implements AllowedComponentsProvider { @Override public @NotNull Set<String> getAllowedComponents(@NotNull String resourcePath, @NotNull ResourceResolver resolver) { PageManager pageManager = AdaptTo.notNull(resolver, PageManager.class); Page page = pageManager.getContainingPage(resourcePath); if (page == null && StringUtils.contains(resourcePath, "/" + JcrConstants.JCR_CONTENT)) { page = pageManager.getPage(StringUtils.substringBefore(resourcePath, "/" + JcrConstants.JCR_CONTENT)); } if (page == null) { return ImmutableSet.of(); } String relativePath = StringUtils.substringAfter(resourcePath, page.getPath() + "/"); return getAllowedComponents(page, relativePath, null, resolver); }  @Override @NotNull Set<String> getAllowedComponents(@NotNull String resourcePath, @NotNull ResourceResolver resolver); @Override @NotNull Set<String> getAllowedComponents(@NotNull Page page, @NotNull String relativeResourcePath,
      @Nullable String resourceType, @NotNull ResourceResolver resolver); @Override @NotNull Set<String> getAllowedComponentsForTemplate(@NotNull String pageComponentPath, @NotNull ResourceResolver resolver);  }
@Test void testGetAllowedComponentsForParsys() { String contentParsys = CONTENT_ROOT_PATH + "/page-1/jcr:content/content"; Set<String> allowedComponents = underTest.getAllowedComponents(contentParsys, context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/comp2"), "Component 'comp2' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/linklist"), "Component 'linklist' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/container2col"), "Component 'container2col' must be allowed in " + contentParsys + "."); assertFalse(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' should not be allowed in " + contentParsys + "."); assertFalse(allowedComponents.contains("dummy/components/comp3"), "Component 'comp3' should not be allowed in " + contentParsys + "."); }
@Test void testGetAllowedComponentsForNestedParsys() { String nested2ColParsys = CONTENT_ROOT_PATH + "/page-1/jcr:content/content/2colContainer/items"; Set<String> allowedComponents = underTest.getAllowedComponents(nested2ColParsys, context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/nestedComp1"), "Component 'nestedComp1' must be allowed in " + nested2ColParsys + "."); assertTrue(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' must be allowed in " + nested2ColParsys + "."); assertTrue(allowedComponents.contains("dummy/components/linklist"), "Component 'linklist' must be allowed in " + nested2ColParsys + "."); assertFalse(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' should not be allowed in " + nested2ColParsys + "."); }
@Test void testGetAllowedComponentsForNestedNestedParsys() { String linklist = CONTENT_ROOT_PATH + "/page-1/jcr:content/content/2colContainer/linklist/links"; Set<String> allowedComponents = underTest.getAllowedComponents(linklist, context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/linkItem"), "Component 'linkItem' must be allowed in " + linklist + "."); assertFalse(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' should not be allowed in " + linklist + "."); assertFalse(allowedComponents.contains("dummy/components/nestedComp1"), "Component 'nestedComp1' must be allowed in " + linklist + "."); }
@Test void testGetAllowedComponentsForInheritedParsys() { String specialParsys = CONTENT_ROOT_PATH + "/page-2/jcr:content/special"; Set<String> allowedComponents = underTest.getAllowedComponents(specialParsys, context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/specialComp1"), "Component 'specialComp1' must be allowed in " + specialParsys + "."); assertTrue(allowedComponents.contains("dummy/components/specialText"), "Component 'specialText' must be allowed in " + specialParsys + "."); assertFalse(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' should not be allowed in " + specialParsys + "."); assertFalse(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' should not be allowed in " + specialParsys + "."); String contentParsys = CONTENT_ROOT_PATH + "/page-2/jcr:content/content"; allowedComponents = underTest.getAllowedComponents(contentParsys, context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/comp2"), "Component 'comp2' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/comp2a"), "Component 'comp2a' must be allowed in " + contentParsys + "."); assertTrue(allowedComponents.contains("dummy/components/linklist"), "Component 'linklist' must be allowed in " + contentParsys + "."); assertFalse(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' should not be allowed in " + contentParsys + "."); assertFalse(allowedComponents.contains("dummy/components/container2col"), "Component 'container2col' must not be allowed in " + contentParsys + "."); assertFalse(allowedComponents.contains("dummy/components/comp3"), "Component 'comp3' should not be allowed in " + contentParsys + "."); String linklistParsys = CONTENT_ROOT_PATH + "/page-2/jcr:content/content/links"; allowedComponents = underTest.getAllowedComponents(linklistParsys, context.resourceResolver()); assertTrue(allowedComponents.contains("dummy/components/comp2b"), "Component 'comp2b' must be allowed in " + linklistParsys + "."); assertFalse(allowedComponents.contains("dummy/components/linkItem"), "Component 'linkItem' should not be allowed in " + linklistParsys + "."); }
@Test void testGetAllowedComponentsForParsys_NonexistingResource_ResourceType_Ancestor1() { String relativePath = "jcr:content/nonExistingResource"; Set<String> allowedComponents = underTest.getAllowedComponents(basePage, relativePath, "dummy/components/parentWithAncestorLevel1", context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/nestedComp1"), "Component 'nestedComp1' must be allowed in " + relativePath + "."); assertTrue(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' must be allowed in " + relativePath + "."); assertTrue(allowedComponents.contains("dummy/components/nestedComp3"), "Component 'nestedComp3' must be allowed in " + relativePath + "."); assertFalse(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' should not be allowed in " + relativePath + "."); }
@Test void testGetAllowedComponentsForParsys_NonexistingResource_ResourceType_NoAncestor() { String relativePath = "jcr:content/nonExistingResource"; Set<String> allowedComponents = underTest.getAllowedComponents(basePage, relativePath, "dummy/components/parentWithoutAncestorLevel", context.resourceResolver()); assertNotNull(allowedComponents, "Allowed component for parsys cannot be null"); assertTrue(allowedComponents.contains("dummy/components/nestedComp1"), "Component 'nestedComp1' must be allowed in " + relativePath + "."); assertTrue(allowedComponents.contains("dummy/components/nestedComp2"), "Component 'nestedComp2' must be allowed in " + relativePath + "."); assertFalse(allowedComponents.contains("dummy/components/comp1"), "Component 'comp1' should not be allowed in " + relativePath + "."); assertFalse(allowedComponents.contains("dummy/components/nestedComp3"), "Component 'nestedComp3' should not be allowed in " + relativePath + "."); }