Search in sources :

Example 6 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetControllerTest method createMockRequest.

private WidgetRequest createMockRequest() {
    Map<String, String> titles = new HashMap<>();
    titles.put("it", "il titolo");
    titles.put("en", "the test title");
    WidgetRequest req = new WidgetRequest();
    req.setCode("test");
    req.setGroup("test");
    req.setCustomUi("<h1>UI Code</h1>");
    req.setTitles(titles);
    return req;
}
Also used : HashMap(java.util.HashMap) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest)

Example 7 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    WidgetRequest widgetRequest = (WidgetRequest) target;
    if (StringUtils.isEmpty(widgetRequest.getCustomUi())) {
        errors.rejectValue("customUi", ERRCODE_NOT_BLANK, new String[] {}, "widgettype.customUi.notBlank");
    }
    this.validateTitles(widgetRequest, errors);
}
Also used : WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest)

Example 8 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method getWidgetRequest.

private WidgetRequest getWidgetRequest(String newWidgetCode) {
    WidgetRequest request = new WidgetRequest();
    request.setCode(newWidgetCode);
    request.setGroup(Group.FREE_GROUP_NAME);
    Map<String, String> titles = new HashMap<>();
    titles.put("it", "Titolo ITA 3");
    titles.put("en", "Title EN 3");
    request.setTitles(titles);
    request.setCustomUi("<h1>Test</h1>");
    request.setGroup(Group.FREE_GROUP_NAME);
    return request;
}
Also used : HashMap(java.util.HashMap) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest)

Example 9 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest 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 10 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest 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

WidgetRequest (org.entando.entando.web.widget.model.WidgetRequest)11 Test (org.junit.Test)7 UserDetails (com.agiletec.aps.system.services.user.UserDetails)5 HashMap (java.util.HashMap)5 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)3 Group (com.agiletec.aps.system.services.group.Group)2 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)2 PageRequest (org.entando.entando.web.page.model.PageRequest)2 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)2