Search in sources :

Example 21 with ResultActions

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 22 with ResultActions

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 23 with ResultActions

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());
    }
}
Also used : HBaseDao(org.apache.metron.indexing.dao.HBaseDao) NavigableMap(java.util.NavigableMap) Get(org.apache.hadoop.hbase.client.Get) ResultActions(org.springframework.test.web.servlet.ResultActions) MockHTable(org.apache.metron.hbase.mock.MockHTable) Result(org.apache.hadoop.hbase.client.Result) SearchIntegrationTest(org.apache.metron.indexing.dao.SearchIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with ResultActions

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));
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 25 with ResultActions

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));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ResultActions(org.springframework.test.web.servlet.ResultActions) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Aggregations

ResultActions (org.springframework.test.web.servlet.ResultActions)600 Test (org.junit.Test)525 UserDetails (com.agiletec.aps.system.services.user.UserDetails)297 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)221 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)101 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)43 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 MvcResult (org.springframework.test.web.servlet.MvcResult)27 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 UUID (java.util.UUID)22 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)22 InputStream (java.io.InputStream)18 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)17 HashMap (java.util.HashMap)17 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)16 Test (org.junit.jupiter.api.Test)15 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)14 IPage (com.agiletec.aps.system.services.page.IPage)13 Page (com.agiletec.aps.system.services.page.Page)12