use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class TestRequestAuthorizator method testService_1.
public void testService_1() throws Throwable {
RequestContext reqCtx = this.getRequestContext();
this.setUserOnSession(SystemConstants.GUEST_USER_NAME);
IPage root = this._pageManager.getOnlineRoot();
reqCtx.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, root);
int status = _authorizator.service(reqCtx, ControllerManager.CONTINUE);
assertEquals(status, ControllerManager.CONTINUE);
String redirectUrl = (String) reqCtx.getExtraParam(RequestContext.EXTRAPAR_REDIRECT_URL);
assertNull(redirectUrl);
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class TestWidgetExecutorService method testExecutor.
public void testExecutor() throws Exception {
super.setUserOnSession("admin");
IPageManager pageManager = (IPageManager) super.getApplicationContext().getBean(SystemConstants.PAGE_MANAGER);
IPage currentPage = pageManager.getOnlinePage("homepage");
super.getRequestContext().addExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE, currentPage);
ExecutorServiceInterface wes = (ExecutorServiceInterface) super.getApplicationContext().getBean("WidgetExecutorService");
wes.service(super.getRequestContext());
String[] widgetOutput = (String[]) super.getRequestContext().getExtraParam("ShowletOutput");
assertNotNull(widgetOutput);
assertEquals(currentPage.getModel().getFrames().length, widgetOutput.length);
for (int i = 0; i < widgetOutput.length; i++) {
String output = widgetOutput[i];
assertNotNull(output);
Widget currentWidget = currentPage.getWidgets()[i];
if (null == currentWidget) {
assertTrue(StringUtils.isBlank(output));
} else {
GuiFragment fragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(currentWidget.getType().getCode());
if (null == fragment) {
assertTrue(StringUtils.isBlank(output));
} else {
assertTrue(StringUtils.isNotBlank(output));
}
}
}
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class ActivityStreamControllerIntegrationTest method initTestObjects.
private void initTestObjects(String accessToken, String... pageCodes) throws Exception {
for (String pageCode : pageCodes) {
PageModel pageModel = this.pageModelManager.getPageModel("internal");
Page mockPage = createPage(pageCode, pageModel);
mockPage.setWidgets(new Widget[pageModel.getFrames().length]);
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())));
// execute and action
ResultActions result = mockMvc.perform(put("/pages/{pageCode}/configuration/defaultWidgets", new Object[] { pageCode }).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
synchronized (this) {
this.wait(1000);
}
}
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class WidgetServiceTest method mockPagedMetadata.
/**
* init mock for a multipaged request
*/
private void mockPagedMetadata(List<String> utilizers, int currPage, int lastPage, int pageSize, int totalSize) {
try {
List<IPage> onlinePageList = utilizers.stream().map(u -> PageMockHelper.mockTestPage(u, WidgetMockHelper.WIDGET_1_CODE)).collect(Collectors.toList());
List<IPage> draftPageList = utilizers.stream().map(u -> PageMockHelper.mockTestPage(u, WidgetMockHelper.WIDGET_1_CODE)).collect(Collectors.toList());
when(pageManager.getOnlineWidgetUtilizers(anyString())).thenReturn(onlinePageList);
when(pageManager.getDraftWidgetUtilizers(anyString())).thenReturn(draftPageList);
when(widgetManager.getWidgetType(anyString())).thenReturn(WidgetMockHelper.mockWidgetType());
RestListRequest restListRequest = new RestListRequest();
restListRequest.setPageSize(pageSize);
restListRequest.setPage(currPage);
List<ComponentUsageEntity> componentUsageEntityList = onlinePageList.stream().map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child.getCode(), IPageService.STATUS_ONLINE)).collect(Collectors.toList());
componentUsageEntityList.addAll(draftPageList.stream().map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child.getCode(), IPageService.STATUS_DRAFT)).collect(Collectors.toList()));
PagedMetadata pagedMetadata = new PagedMetadata(restListRequest, componentUsageEntityList, totalSize);
pagedMetadata.setPageSize(pageSize);
pagedMetadata.setPage(currPage);
pagedMetadata.imposeLimits();
when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
} catch (Exception e) {
Assert.fail("Mock Exception");
}
}
use of com.agiletec.aps.system.services.page.IPage 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));
}
}
Aggregations