use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentListImplTest method testListWithOneFragment.
@SuppressWarnings("unchecked")
private void testListWithOneFragment(String listName) {
Resource resource = context.resourceResolver().getResource("/content/dam/contentfragments-for-list/text-only");
if (resource != null) {
Resource DAMFragment = Mockito.spy(resource);
Query query = Mockito.mock(Query.class);
SearchResult searchResult = Mockito.mock(SearchResult.class);
Iterator<Resource> iterator = Mockito.mock(Iterator.class);
ResourceResolver spyResolver = Mockito.spy(DAMFragment.getResourceResolver());
when(query.getResult()).thenReturn(searchResult);
when(searchResult.getResources()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true, false);
when(iterator.next()).thenReturn(DAMFragment);
when(DAMFragment.getResourceResolver()).thenReturn(spyResolver);
Mockito.doNothing().when(spyResolver).close();
when(queryBuilderMock.createQuery(Mockito.any(PredicateGroup.class), Mockito.any(Session.class))).thenReturn(query);
ContentFragmentList contentFragmentList = getModelInstanceUnderTest(listName);
assertEquals(ContentFragmentListImpl.RESOURCE_TYPE_V1, contentFragmentList.getExportedType());
assertEquals(contentFragmentList.getListItems().size(), 1);
Utils.testJSONExport(contentFragmentList, Utils.getTestExporterJSONPath(TEST_BASE, listName));
Mockito.doCallRealMethod().when(spyResolver).close();
}
}
use of com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentListImplTest method testListWithNoModel.
@Test
void testListWithNoModel() {
ContentFragmentList contentFragmentList = getModelInstanceUnderTest(NO_MODEL);
assertNotNull(contentFragmentList);
assertEquals(contentFragmentList.getListItems().size(), 0);
assertEquals(ContentFragmentListImpl.RESOURCE_TYPE_V1, contentFragmentList.getExportedType());
Utils.testJSONExport(contentFragmentList, Utils.getTestExporterJSONPath(TEST_BASE, NO_MODEL));
}
Aggregations