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")));
}
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)));
}
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");
}
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");
}
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)));
}
Aggregations