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);
}
}
}
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;
}
}
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 });
}
});
}
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);
}
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);
}
Aggregations