Search in sources :

Example 1 with PostController

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

the class MockMvcResponseTimeTest method can_extract_response_time_in_mock_mvc_extension.

@Test
public void can_extract_response_time_in_mock_mvc_extension() {
    long time = RestAssuredMockMvc.given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().extract().time();
    assertThat(time).isGreaterThan(-1).isLessThan(3000L);
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) Test(org.junit.Test)

Example 2 with PostController

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

the class RequestLoggingTest method logging_param_works.

@Test
public void logging_param_works() {
    RestAssuredMockMvc.given().log().all().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/greetingPost\nProxy:\t\t\t<none>\nRequest params:\tname=Johan\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>\n"));
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) Test(org.junit.Test)

Example 3 with PostController

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

the class RequestLoggingTest method logging_form_param_works.

@Test
public void logging_form_param_works() {
    RestAssuredMockMvc.given().log().all().standaloneSetup(new PostController()).formParam("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
    assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/greetingPost\nProxy:\t\t\t<none>\nRequest params:\t<none>\nQuery params:\t<none>\nForm params:\tname=Johan\nPath params:\t<none>\nHeaders:\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>\n"));
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) Test(org.junit.Test)

Example 4 with PostController

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

the class RequestLoggingTest method logging_if_request_validation_fails_works.

@Test
public void logging_if_request_validation_fails_works() {
    try {
        RestAssuredMockMvc.given().log().ifValidationFails().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
        fail("Should throw AssertionError");
    } catch (AssertionError e) {
        assertThat(writer.toString(), equalTo("Request method:\tPOST\nRequest URI:\thttp://localhost:8080/greetingPost\nProxy:\t\t\t<none>\nRequest params:\tname=Johan\nQuery params:\t<none>\nForm params:\t<none>\nPath params:\t<none>\nHeaders:\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\nCookies:\t\t<none>\nMultiparts:\t\t<none>\nBody:\t\t\t<none>\n"));
    }
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) Test(org.junit.Test)

Example 5 with PostController

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

the class ResponseLoggingTest method logging_if_response_validation_fails_doesnt_log_anything_if_validation_succeeds.

@Test
public void logging_if_response_validation_fails_doesnt_log_anything_if_validation_succeeds() {
    RestAssuredMockMvc.given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().log().ifValidationFails().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
    assertThat(writer.toString(), isEmptyString());
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) Test(org.junit.Test)

Aggregations

PostController (io.restassured.module.mockmvc.http.PostController)14 Test (org.junit.Test)14 LogConfig (io.restassured.config.LogConfig)5 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)4 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)2 MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 GreetingController (io.restassured.module.mockmvc.http.GreetingController)1 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)1 JsonPath (io.restassured.path.json.JsonPath)1 PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1