Search in sources :

Example 41 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project Red-Team by CSC480-18S.

the class DictionaryApplicationTests method validateTwoWordsEach.

@Test
public void validateTwoWordsEach() throws Exception {
    String words = "hello,acquire,fuck,shit,lake,snow,snarfblar,xadf";
    MockHttpServletRequestBuilder builder = get("/dictionary/validate?words=" + words);
    builder.contentType(MediaType.APPLICATION_JSON_UTF8);
    ResultActions res = mvc.perform(builder);
    res.andExpect(jsonPath("$", hasSize(8)));
    res.andExpect(jsonPath(String.format("$[0].valid"), is(true)));
    res.andExpect(jsonPath(String.format("$[1].valid"), is(true)));
    res.andExpect(jsonPath(String.format("$[2].bad"), is(true)));
    res.andExpect(jsonPath(String.format("$[3].bad"), is(true)));
    res.andExpect(jsonPath(String.format("$[4].special"), is(true)));
    res.andExpect(jsonPath(String.format("$[5].special"), is(true)));
    res.andExpect(jsonPath(String.format("$[6].valid"), is(false)));
    res.andExpect(jsonPath(String.format("$[7].valid"), is(false)));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project Red-Team by CSC480-18S.

the class DictionaryApplicationTests method validateWithWhiteSpace.

/**
 * performs a validation request with an entry
 * containing whitespace
 */
@Test
public void validateWithWhiteSpace() throws Exception {
    String word = "this has whitespace";
    MockHttpServletRequestBuilder builder = get("/dictionary/validate?words=" + word);
    builder.contentType(MediaType.APPLICATION_JSON_UTF8);
    ResultActions res = mvc.perform(builder);
    res.andExpect(jsonPath("$", hasSize(1)));
    res.andExpect(jsonPath("$[0].valid", is(false)));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project Red-Team by CSC480-18S.

the class TeamTests method getAllTeams.

/**
 * performs a GET request on /teams
 */
@Test
public void getAllTeams() throws Exception {
    MockHttpServletRequestBuilder builder = get("/teams");
    builder.contentType(MediaType.APPLICATION_JSON_UTF8);
    ResultActions res = mvc.perform(builder);
    res.andExpect(jsonPath("$._embedded.teams[0].name", is("Gold")));
    res.andExpect(jsonPath("$._embedded.teams[1].name", is("Green")));
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project community by GoogleCloudPlatform.

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 45 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project openlmis-stockmanagement by OpenLMIS.

the class ReasonConfigurationOptionsControllerIntegrationTest method shouldGetReasonTypes.

@Test
public void shouldGetReasonTypes() throws Exception {
    // when
    ResultActions resultActions = mvc.perform(get(reasonTypesApi).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
    // then
    resultActions.andExpect(status().isOk()).andDo(print()).andExpect(jsonPath("$", hasSize(2))).andExpect(jsonPath("$.[0]", is("CREDIT"))).andExpect(jsonPath("$.[1]", is("DEBIT")));
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

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