Search in sources :

Example 21 with PageRequest

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);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 22 with PageRequest

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);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) PageStatusRequest(org.entando.entando.web.page.model.PageStatusRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 23 with PageRequest

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);
    }
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 24 with PageRequest

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;
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) HashMap(java.util.HashMap)

Example 25 with 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;
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) HashMap(java.util.HashMap)

Aggregations

PageRequest (org.entando.entando.web.page.model.PageRequest)27 Test (org.junit.Test)16 HashMap (java.util.HashMap)12 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)11 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 IPage (com.agiletec.aps.system.services.page.IPage)8 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)8 ResultActions (org.springframework.test.web.servlet.ResultActions)8 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)7 Page (com.agiletec.aps.system.services.page.Page)6 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)6 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)5 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 IManager (com.agiletec.aps.system.common.IManager)3 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 Group (com.agiletec.aps.system.services.group.Group)3 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)3 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)3