use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ClientLibrariesImplTest method testGetCategoriesWithInjectedFilter.
@Test
void testGetCategoriesWithInjectedFilter() {
PageManager pageManager = context.resourceResolver().adaptTo(PageManager.class);
Page page = pageManager.getPage(ROOT_PAGE);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ClientLibraries.OPTION_RESOURCE_TYPES, Utils.getPageResourceTypes(page, context.request(), mock(ModelFactory.class)));
attributes.put("filter", ".*teaser.*");
ClientLibraries clientlibs = getClientLibrariesUnderTest(ROOT_PAGE, attributes);
Set<String> categories = new HashSet<>();
categories.add(TEASER_CATEGORY);
assertEquals(categories, ((ClientLibrariesImpl) clientlibs).getCategoriesFromComponents());
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ClientLibrariesImplTest method testGetCategoriesWithLoginException.
/**
* Same as {@link #testGetCategories()} however a login exception will occur when fetching the
* resource resolver.
*/
@Test
void testGetCategoriesWithLoginException() throws Exception {
PageManager pageManager = context.pageManager();
Page page = pageManager.getPage(ROOT_PAGE);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ClientLibraries.OPTION_RESOURCE_TYPES, Utils.getPageResourceTypes(page, context.request(), mock(ModelFactory.class)));
ClientLibrariesImpl clientlibs = Objects.requireNonNull((ClientLibrariesImpl) getClientLibrariesUnderTest(ROOT_PAGE, attributes));
ResourceResolverFactory factory = mock(ResourceResolverFactory.class);
doThrow(new LoginException()).when(factory).getServiceResourceResolver(anyMap());
clientlibs.resolverFactory = factory;
assertEquals(new HashSet<>(), clientlibs.getCategoriesFromComponents());
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ComponentImplTest method getReferencedComponentUnderTest.
private Component getReferencedComponentUnderTest(String resourcePath, String currentPagePath, String referencerPath, Object... properties) {
Resource resource = context.currentResource(resourcePath);
if (resource != null && properties != null) {
context.contentPolicyMapping(resource.getResourceType(), properties);
}
Resource referencer = context.resourceResolver().getResource(referencerPath);
SlingBindings slingBindings = new SlingBindings();
ComponentContext componentContext = mock(ComponentContext.class);
ComponentContext parentContext = mock(ComponentContext.class);
when(parentContext.getResource()).thenReturn(referencer);
when(componentContext.getParent()).thenReturn(parentContext);
Page currentPage = context.pageManager().getPage(currentPagePath);
slingBindings.put(WCMBindings.COMPONENT_CONTEXT, componentContext);
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
MockSlingHttpServletRequest request = context.request();
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Component.class);
}
use of com.day.cq.wcm.api.Page in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImplTest method setUp.
@BeforeEach
void setUp() {
context.load().json(TEST_BASE + CoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
context.registerService(AdapterFactory.class, new AdapterFactory() {
@Override
@SuppressWarnings("unchecked")
public <AdapterType> AdapterType getAdapter(@NotNull Object o, @NotNull 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 NavigationItemImplTest method test.
@Test
protected void test() {
Page page = mock(Page.class);
when(page.getProperties()).thenReturn(ValueMap.EMPTY);
LinkHandler linkHandler = mock(LinkHandler.class);
Component component = mock(Component.class);
NavigationItemImpl navigationItem = new NavigationItemImpl(page, true, true, linkHandler, 0, Collections.emptyList(), "id", component);
assertEquals(page, navigationItem.getPage());
assertTrue(navigationItem.isActive());
assertEquals(Collections.emptyList(), navigationItem.getChildren());
assertEquals(0, navigationItem.getLevel());
}
Aggregations