Search in sources :

Example 76 with Page

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

the class PWAImplTest method setUp.

@BeforeEach
public void setUp() {
    context.load().json("/pwa" + CoreComponentTestContext.TEST_CONTENT_JSON, SITES_PAGE_PATH);
    resolver = context.resourceResolver();
    resource = spy(resolver.getResource(SITES_PAGE_PATH));
    mvp = resource.adaptTo(ModifiableValueMap.class);
    when(resource.getPath()).thenReturn(SITES_PAGE_PATH);
    ResourceResolver spyResolver = spy(resolver);
    when(resource.getResourceResolver()).thenReturn(spyResolver);
    Resource mockPWAResource = mock(Resource.class);
    when(spyResolver.getResource(SITES_PAGE_PATH + "/" + JcrConstants.JCR_CONTENT)).thenReturn(mockPWAResource);
    PageManager mockPageManager = mock(PageManager.class);
    Page mockPage = mock(Page.class);
    when(spyResolver.adaptTo(PageManager.class)).thenReturn(mockPageManager);
    when(mockPageManager.getContainingPage(resource)).thenReturn(mockPage);
    when(mockPage.getContentResource()).thenReturn(mockPWAResource);
    when(mockPage.getPath()).thenReturn(SITES_PAGE_PATH);
    Page mockParentPage = mock(Page.class);
    when(mockPage.getParent()).thenReturn(mockParentPage);
    mvp.put(PN_PWA_ENABLED, true);
    mvp.put(PN_PWA_START_URL, SITES_PAGE_PATH + ".html");
    when(mockPWAResource.getValueMap()).thenReturn(mvp);
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 77 with Page

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

the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromContentPolicy.

@Test
void testSiteRootFromContentPolicy() throws PersistenceException {
    // given
    Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
    deleteSiblings(page.getContentResource().getChild("root/languagenavigation-component-3"));
    aemContext.contentPolicyMapping(LanguageNavigationImpl.RESOURCE_TYPE, "siteRoot", "/content/languagenavigation", "structureDepth", 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 : Page(com.day.cq.wcm.api.Page) Test(org.junit.jupiter.api.Test)

Example 78 with Page

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

the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPageV2.

@Test
void testSiteRootFromPageV2() throws PersistenceException {
    // given
    Page page = aemContext.pageManager().getPage("/content/languagenavigation/LOCALE-1/LOCALE-5/about");
    Resource languageNav = page.getContentResource().getChild("root/languagenavigation-component-2");
    deleteSiblings(languageNav);
    ModifiableValueMap properties = languageNav.adaptTo(ModifiableValueMap.class);
    properties.put("sling:resourceType", com.adobe.cq.wcm.core.components.internal.models.v2.LanguageNavigationImpl.RESOURCE_TYPE);
    languageNav.getResourceResolver().commit();
    // when
    Page siteRoot = subject.getSiteRoot(page);
    int structureDepth = subject.getStructuralDepth(page);
    // then
    assertNotNull(siteRoot);
    assertEquals("/content/languagenavigation", siteRoot.getPath());
    assertEquals(2, structureDepth);
}
Also used : Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) Test(org.junit.jupiter.api.Test)

Example 79 with Page

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

the class LanguageNavigationSiteRootSelectionStrategyTest method testSiteRootFromPage.

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

Example 80 with Page

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

the class LanguageNavigationSiteRootSelectionStrategyTest method testNoSiteRoot.

@Test
void testNoSiteRoot() throws PersistenceException {
    // given
    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
    assertNull(siteRoot);
    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