use of io.restassured.module.mockmvc.http.PostController in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method mock_mvc_instance_is_overwritten_when_defined_in_specification.
@Test
public void mock_mvc_instance_is_overwritten_when_defined_in_specification() {
// Given
MockMvc otherMockMvcInstance = MockMvcBuilders.standaloneSetup(new PostController()).build();
MockMvc thisMockMvcInstance = MockMvcBuilders.standaloneSetup(new GreetingController()).build();
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setMockMvc(otherMockMvcInstance).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().mockMvc(thisMockMvcInstance).spec(specToMerge);
// Then
assertThat(Whitebox.getInternalState(implOf(spec).getMockMvcFactory(), "mockMvc")).isSameAs(otherMockMvcInstance);
}
use of io.restassured.module.mockmvc.http.PostController in project rest-assured by rest-assured.
the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_post_greeting_controller.
@Test
public void mock_mvc_example_for_post_greeting_controller() throws Exception {
MockMvc mockMvc = standaloneSetup(new PostController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
String contentAsString = mockMvc.perform(post("/greetingPost").param("name", "Johan").contentType(MediaType.APPLICATION_FORM_URLENCODED)).andReturn().getResponse().getContentAsString();
JsonPath jsonPath = new JsonPath(contentAsString);
assertThat(jsonPath.getInt("id"), equalTo(1));
assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
use of io.restassured.module.mockmvc.http.PostController in project rest-assured by rest-assured.
the class RequestLoggingTest method doesnt_log_if_request_validation_succeeds_when_request_logging_if_validation_fails_is_enabled.
@Test
public void doesnt_log_if_request_validation_succeeds_when_request_logging_if_validation_fails_is_enabled() {
RestAssuredMockMvc.given().log().ifValidationFails().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
assertThat(writer.toString(), isEmptyString());
}
use of io.restassured.module.mockmvc.http.PostController in project rest-assured by rest-assured.
the class ResponseLoggingTest method logging_if_response_validation_fails_works.
@Test
public void logging_if_response_validation_fails_works() {
try {
RestAssuredMockMvc.given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().log().ifValidationFails().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("200\nContent-Type: application/json;charset=UTF-8\n\n{\n \"id\": 1,\n \"content\": \"Hello, Johan!\"\n}\n"));
}
}
Aggregations