use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method executeWidgetUsage.
private ResultActions executeWidgetUsage(String widgetTypeCode, String accessToken, ResultMatcher expected) throws Exception {
ResultActions result = mockMvc.perform(get("/widgets/{code}/usage", new Object[] { widgetTypeCode }).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method testAddUpdateWidget_1.
@Test
public void testAddUpdateWidget_1() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String newCode = "test_new_type_1";
Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
try {
WidgetRequest request = new WidgetRequest();
request.setCode(newCode);
request.setGroup(Group.FREE_GROUP_NAME);
Map<String, String> titles = new HashMap<>();
titles.put("it", "Titolo ITA");
titles.put("en", "Title EN");
request.setTitles(titles);
request.setCustomUi("<h1>Custom UI</h1>");
request.setGroup(Group.FREE_GROUP_NAME);
ResultActions result = this.executeWidgetPost(request, accessToken, status().isOk());
result.andExpect(jsonPath("$.payload.code", is(newCode)));
WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
Assert.assertNotNull(widgetType);
Assert.assertEquals("Title EN", widgetType.getTitles().getProperty("en"));
request.setGroup("invalid");
titles.put("en", "Title EN modified");
result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID)));
request.setGroup("helpdesk");
request.setCustomUi("");
result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
titles.put("en", "Title EN modified");
request.setCustomUi("New Custom Ui");
result = this.executeWidgetPut(request, newCode, accessToken, status().isOk());
result.andExpect(jsonPath("$.payload.group", is("helpdesk")));
widgetType = this.widgetTypeManager.getWidgetType(newCode);
Assert.assertNotNull(widgetType);
Assert.assertEquals("Title EN modified", widgetType.getTitles().getProperty("en"));
Assert.assertEquals("helpdesk", widgetType.getMainGroup());
result = this.executeWidgetDelete(newCode, accessToken, status().isOk());
result.andExpect(jsonPath("$.payload.code", is(newCode)));
widgetType = this.widgetTypeManager.getWidgetType(newCode);
Assert.assertNull(widgetType);
} catch (Exception e) {
throw e;
} finally {
this.widgetTypeManager.deleteWidgetType(newCode);
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method testGetWidgetsWithoutPermission.
@Test
public void testGetWidgetsWithoutPermission() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("normal_user", "0x24").build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/widgets").header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
result.andExpect(status().isForbidden());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method executeWidgetDelete.
private ResultActions executeWidgetDelete(String widgetTypeCode, String accessToken, ResultMatcher expected) throws Exception {
ResultActions result = mockMvc.perform(delete("/widgets/{code}", new Object[] { widgetTypeCode }).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method addPage.
private void addPage(String accessToken, PageRequest pageRequest) throws Exception {
ResultActions result = mockMvc.perform(post("/pages").content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
}
Aggregations