Search in sources :

Example 16 with PageRequest

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

the class PageServiceIntegrationTest method testUpdatePageStatus.

@Test
public void testUpdatePageStatus() {
    String newPageCode = "pagina_13";
    try {
        PageDto pageToClone = pageService.getPage("pagina_11", "draft");
        assertNotNull(pageToClone);
        PageRequest pageRequest = this.createRequestFromDto(pageToClone);
        pageRequest.setCode(newPageCode);
        PageDto addedPage = pageService.addPage(pageRequest);
        assertNotNull(addedPage);
        assertEquals(newPageCode, addedPage.getCode());
        assertEquals("pagina_1", addedPage.getParentCode());
        addedPage = pageService.getPage(newPageCode, "draft");
        assertEquals("unpublished", addedPage.getStatus());
        PageStatusRequest pageStatusRequest = new PageStatusRequest();
        pageStatusRequest.setStatus("published");
        PageDto modPage = pageService.updatePageStatus(newPageCode, pageStatusRequest.getStatus());
        assertNotNull(modPage);
        assertEquals("published", modPage.getStatus());
        addedPage = pageService.getPage(newPageCode, "published");
        assertNotNull(addedPage);
        assertEquals("published", addedPage.getStatus());
    } catch (Exception e) {
        throw e;
    } finally {
        pageService.removePage(newPageCode);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) PageStatusRequest(org.entando.entando.web.page.model.PageStatusRequest) Test(org.junit.Test)

Example 17 with PageRequest

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

the class PageServiceIntegrationTest method testChangeOnlyPosition.

@Test
public void testChangeOnlyPosition() {
    String newPageCode = "pagina_13";
    try {
        PageDto pageToClone = pageService.getPage("pagina_11", "draft");
        assertNotNull(pageToClone);
        PageRequest pageRequest = this.createRequestFromDto(pageToClone);
        pageRequest.setCode(newPageCode);
        PageDto addedPage = pageService.addPage(pageRequest);
        assertNotNull(addedPage);
        assertEquals("pagina_1", addedPage.getParentCode());
        assertEquals(3, addedPage.getPosition());
        PagePositionRequest pagePosRequest = new PagePositionRequest();
        pagePosRequest.setCode(newPageCode);
        pagePosRequest.setParentCode("pagina_1");
        pagePosRequest.setPosition(1);
        addedPage = pageService.movePage(newPageCode, pagePosRequest);
        assertNotNull(addedPage);
        assertEquals("pagina_1", addedPage.getParentCode());
        assertEquals(1, addedPage.getPosition());
    } catch (Exception e) {
        throw e;
    } finally {
        pageService.removePage(newPageCode);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 18 with PageRequest

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

the class PageServiceIntegrationTest method createRequestFromDto.

private PageRequest createRequestFromDto(PageDto pageToClone) {
    PageRequest request = new PageRequest();
    request.setCharset(pageToClone.getCharset());
    request.setCode(pageToClone.getCode());
    request.setContentType(pageToClone.getContentType());
    request.setDisplayedInMenu(pageToClone.isDisplayedInMenu());
    request.setJoinGroups(pageToClone.getJoinGroups());
    request.setOwnerGroup(pageToClone.getOwnerGroup());
    request.setPageModel(pageToClone.getPageModel());
    request.setParentCode(pageToClone.getParentCode());
    request.setSeo(pageToClone.isSeo());
    // request.setStatus(pageToClone.getStatus());
    Map<String, String> titles = new HashMap<>();
    pageToClone.getTitles().keySet().forEach(lang -> titles.put(lang, pageToClone.getTitles().get(lang)));
    request.setTitles(titles);
    return request;
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) HashMap(java.util.HashMap)

Example 19 with PageRequest

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

the class PageControllerIntegrationTest method testPageAddUpdateDelete.

@Test
public void testPageAddUpdateDelete() throws Exception {
    String pageCode = "page_update_test";
    String widgetCode = "login_form";
    PageRequest pageRequest = new PageRequest();
    pageRequest.setCode(pageCode);
    pageRequest.setPageModel("home");
    pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
    Map<String, String> titles = new HashMap<>();
    titles.put("it", pageCode);
    titles.put("en", pageCode);
    pageRequest.setTitles(titles);
    pageRequest.setParentCode("homepage");
    WidgetConfigurationRequest widgetRequest = new WidgetConfigurationRequest();
    widgetRequest.setCode(widgetCode);
    widgetRequest.setConfig(new HashMap<>());
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").withAuthorization(Group.FREE_GROUP_NAME, "managePages", Permission.MANAGE_PAGES).build();
    String accessToken = mockOAuthInterceptor(user);
    try {
        mockMvc.perform(post("/pages", pageCode).header("Authorization", "Bearer " + accessToken).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(pageRequest))).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload.code", is(pageCode))).andExpect(jsonPath("$.payload.numWidget", is(0)));
        mockMvc.perform(put("/pages/{code}/widgets/{frame}", pageCode, 0).header("Authorization", "Bearer " + accessToken).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(widgetRequest))).andDo(print()).andExpect(status().isOk());
        mockMvc.perform(put("/pages/{code}", pageCode).header("Authorization", "Bearer " + accessToken).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(pageRequest))).andDo(print()).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload.code", is(pageCode))).andExpect(jsonPath("$.payload.numWidget", is(1)));
    } finally {
        mockMvc.perform(delete("/pages/{code}", pageCode).header("Authorization", "Bearer " + accessToken)).andExpect(status().isOk());
    }
}
Also used : WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 20 with PageRequest

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

the class PageControllerIntegrationTest method testPutOnPageWithChildren.

@Test
public void testPutOnPageWithChildren() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").withAuthorization(Group.FREE_GROUP_NAME, "managePages", Permission.MANAGE_PAGES).build();
    String accessToken = mockOAuthInterceptor(user);
    String parentPageCode = "pageWithChildren";
    String childrenPageCode = "childrenPage";
    try {
        // Posting parent page
        PageRequest pageRequest = new PageRequest();
        pageRequest.setCode(parentPageCode);
        pageRequest.setPageModel("home");
        pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
        Map<String, String> titles = new HashMap<>();
        titles.put("it", parentPageCode);
        titles.put("en", parentPageCode);
        pageRequest.setTitles(titles);
        pageRequest.setParentCode("homepage");
        this.addPage(accessToken, pageRequest);
        IPage page = this.pageManager.getDraftPage(parentPageCode);
        assertThat(page, is(not(nullValue())));
        Assert.assertEquals(0, page.getChildrenCodes().length);
        // Adding children
        pageRequest.setCode(childrenPageCode);
        pageRequest.setParentCode(parentPageCode);
        this.addPage(accessToken, pageRequest);
        page = this.pageManager.getDraftPage(childrenPageCode);
        assertThat(page, is(not(nullValue())));
        Assert.assertEquals(0, page.getChildrenCodes().length);
        page = this.pageManager.getDraftPage(parentPageCode);
        assertThat(page, is(not(nullValue())));
        Assert.assertEquals(1, page.getChildrenCodes().length);
        // Updating parentPage
        pageRequest.setCode(parentPageCode);
        pageRequest.setParentCode("homepage");
        pageRequest.getTitles().put("it", parentPageCode.toUpperCase());
        ResultActions result = mockMvc.perform(put("/pages/{code}", parentPageCode).content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk()).andDo(print());
        page = this.pageManager.getDraftPage(parentPageCode);
        assertThat(page, is(not(nullValue())));
        Assert.assertEquals(1, page.getChildrenCodes().length);
    } finally {
        this.pageManager.deletePage(childrenPageCode);
        this.pageManager.deletePage(parentPageCode);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

PageRequest (org.entando.entando.web.page.model.PageRequest)27 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)11 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 IPage (com.agiletec.aps.system.services.page.IPage)8 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)8 ResultActions (org.springframework.test.web.servlet.ResultActions)8 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)7 Page (com.agiletec.aps.system.services.page.Page)6 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)6 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 IManager (com.agiletec.aps.system.common.IManager)3 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Group (com.agiletec.aps.system.services.group.Group)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)3 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3