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"));
}
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;
}
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;
}
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;
}
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;
}
Aggregations