use of org.entando.entando.web.page.model.PageSearchRequest in project entando-core by entando.
the class PageServiceTest method getPageUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException.
@Test
public void getPageUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException() {
PageDto pageDto = PageMockHelper.mockPageDto();
mockForSinglePage(PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE), pageDto, PageMockHelper.UTILIZERS);
Arrays.stream(new String[] { "not existing", null, "" }).forEach(code -> {
try {
pageService.getComponentUsageDetails(code, new PageSearchRequest(PageMockHelper.PAGE_CODE));
fail("ResourceNotFoundException NOT thrown with code " + code);
} catch (Exception e) {
assertTrue(e instanceof ResourceNotFoundException);
}
});
}
use of org.entando.entando.web.page.model.PageSearchRequest 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.page.model.PageSearchRequest 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");
}
}
use of org.entando.entando.web.page.model.PageSearchRequest in project entando-core by entando.
the class PageModelServiceTest method getPageModelUsageTest.
@Test
public void getPageModelUsageTest() {
String managerName = "PageManager";
PageModel pageModel = PageMockHelper.mockServicePageModel();
PageDto pageDto = PageMockHelper.mockPageDto();
Map<String, Object> pageModelServiceUtilizerMap = new HashMap<>();
pageModelServiceUtilizerMap.put(managerName, pageModelServiceUtilizer);
when(pageModelManager.getPageModel(Mockito.anyString())).thenReturn(pageModel);
when(applicationContext.getBeansOfType(any())).thenReturn(pageModelServiceUtilizerMap);
when(pageModelServiceUtilizer.getManagerName()).thenReturn(managerName);
when(pageModelServiceUtilizer.getPageModelUtilizer(Mockito.anyString())).thenReturn(Collections.singletonList(pageDto));
RestListRequest restListRequest = new RestListRequest();
restListRequest.setPageSize(1);
List<ComponentUsageEntity> componentUsageEntityList = Arrays.asList(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, PageMockHelper.PAGE_CODE, IPageService.STATUS_ONLINE));
PagedMetadata pagedMetadata = new PagedMetadata(restListRequest, componentUsageEntityList, 1);
pagedMetadata.setPageSize(1);
pagedMetadata.setPage(1);
pagedMetadata.imposeLimits();
when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
PagedMetadata<ComponentUsageEntity> usageDetails = pageModelService.getComponentUsageDetails(pageModel.getCode(), new PageSearchRequest(pageModel.getCode()));
PageModelAssertionHelper.assertUsageDetails(usageDetails);
}
use of org.entando.entando.web.page.model.PageSearchRequest in project entando-core by entando.
the class PageServiceTest method testSinglePageUsageDetails.
/**
* contains generic code to test a single paged page usage details
*
* @param pageDto
* @throws Exception
*/
private void testSinglePageUsageDetails(PageDto pageDto) {
Page page = PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE);
mockForSinglePage(page, pageDto, PageMockHelper.UTILIZERS);
PagedMetadata<ComponentUsageEntity> pageUsageDetails = pageService.getComponentUsageDetails(PageMockHelper.PAGE_CODE, new PageSearchRequest(PageMockHelper.PAGE_CODE));
PageAssertionHelper.assertUsageDetails(pageUsageDetails, pageDto.getStatus());
}
Aggregations