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;
}
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);
}
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;
}
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));
}
}
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));
}
}
Aggregations