use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.
the class PageConfigurationControllerIntegrationTest method createPage.
protected Page createPage(String pageCode) {
IPage parentPage = pageManager.getDraftPage("service");
PageModel pageModel = parentPage.getMetadata().getModel();
PageMetadata metadata = PageTestUtil.createPageMetadata(pageModel.getCode(), true, pageCode + "_title", null, null, false, null, null);
ApsProperties config = PageTestUtil.createProperties("temp", "tempValue", "contentId", "ART11");
Widget widgetToAdd = PageTestUtil.createWidget("content_viewer", config, this.widgetTypeManager);
Widget[] widgets = { widgetToAdd };
Page pageToAdd = PageTestUtil.createPage(pageCode, parentPage, "free", metadata, widgets);
return pageToAdd;
}
use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.
the class PageConfigurationControllerWidgetsIntegrationTest method testContentViewer.
@Test
public void testContentViewer() throws Exception {
String pageCode = "draft_page_100";
try {
Page mockPage = createPage(pageCode);
this.pageManager.addPage(mockPage);
IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
assertThat(onlinePage, is(nullValue()));
IPage draftPage = this.pageManager.getDraftPage(pageCode);
assertThat(draftPage, is(not(nullValue())));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/pages/{pageCode}/configuration", new Object[] { pageCode }).param("status", IPageService.STATUS_DRAFT).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
String payloadWithInvalidContentId = "{\n" + " \"code\": \"content_viewer\",\n" + " \"config\": {\n" + " \"contentId\": \"ART1120000000\",\n" + " \"modelId\": \"default\"\n" + " }\n" + "}";
result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(payloadWithInvalidContentId).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
String validContentIdWithIncompatibleGroup = "{\n" + " \"code\": \"content_viewer\",\n" + " \"config\": {\n" + " \"contentId\": \"ART112\",\n" + " \"modelId\": \"default\"\n" + " }\n" + "}";
result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(validContentIdWithIncompatibleGroup).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
} finally {
this.pageManager.deletePage(pageCode);
}
}
use of com.agiletec.aps.system.services.page.Page 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)));
}
use of com.agiletec.aps.system.services.page.Page in project entando-core by entando.
the class PageManagerCacheWrapper method buildTreeHierarchy.
protected void buildTreeHierarchy(IPage root, Map<String, IPage> pagesMap, IPage page) {
Page parent = (Page) pagesMap.get(page.getParentCode());
((Page) page).setParent(parent);
if (!page.getCode().equals(root.getCode())) {
parent.addChildCode(page.getCode());
}
}
Aggregations