Search in sources :

Example 1 with PageSearchDto

use of org.entando.entando.aps.system.services.page.model.PageSearchDto 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");
    }
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) java.util(java.util) Page(com.agiletec.aps.system.services.page.Page) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) Group(com.agiletec.aps.system.services.group.Group) PageAssertionHelper(org.entando.entando.aps.system.services.assertionhelper.PageAssertionHelper) IPage(com.agiletec.aps.system.services.page.IPage) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) PageMockHelper(org.entando.entando.aps.system.services.mockhelper.PageMockHelper) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) PageSearchMapper(org.entando.entando.web.common.assembler.PageSearchMapper) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) PageRequest(org.entando.entando.web.page.model.PageRequest) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Assertions.fail(org.assertj.core.api.Assertions.fail) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IPage(com.agiletec.aps.system.services.page.IPage) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 2 with PageSearchDto

use of org.entando.entando.aps.system.services.page.model.PageSearchDto in project entando-core by entando.

the class PageSearchMapper method toPageSearchDto.

/**
 * craetes a PageSearchDto starting from the received data
 *
 * @param request
 * @param pages
 * @return the created
 */
public PagedMetadata<PageDto> toPageSearchDto(PageSearchRequest request, List<PageDto> pages) {
    BeanComparator<PageDto> comparator = new BeanComparator<>(request.getSort());
    if (request.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
        pages.sort(comparator.reversed());
    } else {
        pages.sort(comparator);
    }
    PageSearchDto result = new PageSearchDto(request, pages);
    result.imposeLimits();
    return result;
}
Also used : PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 3 with PageSearchDto

use of org.entando.entando.aps.system.services.page.model.PageSearchDto in project entando-core by entando.

the class PageService method getPagedResult.

private PagedMetadata<PageDto> getPagedResult(PageSearchRequest request, List<PageDto> pages) {
    BeanComparator comparator = new BeanComparator(request.getSort());
    if (request.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
        Collections.sort(pages, comparator.reversed());
    } else {
        Collections.sort(pages, comparator);
    }
    PageSearchDto result = new PageSearchDto(request, pages);
    result.imposeLimits();
    return result;
}
Also used : PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Aggregations

PageSearchDto (org.entando.entando.aps.system.services.page.model.PageSearchDto)3 BeanComparator (org.apache.commons.beanutils.BeanComparator)2 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)2 Group (com.agiletec.aps.system.services.group.Group)1 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)1 IPage (com.agiletec.aps.system.services.page.IPage)1 IPageManager (com.agiletec.aps.system.services.page.IPageManager)1 Page (com.agiletec.aps.system.services.page.Page)1 PageUtilizer (com.agiletec.aps.system.services.page.PageUtilizer)1 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)1 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)1 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)1 PageAssertionHelper (org.entando.entando.aps.system.services.assertionhelper.PageAssertionHelper)1 PageMockHelper (org.entando.entando.aps.system.services.mockhelper.PageMockHelper)1