use of io.restassured.builder.ResponseBuilder 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));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class PathParamITest method unnamedPathParametersWorksWhenThereAreMultipleTemplatesBetweenEachSlash.
@Test
public void unnamedPathParametersWorksWhenThereAreMultipleTemplatesBetweenEachSlash() throws Exception {
String param1Value = "Hello";
String param2Value = "Hello2";
given().filter((requestSpec, responseSpec, ctx) -> new ResponseBuilder().setStatusCode(200).setStatusLine("HTTP/1.1 200 OK").setBody(requestSpec.getURI()).build()).when().get("param1={param1Value}¶m2={param2Value}", param1Value, param2Value).then().body(equalTo("http://localhost:8080/param1%3DHello%26param2%3DHello2"));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class PathParamITest method mixingUnnamedPathParametersAndQueryParametersWorks.
@Test
public void mixingUnnamedPathParametersAndQueryParametersWorks() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("/{channelName}/item-import/rss/import?source={url}", "games", "http://myurl.com");
// Then
assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/games/item-import/rss/import?source=http%3A%2F%2Fmyurl.com"));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class RequestSpecMergingITest method mergesHeadersCorrectlyWhenOnlyStaticMerging.
@Test
public void mergesHeadersCorrectlyWhenOnlyStaticMerging() {
given().filter((requestSpec, responseSpec, ctx) -> {
Headers headers = requestSpec.getHeaders();
assertThat(requestSpec.getContentType(), nullValue());
assertThat(headers.getValue("authorization"), equalTo("abracadabra"));
assertThat(headers.getValue("accept"), equalTo("*/*"));
assertThat(headers.size(), is(2));
return new ResponseBuilder().setStatusCode(200).build();
}).when().get();
}
use of io.restassured.builder.ResponseBuilder 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;
}
Aggregations