use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageControllerIntegrationTest method testMovePage.
@Test
public void testMovePage() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String codeParent = "testToMoveParent";
String codeChild = "testToMoveChild";
try {
PageRequest pageRequest = new PageRequest();
pageRequest.setCode(codeParent);
pageRequest.setPageModel("home");
pageRequest.setOwnerGroup("customers");
Map<String, String> titles = new HashMap<>();
titles.put("it", codeParent);
titles.put("en", codeParent);
pageRequest.setTitles(titles);
pageRequest.setParentCode("customers_page");
this.addPage(accessToken, pageRequest);
pageRequest.setCode(codeChild);
pageRequest.setPageModel("home");
pageRequest.setOwnerGroup("customers");
titles = new HashMap<>();
titles.put("it", codeChild);
titles.put("en", codeChild);
pageRequest.setTitles(titles);
pageRequest.setParentCode(codeParent);
this.addPage(accessToken, pageRequest);
PagePositionRequest movementRequest = new PagePositionRequest();
movementRequest.setCode(codeParent);
movementRequest.setParentCode(codeParent);
movementRequest.setPosition(1);
// put
ResultActions result = mockMvc.perform(put("/pages/{code}/position", codeParent).content(mapper.writeValueAsString(movementRequest)).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("3")));
// put
movementRequest.setParentCode(codeChild);
result = mockMvc.perform(put("/pages/{code}/position", codeParent).content(mapper.writeValueAsString(movementRequest)).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("3")));
// put
movementRequest.setParentCode("coach_page");
result = mockMvc.perform(put("/pages/{code}/position", codeParent).content(mapper.writeValueAsString(movementRequest)).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
movementRequest.setParentCode("service");
result = mockMvc.perform(put("/pages/{code}/position", codeParent).content(mapper.writeValueAsString(movementRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
} finally {
this.pageManager.deletePage(codeChild);
this.pageManager.deletePage(codeParent);
}
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageControllerIntegrationTest method testPageStatus.
@Test
public void testPageStatus() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String codeParent = "testStatusParent";
String codeChild = "testStatusChild";
try {
PageRequest pageRequest = new PageRequest();
pageRequest.setCode(codeParent);
pageRequest.setPageModel("home");
pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
Map<String, String> titles = new HashMap<>();
titles.put("it", codeParent);
titles.put("en", codeParent);
pageRequest.setTitles(titles);
pageRequest.setParentCode("homepage");
this.addPage(accessToken, pageRequest);
pageRequest.setCode(codeChild);
titles = new HashMap<>();
titles.put("it", codeChild);
titles.put("en", codeChild);
pageRequest.setTitles(titles);
pageRequest.setParentCode(codeParent);
this.addPage(accessToken, pageRequest);
PageStatusRequest statusRequest = new PageStatusRequest();
// put
ResultActions result = this.executeUpdatePageStatus(codeParent, statusRequest, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("53")));
statusRequest.setStatus("xxxxxxx");
result = this.executeUpdatePageStatus(codeParent, statusRequest, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("57")));
statusRequest.setStatus("published");
result = this.executeUpdatePageStatus(codeChild, statusRequest, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("9")));
statusRequest.setStatus("published");
result = this.executeUpdatePageStatus("not_existing", statusRequest, accessToken, status().isNotFound());
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("1")));
statusRequest.setStatus("published");
result = this.executeUpdatePageStatus(codeParent, statusRequest, accessToken, status().isOk());
result.andExpect(jsonPath("$.errors.size()", is(0)));
result.andExpect(jsonPath("$.payload.code", is(codeParent)));
statusRequest.setStatus("published");
result = this.executeUpdatePageStatus(codeChild, statusRequest, accessToken, status().isOk());
result.andExpect(jsonPath("$.errors.size()", is(0)));
result.andExpect(jsonPath("$.payload.code", is(codeChild)));
statusRequest.setStatus("draft");
result = this.executeUpdatePageStatus(codeParent, statusRequest, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("8")));
statusRequest.setStatus("draft");
result = this.executeUpdatePageStatus(codeChild, statusRequest, accessToken, status().isOk());
result.andExpect(jsonPath("$.errors.size()", is(0)));
result.andExpect(jsonPath("$.payload.code", is(codeChild)));
statusRequest.setStatus("draft");
result = this.executeUpdatePageStatus(codeParent, statusRequest, accessToken, status().isOk());
result.andExpect(jsonPath("$.errors.size()", is(0)));
result.andExpect(jsonPath("$.payload.code", is(codeParent)));
} finally {
this.pageManager.deletePage(codeChild);
this.pageManager.deletePage(codeParent);
}
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageControllerIntegrationTest method testPageUsageDetailsWithoutPermissionWillResultIn401.
@Test
public void testPageUsageDetailsWithoutPermissionWillResultIn401() throws Exception {
UserDetails admin = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String adminAccessToken = mockOAuthInterceptor(admin);
try {
PageRequest pageRequest = PageRequestMockHelper.mockPageRequest();
pageRequest.setOwnerGroup(Group.ADMINS_GROUP_NAME);
this.addPage(adminAccessToken, pageRequest);
UserDetails user = new OAuth2TestUtils.UserBuilder("John Lackland", "0x246").withAuthorization(Group.FREE_GROUP_NAME, "admin", Permission.SUPERUSER).build();
String userAccessToken = mockOAuthInterceptor(user);
ResultActions resultActions = mockMvc.perform(get("/pages/{code}/usage/details", PageRequestMockHelper.ADD_PAGE_CODE).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userAccessToken));
resultActions.andExpect(status().isUnauthorized());
} catch (Exception e) {
Assert.fail();
} finally {
this.pageManager.deletePage(PageRequestMockHelper.ADD_PAGE_CODE);
}
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class PageRequestMockHelper method mockPageRequest.
/**
* @param code
* @param parentCode
* @param pageModel
* @param ownerGroup
* @return
*/
public static PageRequest mockPageRequest(String code, String parentCode, String pageModel, String ownerGroup, String status) {
PageRequest pageRequest = new PageRequest();
pageRequest.setCode(code);
pageRequest.setPageModel(pageModel);
pageRequest.setOwnerGroup(ownerGroup);
pageRequest.setStatus(status);
Map<String, String> titles = new HashMap<>();
titles.put("it", code);
titles.put("en", code);
pageRequest.setTitles(titles);
pageRequest.setParentCode(parentCode);
return pageRequest;
}
use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.
the class WidgetControllerIntegrationTest method getPageRequest.
private PageRequest getPageRequest(String pageCode) {
PageRequest pageRequest = new PageRequest();
pageRequest.setCode(pageCode);
pageRequest.setPageModel("home");
pageRequest.setOwnerGroup(Group.FREE_GROUP_NAME);
Map<String, String> pageTitles = new HashMap<>();
pageTitles.put("it", pageCode);
pageTitles.put("en", pageCode);
pageRequest.setTitles(pageTitles);
pageRequest.setParentCode("service");
return pageRequest;
}
Aggregations