use of io.restassured.specification.FilterableResponseSpecification 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.specification.FilterableResponseSpecification 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.specification.FilterableResponseSpecification 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.specification.FilterableResponseSpecification in project rest-assured by rest-assured.
the class AcceptHeaderITest method accept_headers_are_merged_from_request_spec_and_request_when_configured_to.
@Test
public void accept_headers_are_merged_from_request_spec_and_request_when_configured_to() {
RequestSpecification spec = new RequestSpecBuilder().setAccept("text/jux").build();
final MutableObject<List<String>> headers = new MutableObject<List<String>>();
RestAssured.given().config(RestAssuredConfig.config().headerConfig(HeaderConfig.headerConfig().mergeHeadersWithName("Accept"))).accept(ContentType.JSON).spec(spec).body("{ \"message\" : \"hello world\"}").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
headers.setValue(requestSpec.getHeaders().getValues("Accept"));
return ctx.next(requestSpec, responseSpec);
}
}).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world"));
assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript, text/json", "text/jux"));
}
use of io.restassured.specification.FilterableResponseSpecification 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"));
}
Aggregations