Search in sources :

Example 16 with GreetingController

use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.

the class ExtractTest method can_extract_spring_mvcs_result.

@Test
public void can_extract_spring_mvcs_result() {
    MvcResult mvcResult = RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).param("name", "Johan").when().get("/greeting").then().statusCode(200).body("id", equalTo(1)).extract().response().mvcResult();
    assertThat(mvcResult.getResponse().getContentType()).contains("application/json");
}
Also used : GreetingController(io.restassured.module.mockmvc.http.GreetingController) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

Example 17 with GreetingController

use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.

the class GreetingControllerRestAssuredTest method uses_predefined_mock_mvc_instance.

@Test
public void uses_predefined_mock_mvc_instance() throws Exception {
    MockMvc mockMvc = standaloneSetup(new GreetingController()).build();
    RestAssuredMockMvc.given().mockMvc(mockMvc).param("name", "Johan").when().get("/greeting").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
}
Also used : GreetingController(io.restassured.module.mockmvc.http.GreetingController) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 18 with GreetingController

use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.

the class GreetingControllerRestAssuredTest method uses_static_mock_mvc.

@Test
public void uses_static_mock_mvc() throws Exception {
    RestAssuredMockMvc.mockMvc(standaloneSetup(new GreetingController()).build());
    try {
        RestAssuredMockMvc.given().param("name", "Johan").when().get("/greeting").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
        RestAssuredMockMvc.given().param("name", "Erik").when().get("/greeting").then().body("id", equalTo(2)).body("content", equalTo("Hello, Erik!"));
    } finally {
        RestAssuredMockMvc.reset();
    }
}
Also used : GreetingController(io.restassured.module.mockmvc.http.GreetingController) Test(org.junit.Test)

Example 19 with GreetingController

use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.

the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_get_greeting_controller.

@Test
public void mock_mvc_example_for_get_greeting_controller() throws Exception {
    MockMvc mockMvc = standaloneSetup(new GreetingController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
    String contentAsString = mockMvc.perform(get("/greeting?name={name}", "Johan").accept(APPLICATION_JSON)).andReturn().getResponse().getContentAsString();
    JsonPath jsonPath = new JsonPath(contentAsString);
    assertThat(jsonPath.getInt("id"), equalTo(1));
    assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) JsonPath(io.restassured.path.json.JsonPath) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

GreetingController (io.restassured.module.mockmvc.http.GreetingController)19 Test (org.junit.Test)19 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)7 MockMvc (org.springframework.test.web.servlet.MockMvc)5 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)4 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 MultiValueMap (org.springframework.util.MultiValueMap)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)3 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 PostController (io.restassured.module.mockmvc.http.PostController)1 MockMvcResponse (io.restassured.module.mockmvc.response.MockMvcResponse)1 JsonPath (io.restassured.path.json.JsonPath)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1