Search in sources :

Example 1 with PagePositionRequest

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

the class PageControllerTest method shouldValidateMovePageInvalidRequest.

@Test
public void shouldValidateMovePageInvalidRequest() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagePositionRequest request = new PagePositionRequest();
    request.setCode("page_to_move");
    request.setParentCode(null);
    request.setPosition(0);
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}/position", "page_to_move").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is("NotBlank")));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 2 with PagePositionRequest

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

the class PageControllerTest method shouldValidateMovePageStatusMismatch.

@Test
public void shouldValidateMovePageStatusMismatch() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagePositionRequest request = new PagePositionRequest();
    request.setCode("page_to_move");
    request.setParentCode("new_parent_page");
    request.setPosition(1);
    PageM pageToMove = new PageM(true);
    pageToMove.setCode("page_to_move");
    pageToMove.setParentCode("old_parent_page");
    pageToMove.setGroup("valid_group");
    PageM newParent = new PageM(false);
    newParent.setCode("new_parent_page");
    newParent.setParentCode("another_parent_page");
    newParent.setGroup("valid_group");
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("page_to_move")).thenReturn(pageToMove);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("new_parent_page")).thenReturn(newParent);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}/position", "page_to_move").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_STATUS_PAGE_MISMATCH)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 3 with PagePositionRequest

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

the class PageServiceIntegrationTest method testChangeNode.

@Test
public void testChangeNode() {
    PageDto pageToClone = pageService.getPage("pagina_11", "draft");
    assertNotNull(pageToClone);
    PageRequest pageRequest = this.createRequestFromDto(pageToClone);
    pageRequest.setCode("pagina_13");
    PageDto addedPage = pageService.addPage(pageRequest);
    assertNotNull(addedPage);
    assertEquals("pagina_1", addedPage.getParentCode());
    assertEquals(3, addedPage.getPosition());
    PagePositionRequest pagePosRequest = new PagePositionRequest();
    pagePosRequest.setCode("pagina_13");
    pagePosRequest.setParentCode("pagina_2");
    pagePosRequest.setPosition(1);
    addedPage = pageService.movePage("pagina_13", pagePosRequest);
    assertNotNull(addedPage);
    assertEquals("pagina_2", addedPage.getParentCode());
    assertEquals(1, addedPage.getPosition());
    List<PageDto> pages = pageService.getPages("pagina_2");
    assertNotNull(pages);
    assertEquals(1, pages.size());
    assertEquals("pagina_13", pages.get(0).getCode());
    pageService.removePage("pagina_13");
}
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) Test(org.junit.Test)

Example 4 with PagePositionRequest

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

the class PageServiceIntegrationTest method testChangeOnlyPosition.

@Test
public void testChangeOnlyPosition() {
    PageDto pageToClone = pageService.getPage("pagina_11", "draft");
    assertNotNull(pageToClone);
    PageRequest pageRequest = this.createRequestFromDto(pageToClone);
    pageRequest.setCode("pagina_13");
    PageDto addedPage = pageService.addPage(pageRequest);
    assertNotNull(addedPage);
    assertEquals("pagina_1", addedPage.getParentCode());
    assertEquals(3, addedPage.getPosition());
    PagePositionRequest pagePosRequest = new PagePositionRequest();
    pagePosRequest.setCode("pagina_13");
    pagePosRequest.setParentCode("pagina_1");
    pagePosRequest.setPosition(1);
    addedPage = pageService.movePage("pagina_13", pagePosRequest);
    assertNotNull(addedPage);
    assertEquals("pagina_1", addedPage.getParentCode());
    assertEquals(1, addedPage.getPosition());
    pageService.removePage("pagina_13");
}
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) Test(org.junit.Test)

Example 5 with PagePositionRequest

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

the class PageControllerTest method shouldValidateMovePageGroupMismatch.

@Test
public void shouldValidateMovePageGroupMismatch() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagePositionRequest request = new PagePositionRequest();
    request.setCode("page_to_move");
    request.setParentCode("new_parent_page");
    request.setPosition(1);
    Page pageToMove = new Page();
    pageToMove.setCode("page_to_move");
    pageToMove.setParentCode("old_parent_page");
    pageToMove.setGroup("page_to_move_group");
    Page newParent = new Page();
    newParent.setCode("new_parent_page");
    newParent.setParentCode("another_parent_page");
    newParent.setGroup("another_group");
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("page_to_move")).thenReturn(pageToMove);
    when(this.controller.getPageValidator().getPageManager().getDraftPage("new_parent_page")).thenReturn(newParent);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}/position", "page_to_move").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_GROUP_MISMATCH)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) 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)

Aggregations

PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)5 Test (org.junit.Test)5 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)2 PageRequest (org.entando.entando.web.page.model.PageRequest)2 Page (com.agiletec.aps.system.services.page.Page)1