Search in sources :

Example 26 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method testMoveWidgetToAnotherFrame.

@Test
public void testMoveWidgetToAnotherFrame() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String pageCode = "test_move_widget_page";
    String newWidgetCode = "test_move_widget_1";
    Assert.assertNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
    Assert.assertNull(this.pageManager.getDraftPage(pageCode));
    try {
        WidgetRequest request = getWidgetRequest(newWidgetCode);
        ResultActions result = this.executeWidgetPost(request, accessToken, status().isOk());
        result.andDo(print()).andExpect(jsonPath("$.payload.code", is(newWidgetCode)));
        Assert.assertNotNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
        PageRequest pageRequest = getPageRequest(pageCode);
        result = mockMvc.perform(post("/pages").content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk());
        result = this.executeWidgetGet(newWidgetCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.used", is(0)));
        WidgetConfigurationRequest wcr = new WidgetConfigurationRequest();
        wcr.setCode(newWidgetCode);
        result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).content(mapper.writeValueAsString(wcr)).contentType(MediaType.APPLICATION_JSON_VALUE).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk());
        result = this.executeWidgetGet(newWidgetCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.used", is(1)));
        result = mockMvc.perform(get("/pages/{pageCode}/widgets", pageCode).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload[0].code", is(newWidgetCode))).andExpect(jsonPath("$.payload[1]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[2]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[3]", Matchers.isEmptyOrNullString()));
        result = mockMvc.perform(delete("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).contentType(MediaType.APPLICATION_JSON_VALUE).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk());
        result = mockMvc.perform(get("/pages/{pageCode}/widgets", pageCode).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload[0]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[1]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[2]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[3]", Matchers.isEmptyOrNullString()));
        result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 2 }).content(mapper.writeValueAsString(wcr)).contentType(MediaType.APPLICATION_JSON_VALUE).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk());
        result = this.executeWidgetGet(newWidgetCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.used", is(1)));
        result = mockMvc.perform(get("/pages/{pageCode}/widgets", pageCode).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
        result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload[0]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[1]", Matchers.isEmptyOrNullString())).andExpect(jsonPath("$.payload[2].code", is(newWidgetCode))).andExpect(jsonPath("$.payload[3]", Matchers.isEmptyOrNullString()));
    } catch (Exception e) {
        throw e;
    } finally {
        this.pageManager.deletePage(pageCode);
        Assert.assertNull(this.pageManager.getDraftPage(pageCode));
        this.widgetTypeManager.deleteWidgetType(newWidgetCode);
        Assert.assertNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
    }
}
Also used : WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 27 with PageRequest

use of org.entando.entando.web.page.model.PageRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method testAddUpdateWidget_3.

@Test
public void testAddUpdateWidget_3() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String pageCode = "test_add_delete_widget";
    String newWidgetCode = "test_new_type_3";
    Assert.assertNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
    try {
        WidgetRequest request = getWidgetRequest(newWidgetCode);
        ResultActions result0 = this.executeWidgetPost(request, accessToken, status().isOk());
        result0.andExpect(jsonPath("$.payload.code", is(newWidgetCode)));
        Assert.assertNotNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
        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");
        this.addPage(accessToken, pageRequest);
        ResultActions result1 = this.executeWidgetGet(newWidgetCode, accessToken, status().isOk());
        result1.andExpect(jsonPath("$.payload.used", is(0)));
        WidgetConfigurationRequest wcr = new WidgetConfigurationRequest();
        wcr.setCode(newWidgetCode);
        ResultActions resultPutWidget = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 1 }).content(mapper.writeValueAsString(wcr)).contentType(MediaType.APPLICATION_JSON_VALUE).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
        resultPutWidget.andExpect(status().isOk());
        ResultActions result3 = this.executeWidgetGet(newWidgetCode, accessToken, status().isOk());
        result3.andExpect(jsonPath("$.payload.used", is(1)));
    } catch (Exception e) {
        throw e;
    } finally {
        this.pageManager.deletePage(pageCode);
        Assert.assertNull(this.pageManager.getDraftPage(pageCode));
        this.widgetTypeManager.deleteWidgetType(newWidgetCode);
        Assert.assertNull(this.widgetTypeManager.getWidgetType(newWidgetCode));
    }
}
Also used : WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) 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) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

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