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");
}
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!"));
}
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();
}
}
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!"));
}
Aggregations