use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class WidgetServiceTest method getWidgetUsageDetails.
@Test
public void getWidgetUsageDetails() throws Exception {
this.mockPagedMetadata(Arrays.asList(PageMockHelper.PAGE_CODE), 1, 1, 100, 2);
PagedMetadata<ComponentUsageEntity> usageDetails = widgetService.getComponentUsageDetails(WidgetMockHelper.WIDGET_1_CODE, new PageSearchRequest(WidgetMockHelper.WIDGET_1_CODE));
WidgetAssertionHelper.assertUsageDetails(usageDetails);
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class WidgetServiceTest method mockPagedMetadata.
/**
* init mock for a multipaged request
*/
private void mockPagedMetadata(List<String> utilizers, int currPage, int lastPage, int pageSize, int totalSize) {
try {
List<IPage> onlinePageList = utilizers.stream().map(u -> PageMockHelper.mockTestPage(u, WidgetMockHelper.WIDGET_1_CODE)).collect(Collectors.toList());
List<IPage> draftPageList = utilizers.stream().map(u -> PageMockHelper.mockTestPage(u, WidgetMockHelper.WIDGET_1_CODE)).collect(Collectors.toList());
when(pageManager.getOnlineWidgetUtilizers(anyString())).thenReturn(onlinePageList);
when(pageManager.getDraftWidgetUtilizers(anyString())).thenReturn(draftPageList);
when(widgetManager.getWidgetType(anyString())).thenReturn(WidgetMockHelper.mockWidgetType());
RestListRequest restListRequest = new RestListRequest();
restListRequest.setPageSize(pageSize);
restListRequest.setPage(currPage);
List<ComponentUsageEntity> componentUsageEntityList = onlinePageList.stream().map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child.getCode(), IPageService.STATUS_ONLINE)).collect(Collectors.toList());
componentUsageEntityList.addAll(draftPageList.stream().map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child.getCode(), IPageService.STATUS_DRAFT)).collect(Collectors.toList()));
PagedMetadata pagedMetadata = new PagedMetadata(restListRequest, componentUsageEntityList, totalSize);
pagedMetadata.setPageSize(pageSize);
pagedMetadata.setPage(currPage);
pagedMetadata.imposeLimits();
when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
} catch (Exception e) {
Assert.fail("Mock Exception");
}
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class PageServiceTest method getPageUsageDetailsWithNoChildrenShouldReturnItself.
@Test
public void getPageUsageDetailsWithNoChildrenShouldReturnItself() {
PageDto pageDto = PageMockHelper.mockPageDto();
pageDto.setChildren(new ArrayList<>());
mockForSinglePage(PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE), pageDto, new String[0]);
PagedMetadata<ComponentUsageEntity> pageUsageDetails = pageService.getComponentUsageDetails(PageMockHelper.PAGE_CODE, new PageSearchRequest(PageMockHelper.PAGE_CODE));
PageAssertionHelper.assertUsageDetails(pageUsageDetails, new String[0], 0, 1, pageDto.getStatus());
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class GuiFragmentServiceTest method getFragmentUsageTest.
@Test
public void getFragmentUsageTest() throws Exception {
Lang lang = new Lang();
lang.setCode("IT");
when(langManager.getDefaultLang()).thenReturn(lang);
GuiFragment fragment = FragmentMockHelper.mockGuiFragment();
GuiFragmentDto fragmentDto = FragmentMockHelper.mockGuiFragmentDto(fragment, langManager);
mockPagedMetadata(fragment, fragmentDto, 1, 1, 100, 5);
PagedMetadata<ComponentUsageEntity> componentUsageDetails = guiFragmentService.getComponentUsageDetails(fragment.getCode(), new PageSearchRequest(PageMockHelper.PAGE_CODE));
GuiFragmentAssertionHelper.assertUsageDetails(componentUsageDetails);
}
use of org.entando.entando.web.component.ComponentUsageEntity in project entando-core by entando.
the class GuiFragmentServiceTest method mockPagedMetadata.
/**
* init mock for a multipaged request
*/
private void mockPagedMetadata(GuiFragment fragment, GuiFragmentDto fragmentDto, int currPage, int lastPage, int pageSize, int totalSize) {
try {
when(guiFragmentManager.getGuiFragment(anyString())).thenReturn(fragment);
when(this.dtoBuilder.convert(any(GuiFragment.class))).thenReturn(fragmentDto);
RestListRequest restListRequest = new RestListRequest();
restListRequest.setPageSize(pageSize);
ComponentUsageEntity componentUsageEntity = new ComponentUsageEntity(ComponentUsageEntity.TYPE_WIDGET, fragmentDto.getWidgetTypeCode());
List<ComponentUsageEntity> fragmentList = fragmentDto.getFragments().stream().map(fragmentRef -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_FRAGMENT, fragmentRef.getCode())).collect(Collectors.toList());
List<ComponentUsageEntity> pageModelList = fragmentDto.getPageModels().stream().map(pageModelRef -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE_TEMPLATE, pageModelRef.getCode())).collect(Collectors.toList());
List<ComponentUsageEntity> componentUsageEntityList = new ArrayList<>();
componentUsageEntityList.add(componentUsageEntity);
componentUsageEntityList.addAll(fragmentList);
componentUsageEntityList.addAll(pageModelList);
PagedMetadata pagedMetadata = new PagedMetadata(restListRequest, 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