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