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