use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class PageModelControllerTest method should_add_valid_page_model.
@Test
public void should_add_valid_page_model() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String payload = " {\n" + " \"code\": \"test\",\n" + " \"descr\": \"test\",\n" + " \"configuration\": {\n" + " \"frames\": [{\n" + " \"pos\": 0,\n" + " \"descr\": \"test_frame\",\n" + " \"mainFrame\": false,\n" + " \"defaultWidget\": null,\n" + " \"sketch\": null\n" + " }]\n" + " },\n" + " \"pluginCode\": null,\n" + " \"template\": \"ciao\"\n" + " }";
// System.out.println(payload);
ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
Mockito.verify(pageModelService, Mockito.times(1)).addPageModel(Mockito.any());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserSettigsControllerUnitTest method testUpdateSettingsWithEmptyParams.
@Test
public void testUpdateSettingsWithEmptyParams() throws Throwable {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
ResultActions result = mockMvc.perform(put("/usersettings").content(mapper.writeValueAsString(userSettingsRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isBadRequest());
}
use of org.springframework.test.web.servlet.ResultActions in project metron by apache.
the class UpdateControllerIntegrationTest method test.
@Test
public void test() throws Exception {
String guid = "bro_2";
ResultActions result = this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0));
try {
result.andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").doesNotExist()).andExpect(jsonPath("$.timestamp").value(2));
} catch (Throwable t) {
System.err.println(result.andReturn().getResponse().getContentAsString());
throw t;
}
MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE);
Assert.assertEquals(0, table.size());
this.mockMvc.perform(patch(updateUrl + "/patch").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(patch)).andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").value("metron")).andExpect(jsonPath("$.timestamp").value(2));
Assert.assertEquals(1, table.size());
{
// ensure hbase is up to date
Get g = new Get(new HBaseDao.Key(guid, "bro").toBytes());
Result r = table.get(g);
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(1, columns.size());
}
this.mockMvc.perform(post(updateUrl + "/replace").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(replace)).andExpect(status().isOk());
this.mockMvc.perform(post(searchUrl + "/findOne").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(findMessage0)).andExpect(status().isOk()).andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(jsonPath("$.source:type").value("bro")).andExpect(jsonPath("$.guid").value(guid)).andExpect(jsonPath("$.project").doesNotExist()).andExpect(jsonPath("$.timestamp").value(200));
Assert.assertEquals(1, table.size());
{
// ensure hbase is up to date
Get g = new Get(new HBaseDao.Key(guid, "bro").toBytes());
Result r = table.get(g);
NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes());
Assert.assertEquals(2, columns.size());
}
}
use of org.springframework.test.web.servlet.ResultActions in project formation-jenkins by x2i-tvercruysse.
the class VetControllerTests method testShowResourcesVetList.
@Test
public void testShowResourcesVetList() throws Exception {
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
actions.andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.vetList[0].id").value(1));
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class PrivilegeRestControllerTest method testFindPrivileges.
@Test
public void testFindPrivileges() throws Exception {
PrivilegeEntity dbResult = new PrivilegeEntity().setId("123").setName("12345").setDescription("Description 12345");
Page<PrivilegeEntity> pageResponseBody = new PageImpl<>(Arrays.asList(dbResult));
Page<PrivilegeRestData> expectedResponseBody = new PageImpl<>(Arrays.asList(PrivilegeRestData.builder().fromPrivilegeEntity(dbResult).build()));
when(privilegeService.findPrivileges(anyString(), any())).thenReturn(pageResponseBody);
ResultActions resultActions = mockMvc.perform(get("/api/privileges").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("privilege-read-all"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
verify(privilegeService).findPrivileges(anyString(), any());
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expectedResponseBody));
}
Aggregations