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