Search in sources :

Example 66 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class TestRequestAuthorizator method testService_1.

public void testService_1() throws Throwable {
    RequestContext reqCtx = this.getRequestContext();
    this.setUserOnSession(SystemConstants.GUEST_USER_NAME);
    IPage root = this._pageManager.getOnlineRoot();
    reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, root);
    int status = _authorizator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
    assertNull(redirectUrl);
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) RequestContext(com.agiletec.aps.system.RequestContext)

Example 67 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class TestWidgetExecutorService method testExecutor.

public void testExecutor() throws Exception {
    super.setUserOnSession("admin");
    IPageManager pageManager = (IPageManager) super.getApplicationContext().getBean(SystemConstants.PAGE_MANAGER);
    IPage currentPage = pageManager.getOnlinePage("homepage");
    super.getRequestContext().addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, currentPage);
    ExecutorServiceInterface wes = (ExecutorServiceInterface) super.getApplicationContext().getBean("WidgetExecutorService");
    wes.service(super.getRequestContext());
    String[] widgetOutput = (String[]) super.getRequestContext().getExtraParam("ShowletOutput");
    assertNotNull(widgetOutput);
    assertEquals(currentPage.getModel().getFrames().length, widgetOutput.length);
    for (int i = 0; i < widgetOutput.length; i++) {
        String output = widgetOutput[i];
        assertNotNull(output);
        Widget currentWidget = currentPage.getWidgets()[i];
        if (null == currentWidget) {
            assertTrue(StringUtils.isBlank(output));
        } else {
            GuiFragment fragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(currentWidget.getType().getCode());
            if (null == fragment) {
                assertTrue(StringUtils.isBlank(output));
            } else {
                assertTrue(StringUtils.isNotBlank(output));
            }
        }
    }
}
Also used : IPageManager(com.agiletec.aps.system.services.page.IPageManager) IPage(com.agiletec.aps.system.services.page.IPage) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Widget(com.agiletec.aps.system.services.page.Widget)

Example 68 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class ActivityStreamControllerIntegrationTest method initTestObjects.

private void initTestObjects(String accessToken, String... pageCodes) throws Exception {
    for (String pageCode : pageCodes) {
        PageModel pageModel = this.pageModelManager.getPageModel("internal");
        Page mockPage = createPage(pageCode, pageModel);
        mockPage.setWidgets(new Widget[pageModel.getFrames().length]);
        this.pageManager.addPage(mockPage);
        IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
        assertThat(onlinePage, is(nullValue()));
        IPage draftPage = this.pageManager.getDraftPage(pageCode);
        assertThat(draftPage, is(not(nullValue())));
        // execute and action
        ResultActions result = mockMvc.perform(put("/pages/{pageCode}/configuration/defaultWidgets", new Object[] { pageCode }).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        synchronized (this) {
            this.wait(1000);
        }
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResultActions(org.springframework.test.web.servlet.ResultActions)

Example 69 with IPage

use of com.agiletec.aps.system.services.page.IPage 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");
    }
}
Also used : ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ArgumentMatchers(org.mockito.ArgumentMatchers) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterOperator(org.entando.entando.web.common.model.FilterOperator) Group(com.agiletec.aps.system.services.group.Group) IPage(com.agiletec.aps.system.services.page.IPage) IPageService(org.entando.entando.aps.system.services.page.IPageService) 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) PageMockHelper(org.entando.entando.aps.system.services.mockhelper.PageMockHelper) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ImmutableMap(com.google.common.collect.ImmutableMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Collectors(java.util.stream.Collectors) RestListRequest(org.entando.entando.web.common.model.RestListRequest) Stream(java.util.stream.Stream) Assertions.fail(org.assertj.core.api.Assertions.fail) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) IntStream(java.util.stream.IntStream) java.util(java.util) Page(com.agiletec.aps.system.services.page.Page) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Function(java.util.function.Function) PageAssertionHelper(org.entando.entando.aps.system.services.assertionhelper.PageAssertionHelper) WidgetDtoBuilder(org.entando.entando.aps.system.services.widgettype.model.WidgetDtoBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) WidgetAssertionHelper(org.entando.entando.aps.system.services.assertionhelper.WidgetAssertionHelper) IPageManager(com.agiletec.aps.system.services.page.IPageManager) IComponentManager(org.entando.entando.aps.system.init.IComponentManager) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IGuiFragmentManager(org.entando.entando.aps.system.services.guifragment.IGuiFragmentManager) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) Filter(org.entando.entando.web.common.model.Filter) WidgetMockHelper(org.entando.entando.aps.system.services.mockhelper.WidgetMockHelper) Assert(org.junit.Assert) IPage(com.agiletec.aps.system.services.page.IPage) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) RestListRequest(org.entando.entando.web.common.model.RestListRequest) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 70 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageServiceIntegrationTest method testUpdatePage.

@Test
public void testUpdatePage() {
    String newCode = "pagina_13";
    PageDto pageToClone = pageService.getPage("pagina_12", "draft");
    try {
        assertNotNull(pageToClone);
        assertEquals(2, pageToClone.getTitles().size());
        assertEquals("Pagina 1-2", pageToClone.getTitles().get("it"));
        PageDto parentPage = pageService.getPage(pageToClone.getParentCode(), "draft");
        assertEquals(2, parentPage.getChildren().size());
        PageRequest pageRequest = this.createRequestFromDto(pageToClone);
        pageRequest.setCode(newCode);
        pageRequest.getTitles().put("en", "Page 1-3");
        pageRequest.getTitles().put("it", "Pagina 1-3");
        PageDto addedPage = pageService.addPage(pageRequest);
        assertEquals(3, addedPage.getPosition());
        parentPage = pageService.getPage(addedPage.getParentCode(), "draft");
        assertEquals(3, parentPage.getChildren().size());
        assertEquals(newCode, parentPage.getChildren().get(2));
        IPage newDraftPage = this.pageManager.getDraftPage(newCode);
        assertEquals(3, newDraftPage.getPosition());
        PageRequest newPageRequest = this.createRequestFromDto(addedPage);
        newPageRequest.getTitles().put("it", "Pagina 1-3 mod");
        PageDto modPage = pageService.updatePage(newCode, newPageRequest);
        assertNotNull(modPage);
        assertEquals(2, modPage.getTitles().size());
        assertEquals("Pagina 1-3 mod", modPage.getTitles().get("it"));
        assertEquals(3, modPage.getPosition());
        newDraftPage = this.pageManager.getDraftPage(newCode);
        assertEquals(3, newDraftPage.getPosition());
        modPage = pageService.getPage(newCode, "draft");
        assertNotNull(modPage);
        assertEquals(2, modPage.getTitles().size());
        assertEquals("Pagina 1-3 mod", modPage.getTitles().get("it"));
        assertEquals(3, modPage.getPosition());
        newPageRequest.getTitles().put("it", "Pagina 1-3");
        modPage = pageService.updatePage(newCode, newPageRequest);
        assertEquals(3, modPage.getPosition());
        modPage = pageService.getPage(newCode, "draft");
        assertNotNull(modPage);
        assertEquals(2, modPage.getTitles().size());
        assertEquals("Pagina 1-3", modPage.getTitles().get("it"));
        assertEquals(3, modPage.getPosition());
    } catch (Exception e) {
        throw e;
    } finally {
        this.pageService.removePage(newCode);
        assertNull(pageManager.getDraftPage(newCode));
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) IPage(com.agiletec.aps.system.services.page.IPage) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Test(org.junit.Test)

Aggregations

IPage (com.agiletec.aps.system.services.page.IPage)253 Widget (com.agiletec.aps.system.services.page.Widget)55 ArrayList (java.util.ArrayList)41 Page (com.agiletec.aps.system.services.page.Page)37 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)30 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)25 HashMap (java.util.HashMap)23 ApsProperties (com.agiletec.aps.util.ApsProperties)20 List (java.util.List)20 RestServerError (org.entando.entando.aps.system.exception.RestServerError)18 IPageManager (com.agiletec.aps.system.services.page.IPageManager)16 UserDetails (com.agiletec.aps.system.services.user.UserDetails)16 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)16 RequestContext (com.agiletec.aps.system.RequestContext)15 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)15 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)15 Test (org.junit.Test)14 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)13 Lang (com.agiletec.aps.system.services.lang.Lang)12 ResultActions (org.springframework.test.web.servlet.ResultActions)12