use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testListRenderedAsTeaserItems.
@Test
protected void testListRenderedAsTeaserItems() {
List list = getListUnderTest(LIST_20);
assertEquals(3, list.getListItems().size());
Collection<ListItem> items = list.getListItems();
// The featured image of the page exists: the featured image node of the page is used to render the teaser item
ListItem item0 = (ListItem) items.toArray()[0];
Resource teaserResource0 = item0.getTeaserResource();
ValueMap teaserProperties = teaserResource0.getValueMap();
String linkURL = teaserProperties.get("linkURL", String.class);
String fileReference = teaserProperties.get("fileReference", String.class);
String title = teaserProperties.get("jcr:title", String.class);
String description = teaserProperties.get("jcr:description", String.class);
assertEquals("/content/list/pages/page_1/page_1_1/jcr:content/cq:featuredimage", teaserResource0.getPath(), "image resource: path");
assertEquals("core/wcm/components/teaser/v2/teaser", teaserResource0.getResourceType(), "image resource: resource type");
assertEquals("/content/list/pages/page_1/page_1_1", linkURL, "image resource: linkURL");
assertEquals("/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", fileReference, "image resource: fileReference");
assertEquals("Page 1.1", title, "image resource: title");
assertEquals("Description for Page 1.1", description, "image resource: description");
// The featured image of the page does not exist: the content node of the page is used to render the teaser item
ListItem item2 = (ListItem) items.toArray()[2];
Resource teaserResource2 = item2.getTeaserResource();
assertEquals("/content/list/pages/page_1/page_1_3/jcr:content", teaserResource2.getPath(), "image resource: path");
Utils.testJSONExport(list, Utils.getTestExporterJSONPath(testBase, LIST_20));
}
use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImpl method getSearchListItems.
/**
* Get the list items if using the search source type.
*
* @return The search list items.
*/
private Stream<Page> getSearchListItems() {
Optional<Page> searchRoot = getRootPage(PN_SEARCH_IN);
String query = properties.get(PN_SEARCH_QUERY, String.class);
if (!StringUtils.isBlank(query) && searchRoot.isPresent()) {
SimpleSearch search = resource.adaptTo(SimpleSearch.class);
if (search != null) {
search.setQuery(query);
search.setSearchIn(searchRoot.get().getPath());
search.addPredicate(new Predicate("type", "type").set("type", NameConstants.NT_PAGE));
int limit = properties.get(PN_SEARCH_LIMIT, SEARCH_LIMIT_DEFAULT);
search.setHitsPerPage(limit);
return safeGetSearchResult(search).map(SearchResult::getResources).map(it -> (Iterable<Resource>) () -> it).map(it -> StreamSupport.stream(it.spliterator(), false)).orElseGet(Stream::empty).filter(Objects::nonNull).map(currentPage.getPageManager()::getContainingPage).filter(Objects::nonNull);
}
}
return Stream.empty();
}
use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testChildrenListTypeWithDepth.
@Test
public void testChildrenListTypeWithDepth() throws Exception {
Resource resource = context.currentResource("/content/list/listTypes/childrenListTypeWithDepth");
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
List list = context.request().adaptTo(List.class);
assertEquals(4, list.getItems().size());
}
use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testOrderDescBy.
@Test
public void testOrderDescBy() throws Exception {
Resource resource = context.currentResource("/content/list/listTypes/staticOrderByTitleDescListType");
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
List list2 = context.request().adaptTo(List.class);
checkListConsistency(list2, new String[] { "Page 2", "Page 1" });
}
use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testOrderBy.
@Test
public void testOrderBy() throws Exception {
Resource resource = context.currentResource("/content/list/listTypes/staticOrderByTitleListType");
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
List list = context.request().adaptTo(List.class);
checkListConsistency(list, new String[] { "Page 1", "Page 2" });
}
Aggregations