Search in sources :

Example 81 with Response

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

the class CookieITest method detailedCookieWorks.

@Test
public void detailedCookieWorks() throws Exception {
    final Response response = get("/html_with_cookie");
    final Cookie detailedCookieJsessionId = response.detailedCookie("JSESSIONID");
    assertThat(detailedCookieJsessionId, notNullValue());
    assertThat(detailedCookieJsessionId.getPath(), equalTo("/"));
    assertThat(detailedCookieJsessionId.getValue(), equalTo("B3134D534F40968A3805968207273EF5"));
}
Also used : Response(io.restassured.response.Response) Cookie(io.restassured.http.Cookie) RestAssuredMatchers.detailedCookie(io.restassured.matcher.RestAssuredMatchers.detailedCookie) Test(org.junit.Test)

Example 82 with Response

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

the class StatusCodeBasedLoggingFilter method cloneResponseIfNeeded.

/*
     * If body expectations are defined we need to return a new Response otherwise the stream
     * has been closed due to the logging.
     */
private Response cloneResponseIfNeeded(Response response, byte[] responseAsString) {
    if (responseAsString != null && response instanceof RestAssuredResponseImpl && !((RestAssuredResponseImpl) response).getHasExpectations()) {
        final Response build = new ResponseBuilder().clone(response).setBody(responseAsString).build();
        ((RestAssuredResponseImpl) build).setHasExpectations(true);
        return build;
    }
    return response;
}
Also used : Response(io.restassured.response.Response) RestAssuredResponseImpl(io.restassured.internal.RestAssuredResponseImpl) ResponseBuilder(io.restassured.builder.ResponseBuilder)

Example 83 with Response

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

the class StatusCodeBasedLoggingFilter method filter.

public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
    Response response = ctx.next(requestSpec, responseSpec);
    final int statusCode = response.statusCode();
    if (matcher.matches(statusCode)) {
        ResponsePrinter.print(response, response, stream, logDetail, shouldPrettyPrint);
        final byte[] responseBody;
        if (logDetail == LogDetail.BODY || logDetail == LogDetail.ALL) {
            responseBody = response.asByteArray();
        } else {
            responseBody = null;
        }
        response = cloneResponseIfNeeded(response, responseBody);
    }
    return response;
}
Also used : Response(io.restassured.response.Response)

Example 84 with Response

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

the class SessionFilter method filter.

public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
    if (hasStoredSessionId() && !requestHasSessionIdDefined(requestSpec)) {
        requestSpec.sessionId(sessionId.get());
    }
    final Response response = ctx.next(requestSpec, responseSpec);
    final String sessionIdInResponse = response.sessionId();
    if (isNotBlank(sessionIdInResponse)) {
        sessionId.set(sessionIdInResponse);
    }
    return response;
}
Also used : Response(io.restassured.response.Response)

Example 85 with Response

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

the class CookieFilter method filter.

public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
    final CookieOrigin cookieOrigin = cookieOriginFromUri(requestSpec.getURI());
    for (Cookie cookie : cookieStore.getCookies()) {
        if (cookieSpec.match(cookie, cookieOrigin) && !requestSpec.getCookies().hasCookieWithName(cookie.getName())) {
            requestSpec.cookie(cookie.getName(), cookie.getValue());
        }
    }
    final Response response = ctx.next(requestSpec, responseSpec);
    List<Cookie> responseCookies = extractResponseCookies(response, cookieOrigin);
    cookieStore.addCookies(responseCookies.toArray(new Cookie[responseCookies.size()]));
    return response;
}
Also used : Cookie(org.apache.http.cookie.Cookie) Response(io.restassured.response.Response) CookieOrigin(org.apache.http.cookie.CookieOrigin)

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