Search in sources :

Example 66 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class FilterITest method httpClientIsAccessibleFromTheRequestSpecification.

@Test
public void httpClientIsAccessibleFromTheRequestSpecification() {
    // Given
    final MutableObject<HttpClient> client = new MutableObject<HttpClient>();
    // When
    given().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            client.setValue(requestSpec.getHttpClient());
            return new ResponseBuilder().setStatusCode(200).setContentType("application/json").setBody("{ \"message\" : \"hello\"}").build();
        }
    }).expect().body("message", equalTo("hello")).when().get("/something");
    // Then
    assertThat(client.getValue(), instanceOf(DefaultHttpClient.class));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) ResponseBuilder(io.restassured.builder.ResponseBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 67 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class FilterITest method content_type_in_filter_contains_charset_by_default.

@Test
public void content_type_in_filter_contains_charset_by_default() {
    final AtomicReference<String> contentType = new AtomicReference<String>();
    given().filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            contentType.set(requestSpec.getContentType());
            return ctx.next(requestSpec, responseSpec);
        }
    }).formParam("firstName", "John").formParam("lastName", "Doe").when().post("/greet").then().statusCode(200);
    assertThat(contentType.get(), equalTo("application/x-www-form-urlencoded; charset=ISO-8859-1"));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) AtomicReference(java.util.concurrent.atomic.AtomicReference) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 68 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class FilterITest method content_type_in_filter_doesnt_contain_charset_if_configured_not_to.

@Test
public void content_type_in_filter_doesnt_contain_charset_if_configured_not_to() {
    final AtomicReference<String> contentType = new AtomicReference<String>();
    given().config(RestAssuredConfig.config().encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).filter(new Filter() {

        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            contentType.set(requestSpec.getContentType());
            return ctx.next(requestSpec, responseSpec);
        }
    }).formParam("firstName", "John").formParam("lastName", "Doe").when().post("/greet").then().statusCode(200);
    assertThat(contentType.get(), equalTo("application/x-www-form-urlencoded"));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) ErrorLoggingFilter(io.restassured.filter.log.ErrorLoggingFilter) SpookyGreetJsonResponseFilter(io.restassured.itest.java.support.SpookyGreetJsonResponseFilter) FormAuthFilter(io.restassured.internal.filter.FormAuthFilter) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) Filter(io.restassured.filter.Filter) AtomicReference(java.util.concurrent.atomic.AtomicReference) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 69 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class HttpClientConfigITest method http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests.

@Test
public void http_client_config_allows_specifying_that_the_http_client_instance_is_reused_in_multiple_requests() {
    final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
    final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();
    RestAssured.config = RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance());
    // When
    try {
        given().param("url", "/hello").filter(new Filter() {

            public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                client1.setValue(requestSpec.getHttpClient());
                return ctx.next(requestSpec, responseSpec);
            }
        }).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");
        given().header("name", "value").filter((requestSpec, responseSpec, ctx) -> {
            client2.setValue(requestSpec.getHttpClient());
            return ctx.next(requestSpec, responseSpec);
        }).when().post("/reflect");
    } finally {
        RestAssured.reset();
    }
    assertThat(client1.getValue(), sameInstance(client2.getValue()));
}
Also used : Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) Filter(io.restassured.filter.Filter) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) MutableObject(org.apache.commons.lang3.mutable.MutableObject) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Example 70 with Response

use of io.restassured.response.Response in project rest-assured by rest-assured.

the class ResponseITest method responseSupportsGettingStatusCode.

@Test
public void responseSupportsGettingStatusCode() throws Exception {
    final Response response = get("/hello");
    assertThat(response.statusCode(), equalTo(200));
    assertThat(response.getStatusCode(), equalTo(200));
}
Also used : Response(io.restassured.response.Response) Test(org.junit.Test)

Aggregations

Response (io.restassured.response.Response)270 Test (org.junit.Test)209 Matchers.containsString (org.hamcrest.Matchers.containsString)43 ValidatableResponse (io.restassured.response.ValidatableResponse)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)29 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)25 HttpResponse (org.apache.http.HttpResponse)25 Matchers.emptyString (org.hamcrest.Matchers.emptyString)24 FilterContext (io.restassured.filter.FilterContext)17 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)17 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)17 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)17 Filter (io.restassured.filter.Filter)16 VerifyTest (org.apache.knox.test.category.VerifyTest)15 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 Book (org.baeldung.persistence.model.Book)13 JSONObject (org.json.simple.JSONObject)13 ResponseBuilder (io.restassured.builder.ResponseBuilder)12 IOException (java.io.IOException)11