Search in sources :

Example 6 with PageRequest

use of org.entando.entando.web.page.model.PageRequest 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)

Example 7 with PageRequest

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

the class PageMockHelper method mockPageRequest.

public static PageRequest mockPageRequest(Page page) {
    PageRequest request = new PageRequest();
    request.setPageModel(page.getModel().getCode());
    request.setParentCode(page.getParentCode());
    request.setOwnerGroup(page.getGroup());
    return request;
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest)

Example 8 with PageRequest

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

the class PageControllerTest method shouldValidatePostConflict.

@Test
public void shouldValidatePostConflict() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageRequest page = new PageRequest();
    page.setCode("existing_page");
    page.setPageModel("existing_model");
    page.setParentCode("existing_parent");
    page.setOwnerGroup("existing_group");
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    when(this.controller.getPageValidator().getPageManager().getDraftPage(any(String.class))).thenReturn(new Page());
    ResultActions result = mockMvc.perform(post("/pages").sessionAttr("user", user).content(convertObjectToJsonBytes(page)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isConflict());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageValidator.ERRCODE_PAGE_ALREADY_EXISTS)));
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Page(com.agiletec.aps.system.services.page.Page) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 9 with PageRequest

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

the class PageControllerIntegrationTest method testAddPublishUnpublishDelete.

@Test
public void testAddPublishUnpublishDelete() 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 code = "testAddDelete";
    try {
        PageRequest pageRequest = new PageRequest();
        pageRequest.setCode(code);
        pageRequest.setPageModel("home");
        pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
        Map<String, String> titles = new HashMap<>();
        titles.put("it", code);
        titles.put("en", code);
        pageRequest.setTitles(titles);
        pageRequest.setParentCode("service");
        this.addPage(accessToken, pageRequest);
        IPage page = this.pageManager.getDraftPage(code);
        assertThat(page, is(not(nullValue())));
        Assert.assertEquals(6, page.getWidgets().length);
        // put (move the page changing parent from service to homepage)
        String newParentCode = "homepage";
        pageRequest.setParentCode(newParentCode);
        pageRequest.getTitles().put("it", code.toUpperCase());
        ResultActions result = mockMvc.perform(put("/pages/{code}", code).content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        assertThat(page.getParentCode(), is(newParentCode));
        // put
        pageRequest.setParentCode("service");
        pageRequest.setOwnerGroup(Group.ADMINS_GROUP_NAME);
        pageRequest.getTitles().put("it", code.toUpperCase());
        result = mockMvc.perform(put("/pages/{code}", code).content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isBadRequest());
        result.andExpect(jsonPath("$.errors.size()", is(1)));
        result.andExpect(jsonPath("$.errors[0].code", is("2")));
        // put
        pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
        pageRequest.getTitles().put("it", code.toUpperCase());
        result = mockMvc.perform(put("/pages/{code}", code).content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        assertThat(page, is(not(nullValue())));
        assertThat(page.getTitle("it"), is(code.toUpperCase()));
        // put
        pageRequest.setPageModel("service");
        pageRequest.getTitles().put("it", "new Italian title");
        result = mockMvc.perform(put("/pages/{code}", code).content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        Assert.assertEquals(4, page.getWidgets().length);
        Assert.assertEquals("new Italian title", page.getTitle("it"));
        // status
        PageStatusRequest pageStatusRequest = new PageStatusRequest();
        pageStatusRequest.setStatus("published");
        result = mockMvc.perform(put("/pages/{code}/status", code).content(mapper.writeValueAsString(pageStatusRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        assertThat(page, is(not(nullValue())));
        IPage onlinePage = this.pageManager.getOnlinePage(code);
        assertThat(onlinePage, is(not(nullValue())));
        pageStatusRequest.setStatus("draft");
        result = mockMvc.perform(put("/pages/{code}/status", code).content(mapper.writeValueAsString(pageStatusRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        assertThat(page, is(not(nullValue())));
        onlinePage = this.pageManager.getOnlinePage(code);
        assertThat(onlinePage, is(nullValue()));
        // delete
        result = mockMvc.perform(delete("/pages/{code}", code).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        page = this.pageManager.getDraftPage(code);
        assertThat(page, is(nullValue()));
    } finally {
        this.pageManager.deletePage(code);
    }
}
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) PageStatusRequest(org.entando.entando.web.page.model.PageStatusRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 10 with PageRequest

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

the class PageControllerIntegrationTest method addPagesForUsageDetailsTest.

/**
 * insert some pages useful to test
 */
private void addPagesForUsageDetailsTest(boolean publishParentPage, String adminAccessToken, boolean addSecondChildPage) throws Exception {
    // add base page
    PageRequest pageRequest = PageRequestMockHelper.mockPageRequest();
    this.addPage(adminAccessToken, pageRequest);
    if (publishParentPage) {
        this.pageManager.setPageOnline(PageRequestMockHelper.ADD_PAGE_CODE);
    }
    // add first child page
    PageRequest firstChildPageRequest = PageRequestMockHelper.mockPageRequest();
    firstChildPageRequest.setCode(PageRequestMockHelper.ADD_FIRST_CHILD_PAGE_CODE);
    firstChildPageRequest.setParentCode(PageRequestMockHelper.ADD_PAGE_CODE);
    this.addPage(adminAccessToken, firstChildPageRequest);
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest)

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