Search in sources :

Example 26 with Page

use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootOnIntermediatePage.

/**
 * Intermediate pages exist, when a descendant got published but its parent not. They miss the jcr:content node
 */
@Test
void testNoSiteRootOnIntermediatePage() {
    // given
    Page page = aemContext.create().resource("/content/languagenavigation/LOCALE-X/LOCALE-Y", "jcr:primaryType", "cq:Page").adaptTo(Page.class);
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertNull(siteRoot);
    assertEquals(1, structureDepth);
}
Also used : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 27 with Page

use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPageWithExperienceFragment.

@Test
void testSiteRootFromPageWithExperienceFragment() {
    // given
    Page page = aemContext.create().page("/content/languagenavigation/LOCALE-1/LOCALE-5/about-2");
    Page variant = aemContext.create().page("/content/experience-fragments/fragment/master", "xf", ExperienceFragmentsConstants.PN_XF_VARIANT_TYPE, "web");
    String contentPath = page.getContentResource().getPath();
    Resource pageRoot = aemContext.create().resource(contentPath + "/root");
    Resource pageRootXf = aemContext.create().resource(contentPath + "/root/xf", "sling:resourceType", ExperienceFragmentImpl.RESOURCE_TYPE_V2, ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, variant.getPath());
    String variantContentPath = variant.getContentResource().getPath();
    Resource variantRoot = aemContext.create().resource(variantContentPath + "/root");
    Resource variantRootLanguageNav = aemContext.create().resource(variantContentPath + "/root/languageNavigation", "sling:resourceType", LanguageNavigationImpl.RESOURCE_TYPE, LanguageNavigation.PN_NAVIGATION_ROOT, "/content/languagenavigation", LanguageNavigation.PN_STRUCTURE_DEPTH, 3);
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertNotNull(siteRoot);
    assertEquals("/content/languagenavigation", siteRoot.getPath());
    assertEquals(3, structureDepth);
}
Also used : Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 28 with Page

use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootFallbackToDefault.

@Test
void testNoSiteRootFallbackToDefault() throws PersistenceException, NoSuchFieldException, IllegalAccessException {
    // given
    // replace with service injection after SLING-10616 was released
    DefaultSiteRootSelectionStrategy defaultSiteRootSelectionStrategy = spy(new DefaultSiteRootSelectionStrategy());
    Field defaultSelectionStrategy = subject.getClass().getDeclaredField("defaultSelectionStrategy");
    defaultSelectionStrategy.setAccessible(true);
    defaultSelectionStrategy.set(subject, defaultSiteRootSelectionStrategy);
    Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
    deleteSiblings(page.getContentResource().getChild("root/languagenavigation-component-4"));
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertEquals("/content/languagenavigation", siteRoot.getPath());
    assertEquals(2, structureDepth);
    verify(defaultSiteRootSelectionStrategy).getSiteRoot(page);
    verify(defaultSiteRootSelectionStrategy).getStructuralDepth(page);
}
Also used : Field(java.lang.reflect.Field) Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 29 with Page

use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRootOnPageWithoutLanguageNav.

@Test
void testNoSiteRootOnPageWithoutLanguageNav() {
    // given
    Page page = aemContext.create().page("/content/languagenavigation/LOCALE-X/LOCALE-Y");
    aemContext.create().resource(page, "root");
    aemContext.create().resource(page, "anyComponent");
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertNull(siteRoot);
    assertEquals(1, structureDepth);
}
Also used : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 30 with Page

use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPageWithDefaultStructureDepth.

@Test
void testSiteRootFromPageWithDefaultStructureDepth() throws PersistenceException {
    // given
    Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
    deleteSiblings(page.getContentResource().getChild("root/languagenavigation-component-1"));
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertNotNull(siteRoot);
    assertEquals("/content/languagenavigation", siteRoot.getPath());
    assertEquals(1, structureDepth);
}
Also used : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Page (com.day.cq.wcm.api.Page)100 Resource (org.apache.sling.api.resource.Resource)45 PageManager (com.day.cq.wcm.api.PageManager)34 Test (org.junit.jupiter.api.Test)22 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)18 ValueMap (org.apache.sling.api.resource.ValueMap)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 SlingBindings (org.apache.sling.api.scripting.SlingBindings)12 NotNull (org.jetbrains.annotations.NotNull)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Optional (java.util.Optional)6 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)6 Nullable (org.jetbrains.annotations.Nullable)6 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)5 Template (com.day.cq.wcm.api.Template)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Before (org.junit.Before)5