use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method testGetWidgetList_1.
@Test
public void testGetWidgetList_1() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").withAuthorization(Group.FREE_GROUP_NAME, "managePages", Permission.MANAGE_PAGES).build();
String accessToken = mockOAuthInterceptor(user);
// @formatter:off
ResultActions result = mockMvc.perform(get("/widgets").param("pageSize", "100").header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload", Matchers.hasSize(6)));
result.andExpect(jsonPath("$.metaData.pageSize", is(100)));
result.andExpect(jsonPath("$.metaData.totalItems", is(6)));
String response = result.andReturn().getResponse().getContentAsString();
assertNotNull(response);
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class WidgetControllerIntegrationTest method testAddUpdateWidget_2.
@Test
public void testAddUpdateWidget_2() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String newCode = "test_new_type_2";
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 2");
titles.put("en", "Title EN 2");
request.setTitles(titles);
request.setCustomUi("");
request.setGroup(Group.FREE_GROUP_NAME);
ResultActions result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
titles.put("en", "");
request.setCustomUi("Custom UI");
result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
titles.put("en", "Title EN 2 bis");
result = this.executeWidgetPut(request, newCode, accessToken, status().isNotFound());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_NOT_FOUND)));
result = this.executeWidgetPost(request, accessToken, status().isOk());
result.andExpect(jsonPath("$.payload.group", is(Group.FREE_GROUP_NAME)));
WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
Assert.assertNotNull(widgetType);
Assert.assertEquals("Title EN 2 bis", widgetType.getTitles().getProperty("en"));
titles.put("it", "");
result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
} catch (Exception e) {
throw e;
} finally {
this.widgetTypeManager.deleteWidgetType(newCode);
Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ActivityStreamControllerIntegrationTest method initTestObjects.
private void initTestObjects(String accessToken, String... pageCodes) throws Exception {
for (String pageCode : pageCodes) {
PageModel pageModel = this.pageModelManager.getPageModel("internal");
Page mockPage = createPage(pageCode, pageModel);
mockPage.setWidgets(new Widget[pageModel.getFrames().length]);
this.pageManager.addPage(mockPage);
IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
assertThat(onlinePage, is(nullValue()));
IPage draftPage = this.pageManager.getDraftPage(pageCode);
assertThat(draftPage, is(not(nullValue())));
// execute and action
ResultActions result = mockMvc.perform(put("/pages/{pageCode}/configuration/defaultWidgets", new Object[] { pageCode }).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
synchronized (this) {
this.wait(1000);
}
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ActivityStreamControllerIntegrationTest method testGetActivityStream.
@Test
public void testGetActivityStream() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/activityStream").param("sort", "createdAt").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ActivityStreamControllerIntegrationTest method testGetActivityStreamDate.
@Test
public void testGetActivityStreamDate() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String start = new Timestamp(DateConverter.parseDate("2017/01/01", "yyyy/MM/dd").getTime()).toString();
String end = new Timestamp(DateConverter.parseDate("2017/01/01", "yyyy/MM/dd").getTime()).toString();
ResultActions result = mockMvc.perform(get("/activityStream").param("sort", "createdAt").param("filters[0].attribute", "createdAt").param("filters[0].value", String.format("[%s TO %s]", start, end)).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
}
Aggregations