use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class GuiFragmentAssertionHelper method assertUsageDetails.
/**
* does assertions on the received PagedMetadata basing on the default FragmentMockHelper mocked data
* @param usageDetails
*/
public static void assertUsageDetails(PagedMetadata<ComponentUsageEntity> usageDetails) {
int expectedTotalItems = 5;
assertEquals(expectedTotalItems, usageDetails.getTotalItems());
assertEquals(expectedTotalItems, usageDetails.getBody().size());
assertEquals(1, usageDetails.getPage());
List<ComponentUsageEntity> usageEntityList = Arrays.asList(new ComponentUsageEntity(ComponentUsageEntity.TYPE_WIDGET, WidgetMockHelper.WIDGET_1_CODE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_FRAGMENT, FragmentMockHelper.FRAGMENT_REF_1_CODE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_FRAGMENT, FragmentMockHelper.FRAGMENT_REF_2_CODE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE_TEMPLATE, PageMockHelper.PAGE_MODEL_REF_CODE_1), new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE_TEMPLATE, PageMockHelper.PAGE_MODEL_REF_CODE_2));
IntStream.range(0, usageDetails.getBody().size()).forEach(i -> ComponentUsageEntityAssertionHelper.assertComponentUsageEntity(usageEntityList.get(i), usageDetails.getBody().get(i)));
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class WidgetService method getComponentUsageDetails.
@Override
public PagedMetadata<ComponentUsageEntity> getComponentUsageDetails(String componentCode, RestListRequest restListRequest) {
WidgetInfoDto widgetInfoDto = this.getWidgetInfo(componentCode);
List<ComponentUsageEntity> totalReferenced = widgetInfoDto.getPublishedUtilizers().stream().map(widgetDetail -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, widgetDetail.getPageCode(), IPageService.STATUS_ONLINE)).collect(Collectors.toList());
List<ComponentUsageEntity> draftReferenced = widgetInfoDto.getDraftUtilizers().stream().map(widgetDetail -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, widgetDetail.getPageCode(), IPageService.STATUS_DRAFT)).collect(Collectors.toList());
totalReferenced.addAll(draftReferenced);
return pagedMetadataMapper.getPagedResult(restListRequest, totalReferenced);
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class WidgetServiceTest method getWidgetUsageDetailsWithPagination.
@Test
public void getWidgetUsageDetailsWithPagination() throws Exception {
int pageSize = 3;
// creates paged data
List<Integer> pageNumList = Arrays.asList(1, 2);
Map<Integer, List<ComponentUsageEntity>> usageEntityMap = new HashMap<>();
usageEntityMap.put(pageNumList.get(0), Arrays.asList(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_MISSION_CODE, IPageService.STATUS_ONLINE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_ONLINE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_MISSION_CODE, IPageService.STATUS_DRAFT)));
usageEntityMap.put(pageNumList.get(1), Arrays.asList(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_DRAFT)));
PageSearchRequest pageSearchRequest = new PageSearchRequest(WidgetMockHelper.WIDGET_1_CODE);
pageSearchRequest.setPageSize(pageSize);
// does assertions
IntStream.range(0, pageNumList.size()).forEach(i -> {
mockPagedMetadata(Arrays.asList(PageMockHelper.PAGE_MISSION_CODE, PageMockHelper.PAGE_CODE), pageNumList.get(i), pageNumList.get(pageNumList.size() - 1), pageSize, 4);
pageSearchRequest.setPage(pageNumList.get(i));
PagedMetadata<ComponentUsageEntity> pageUsageDetails = widgetService.getComponentUsageDetails(WIDGET_1_CODE, pageSearchRequest);
WidgetAssertionHelper.assertUsageDetails(pageUsageDetails, usageEntityMap.get(i + 1), 4, pageNumList.get(i));
});
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class PageServiceTest method testPagedPageUsageDetails.
/**
* contains generic code to test a single paged page usage details
*
* @param pageDto
* @throws Exception
*/
private void testPagedPageUsageDetails(PageDto pageDto) {
Page page = PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE);
int pageSize = 3;
int totalSize = PageMockHelper.UTILIZERS.length + (pageDto.getStatus().equals(IPageService.STATUS_ONLINE) ? 1 : 0);
mockForSinglePage(page, pageDto, PageMockHelper.UTILIZERS);
PageSearchRequest pageSearchRequest = new PageSearchRequest(PageMockHelper.PAGE_CODE);
pageSearchRequest.setPageSize(pageSize);
// creates paged data
List<Integer> pageList = Arrays.asList(1, 2);
String[][] utilizers = { { PageMockHelper.UTILIZER_1, PageMockHelper.UTILIZER_2, PageMockHelper.UTILIZER_3 }, { PageMockHelper.UTILIZER_4, PageMockHelper.UTILIZER_5 } };
// does assertions
IntStream.range(0, pageList.size()).forEach(i -> {
pageSearchRequest.setPage(pageList.get(i));
mockPagedMetadata(page, pageDto, PageMockHelper.UTILIZERS, pageList.get(i), 2, pageSize, totalSize);
PagedMetadata<ComponentUsageEntity> pageUsageDetails = pageService.getComponentUsageDetails(PageMockHelper.PAGE_CODE, pageSearchRequest);
PageAssertionHelper.assertUsageDetails(pageUsageDetails, utilizers[i], PageMockHelper.UTILIZERS.length, pageList.get(i), pageDto.getStatus());
});
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class PageServiceTest method mockPagedMetadata.
/**
* init mock for a multipaged request
*/
private void mockPagedMetadata(Page page, PageDto pageDto, String[] utilizers, int currPage, int lastPage, int pageSize, int totalSize) {
try {
when(pageManager.getDraftPage(page.getCode())).thenReturn(page);
when(pageTokenManager.encrypt(page.getCode())).thenReturn(PageMockHelper.TOKEN);
when(dtoBuilder.convert(any(IPage.class))).thenReturn(pageDto);
when(applicationContext.getBeanNamesForType((Class<?>) any())).thenReturn(PageMockHelper.UTILIZERS);
when(applicationContext.getBean(anyString())).thenReturn(pageUtilizer);
when(pageUtilizer.getPageUtilizers(page.getCode())).thenReturn(Arrays.asList(PageMockHelper.UTILIZERS));
when(pageUtilizer.getName()).thenReturn(PageMockHelper.UTILIZER_1).thenReturn(PageMockHelper.UTILIZER_2);
PageSearchRequest pageSearchRequest = new PageSearchRequest(PageMockHelper.PAGE_CODE);
pageSearchRequest.setPageSize(pageSize);
PageSearchDto pageSearchDto = new PageSearchDto(pageSearchRequest, Collections.singletonList(pageDto));
pageSearchDto.setPageSize(pageSize);
pageSearchDto.imposeLimits();
List<ComponentUsageEntity> componentUsageEntityList = Arrays.stream(utilizers).map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child)).collect(Collectors.toList());
if (pageDto.getStatus().equals(IPageService.STATUS_ONLINE) && currPage == lastPage) {
componentUsageEntityList.add(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, page.getCode()));
}
PagedMetadata pagedMetadata = new PagedMetadata(pageSearchRequest, componentUsageEntityList, totalSize);
pagedMetadata.setPageSize(pageSize);
pagedMetadata.setPage(currPage);
pagedMetadata.imposeLimits();
when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
} catch (Exception e) {
Assert.fail("Mock Exception");
}
}
Aggregations