Search in sources :

Example 1 with ContentFragmentList

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();
    }
}
Also used : Query(com.day.cq.search.Query) ContentFragmentList(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList) Resource(org.apache.sling.api.resource.Resource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) SearchResult(com.day.cq.search.result.SearchResult) PredicateGroup(com.day.cq.search.PredicateGroup) Session(javax.jcr.Session)

Example 2 with ContentFragmentList

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));
}
Also used : ContentFragmentList(com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList) Test(org.junit.jupiter.api.Test)

Aggregations

ContentFragmentList (com.adobe.cq.wcm.core.components.models.contentfragment.ContentFragmentList)2 PredicateGroup (com.day.cq.search.PredicateGroup)1 Query (com.day.cq.search.Query)1 SearchResult (com.day.cq.search.result.SearchResult)1 Session (javax.jcr.Session)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 Test (org.junit.jupiter.api.Test)1