Skip to content

Commit

Permalink
Fixed so that with RestAssuredHttpBuilder no longer requires Response…
Browse files Browse the repository at this point in the history
…SpecificationImpl but rather a FilterableResponseSpecification
  • Loading branch information
johanhaleby committed Apr 1, 2022
1 parent ba9de60 commit 3c3ad64
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changelog next version
----------------------
* Fixed so that with RestAssuredHttpBuilder no longer requires ResponseSpecificationImpl but rather a FilterableResponseSpecification

Changelog 5.0.0 (2022-03-25)
----------------------------
* Breaking change: REST Assured now builds on Groovy 4!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ class RequestSpecificationImpl implements FilterableRequestSpecification, Groovy
throw new IllegalStateException(format("Unfortunately Rest Assured only supports Http Client instances of type %s.", AbstractHttpClient.class.getName()))
}

def http = new RestAssuredHttpBuilder(responseSpecification as ResponseSpecificationImpl, requestHeaders, queryParameters, targetUri, assertionClosure, urlEncodingEnabled,
def http = new RestAssuredHttpBuilder(responseSpecification, requestHeaders, queryParameters, targetUri, assertionClosure, urlEncodingEnabled,
config, requestSpecification.getHttpClient() as AbstractHttpClient, allowContentType, responseSpecification.rpr.defaultParser)
applyProxySettings(http)
applyRestAssuredConfig(http)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.restassured.internal;

import groovy.lang.Closure;
Expand All @@ -8,6 +24,7 @@
import io.restassured.internal.http.*;
import io.restassured.internal.util.SafeExceptionRethrower;
import io.restassured.parsing.Parser;
import io.restassured.specification.FilterableResponseSpecification;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
Expand Down Expand Up @@ -41,10 +58,10 @@ class RestAssuredHttpBuilder extends HTTPBuilder {
private RestAssuredConfig config;
private boolean allowContentType;
private Parser parser;
ResponseSpecificationImpl responseSpecification;
FilterableResponseSpecification responseSpecification;
Object assertionClosure;

RestAssuredHttpBuilder(ResponseSpecificationImpl responseSpecification, Headers requestHeaders, LinkedHashMap<String, String> queryParameters, Object defaultURI,
RestAssuredHttpBuilder(FilterableResponseSpecification responseSpecification, Headers requestHeaders, LinkedHashMap<String, String> queryParameters, Object defaultURI,
Object assertionClosure, boolean urlEncodingEnabled, RestAssuredConfig config, AbstractHttpClient client, boolean allowContentType,
Parser parser) {
super(defaultURI, urlEncodingEnabled, orNull(config, RestAssuredConfig::getEncoderConfig), orNull(config, RestAssuredConfig::getDecoderConfig), orNull(config, RestAssuredConfig::getOAuthConfig), client);
Expand Down Expand Up @@ -128,7 +145,6 @@ protected Object doRequest(HTTPBuilder.RequestConfigDelegate delegate) throws IO
Closure responseClosure = delegate.findResponseHandler(status);

Object returnVal;
Object[] closureArgs = null;
switch (responseClosure.getMaximumNumberOfParameters()) {
case 1:
returnVal = responseClosure.call(resp);
Expand All @@ -151,7 +167,7 @@ protected Object doRequest(HTTPBuilder.RequestConfigDelegate delegate) throws IO
}
return returnVal;
} finally {
if (responseSpecification.hasBodyAssertionsDefined()) {
if (responseSpecification instanceof ResponseSpecificationImpl && ((ResponseSpecificationImpl) responseSpecification).hasBodyAssertionsDefined()) {
HttpEntity entity = resp.getEntity();
if (entity != null) EntityUtils.consumeQuietly(entity);
}
Expand Down

0 comments on commit 3c3ad64

Please sign in to comment.