use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class PageService method getComponentUsageDetails.
@Override
public PagedMetadata<ComponentUsageEntity> getComponentUsageDetails(String pageCode, RestListRequest restListRequest) {
PageDto pageDto = this.getPage(pageCode, IPageService.STATUS_DRAFT);
List<PageDto> childrenPageDtoList = this.getPages(pageCode);
List<ComponentUsageEntity> componentUsageEntityList = childrenPageDtoList.stream().map(childPageDto -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, childPageDto.getCode(), childPageDto.getStatus())).collect(Collectors.toList());
if (pageDto.getStatus().equals(IPageService.STATUS_ONLINE)) {
componentUsageEntityList.add(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, pageDto.getCode(), pageDto.getStatus()));
}
return pagedMetadataMapper.getPagedResult(restListRequest, componentUsageEntityList);
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class PageModelAssertionHelper method assertUsageDetails.
/**
* does assertions on the received PagedMetadata basing on the default PageMockHelper mocked data
* @param usageDetails
*/
public static void assertUsageDetails(PagedMetadata<ComponentUsageEntity> usageDetails) {
assertEquals(1, usageDetails.getTotalItems());
assertEquals(1, usageDetails.getBody().size());
assertEquals(1, usageDetails.getPage());
ComponentUsageEntity expected = new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_ONLINE);
ComponentUsageEntityAssertionHelper.assertComponentUsageEntity(expected, usageDetails.getBody().get(0));
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class WidgetAssertionHelper method assertUsageDetails.
/**
* does assertions on the received PagedMetadata basing on the default WidgetMockHelper mocked data
* @param usageDetails
*/
public static void assertUsageDetails(PagedMetadata<ComponentUsageEntity> usageDetails) {
List<ComponentUsageEntity> usageEntityList = Arrays.asList(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_ONLINE), new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_DRAFT));
assertUsageDetails(usageDetails, usageEntityList, usageEntityList.size(), 1);
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-engine 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);
Mockito.lenient().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) {
Assertions.fail("Mock Exception");
}
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-engine by entando.
the class WidgetServiceTest method getWidgetUsageDetailsWithPagination.
@Test
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));
});
}
Aggregations