Search in sources :

Example 1 with PageSearchRequest

use of org.entando.entando.web.page.model.PageSearchRequest in project entando-core by entando.

the class WidgetServiceTest method getWidgetUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException.

@Test
public void getWidgetUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException() throws Exception {
    Page page1 = PageMockHelper.mockTestPage(PageMockHelper.PAGE_MISSION_CODE, WidgetMockHelper.WIDGET_1_CODE);
    Page page2 = PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE, WidgetMockHelper.WIDGET_1_CODE);
    List mockedPageList = Arrays.asList(page1, page2);
    mockPagedMetadata(Arrays.asList(PageMockHelper.PAGE_MISSION_CODE, PageMockHelper.PAGE_CODE), 1, 1, 100, 4);
    PageSearchRequest pageSearchRequest = new PageSearchRequest(PageMockHelper.PAGE_CODE);
    Arrays.stream(new String[] { "not existing", null, "" }).forEach(code -> {
        try {
            widgetService.getComponentUsageDetails(code, pageSearchRequest);
            fail("NoSuchElementException NOT thrown with code " + code);
        } catch (Exception e) {
            assertTrue(e instanceof NoSuchElementException || e instanceof NullPointerException);
        }
    });
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) ImmutableList(com.google.common.collect.ImmutableList) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Example 2 with PageSearchRequest

use of org.entando.entando.web.page.model.PageSearchRequest 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);
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Test(org.junit.Test)

Example 3 with PageSearchRequest

use of org.entando.entando.web.page.model.PageSearchRequest 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());
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Test(org.junit.Test)

Example 4 with PageSearchRequest

use of org.entando.entando.web.page.model.PageSearchRequest 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);
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) Lang(com.agiletec.aps.system.services.lang.Lang) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Test(org.junit.Test)

Example 5 with PageSearchRequest

use of org.entando.entando.web.page.model.PageSearchRequest 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));
    });
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ImmutableList(com.google.common.collect.ImmutableList) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Test(org.junit.Test)

Aggregations

PageSearchRequest (org.entando.entando.web.page.model.PageSearchRequest)12 ComponentUsageEntity (org.entando.entando.web.component.ComponentUsageEntity)8 Test (org.junit.Test)7 IPage (com.agiletec.aps.system.services.page.IPage)4 Page (com.agiletec.aps.system.services.page.Page)4 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 Group (com.agiletec.aps.system.services.group.Group)1 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)1 Lang (com.agiletec.aps.system.services.lang.Lang)1 IPageManager (com.agiletec.aps.system.services.page.IPageManager)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 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1