Search in sources :

Example 1 with MockMvcResponse

use of io.restassured.module.mockmvc.response.MockMvcResponse in project rest-assured by rest-assured.

the class ResponseConverter method toStandardResponse.

static Response toStandardResponse(MockMvcResponse response) {
    if (!(response instanceof MockMvcRestAssuredResponseImpl)) {
        throw new IllegalArgumentException(MockMvcResponse.class.getName() + " must be an instance of " + MockMvcRestAssuredResponseImpl.class.getName());
    }
    MockMvcRestAssuredResponseImpl mvc = (MockMvcRestAssuredResponseImpl) response;
    RestAssuredResponseImpl std = new RestAssuredResponseImpl();
    std.setConnectionManager(mvc.getConnectionManager());
    std.setContent(mvc.getContent());
    std.setContentType(mvc.getContentType());
    std.setCookies(mvc.detailedCookies());
    std.setDecoderConfig(mvc.getDecoderConfig());
    std.setDefaultContentType(mvc.getDefaultContentType());
    std.setHasExpectations(mvc.getHasExpectations());
    std.setResponseHeaders(mvc.getResponseHeaders());
    std.setSessionIdName(mvc.getSessionIdName());
    std.setStatusCode(mvc.getStatusCode());
    std.setStatusLine(mvc.getStatusLine());
    std.setRpr(mvc.getRpr());
    std.setFilterContextProperties(mvc.getFilterContextProperties());
    std.setLogRepository(mvc.getLogRepository());
    return std;
}
Also used : MockMvcResponse(io.restassured.module.mockmvc.response.MockMvcResponse) RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl)

Example 2 with MockMvcResponse

use of io.restassured.module.mockmvc.response.MockMvcResponse in project rest-assured by rest-assured.

the class ExtractTest method can_extract_rest_assureds_mock_mvc_response.

@Test
public void can_extract_rest_assureds_mock_mvc_response() {
    MockMvcResponse response = RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).param("name", "Johan").when().get("/greeting").then().statusCode(200).body("id", equalTo(1)).extract().response();
    assertThat(response.path("content")).isEqualTo("Hello, Johan!");
}
Also used : MockMvcResponse(io.restassured.module.mockmvc.response.MockMvcResponse) GreetingController(io.restassured.module.mockmvc.http.GreetingController) Test(org.junit.Test)

Aggregations

MockMvcResponse (io.restassured.module.mockmvc.response.MockMvcResponse)2 RestAssuredResponseImpl (io.restassured.internal.RestAssuredResponseImpl)1 GreetingController (io.restassured.module.mockmvc.http.GreetingController)1 Test (org.junit.Test)1