Search in sources :

Example 51 with Page

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

the class ListImpl method populateStaticListItems.

private void populateStaticListItems() {
    listItems = new ArrayList<>();
    String[] pagesPaths = properties.get(PN_PAGES, new String[0]);
    for (String path : pagesPaths) {
        Page page = pageManager.getContainingPage(path);
        if (page != null) {
            listItems.add(page);
        }
    }
}
Also used : Page(com.day.cq.wcm.api.Page)

Example 52 with Page

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

the class ListImpl method setMaxItems.

private void setMaxItems() {
    if (maxItems != 0) {
        java.util.List<Page> tmpListItems = new ArrayList<>();
        for (Page item : listItems) {
            if (tmpListItems.size() < maxItems) {
                tmpListItems.add(item);
            } else {
                break;
            }
        }
        listItems = tmpListItems;
    }
}
Also used : ArrayList(java.util.ArrayList) Page(com.day.cq.wcm.api.Page)

Example 53 with Page

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

the class SocialMediaHelperImplTest method setUp.

@BeforeClass
public static void setUp() {
    CONTEXT.registerService(Externalizer.class, MockExternalizerFactory.getExternalizerService());
    CONTEXT.registerService(AdapterFactory.class, new AdapterFactory() {

        @Override
        public <AdapterType> AdapterType getAdapter(@Nonnull Object o, @Nonnull Class<AdapterType> clazz) {
            Object result = null;
            switch(clazz.getName()) {
                case CLASS_PRODUCT:
                    if (o instanceof Resource) {
                        result = MockCommerceFactory.getProduct((Resource) o);
                    }
                    break;
                case CLASS_COMMERCE_SERVICE:
                    if (o instanceof Resource) {
                        result = MockCommerceFactory.getCommerceService((Resource) o);
                    }
                    break;
                case CLASS_XF_SOCIAL_VARIATION:
                    if (o instanceof Page) {
                        result = MockXFFactory.getExperienceFragmentSocialVariation((Page) o);
                    }
            }
            return (AdapterType) result;
        }
    }, new HashMap<String, Object>() {

        {
            put(AdapterFactory.ADAPTABLE_CLASSES, new String[] { CLASS_RESOURCE, CLASS_PAGE });
            put(AdapterFactory.ADAPTER_CLASSES, new String[] { CLASS_PRODUCT, CLASS_COMMERCE_SERVICE, CLASS_XF_SOCIAL_VARIATION });
        }
    });
}
Also used : AdapterFactory(org.apache.sling.api.adapter.AdapterFactory) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) BeforeClass(org.junit.BeforeClass)

Example 54 with Page

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

the class SocialMediaHelperImplTest method getSocialMediaHelperUnderTest.

private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
    Resource currentResource = CONTEXT.resourceResolver().getResource(pagePath);
    Page currentPage = currentResource.adaptTo(Page.class);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    request.setContextPath(CONTEXT_PATH);
    request.setResource(currentResource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setExtension(EXTENSION);
    requestPathInfo.setResourcePath(currentResource.getPath());
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
    slingBindings.put(SlingBindings.RESOLVER, CONTEXT.resourceResolver());
    slingBindings.put(SlingBindings.RESPONSE, response);
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(SocialMediaHelper.class);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Page(com.day.cq.wcm.api.Page)

Example 55 with Page

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

the class ImageImplTest method getImageUnderTest.

private Image getImageUnderTest(String resourcePath, WCMMode wcmMode) {
    Resource resource = aemContext.resourceResolver().getResource(resourcePath);
    ContentPolicyMapping mapping = resource.adaptTo(ContentPolicyMapping.class);
    ContentPolicy contentPolicy = mapping.getPolicy();
    SlingBindings slingBindings = new SlingBindings();
    if (contentPolicy != null) {
        when(contentPolicyManager.getPolicy(resource)).thenReturn(contentPolicy);
    }
    slingBindings.put(SlingBindings.RESOURCE, resource);
    final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(aemContext.resourceResolver(), aemContext.bundleContext());
    request.setContextPath(CONTEXT_PATH);
    request.setResource(resource);
    Page page = aemContext.pageManager().getPage(PAGE);
    slingBindings.put(WCMBindings.CURRENT_PAGE, page);
    if (wcmMode != null) {
        request.setAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME, wcmMode);
    }
    slingBindings.put(WCMBindings.WCM_MODE, new SightlyWCMMode(request));
    slingBindings.put(WCMBindings.PAGE_MANAGER, aemContext.pageManager());
    Style style = mock(Style.class);
    when(style.get(anyString(), (Object) Matchers.anyObject())).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[1]);
    slingBindings.put(WCMBindings.CURRENT_STYLE, style);
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(Image.class);
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ContentPolicyMapping(com.day.cq.wcm.api.policies.ContentPolicyMapping) Resource(org.apache.sling.api.resource.Resource) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) Style(com.day.cq.wcm.api.designer.Style) Page(com.day.cq.wcm.api.Page) SightlyWCMMode(com.adobe.cq.sightly.SightlyWCMMode)

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