use of io.restassured.filter.FilterContext in project rest-assured by rest-assured.
the class OrderedFilterITest method high_precedence_are_sorted_before_low_precedence.
@Test
public void high_precedence_are_sorted_before_low_precedence() {
List<String> list = new CopyOnWriteArrayList<>();
given().filter((requestSpec, responseSpec, ctx) -> {
list.add("Default");
return ctx.next(requestSpec, responseSpec);
}).filter(new OrderedFilter() {
@Override
public int getOrder() {
return 1002;
}
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
list.add("Custom");
return ctx.next(requestSpec, responseSpec);
}
}).filter(new OrderedFilter() {
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
list.add("Lowest");
return ctx.next(requestSpec, responseSpec);
}
}).filter(new OrderedFilter() {
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
list.add("Highest");
return ctx.next(requestSpec, responseSpec);
}
}).when().get("/lotto");
assertThat(list, contains("Highest", "Default", "Custom", "Lowest"));
}
use of io.restassured.filter.FilterContext in project rest-assured by rest-assured.
the class HttpClientConfigITest method local_http_client_config_reuse_reuse_static_http_client_instance_when_local_config_changes_other_configs_than_http_client_config.
@Test
public void local_http_client_config_reuse_reuse_static_http_client_instance_when_local_config_changes_other_configs_than_http_client_config() {
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().config(RestAssured.config.decoderConfig(DecoderConfig.decoderConfig().with().contentDecoders(DecoderConfig.ContentDecoder.DEFLATE))).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client2.setValue(requestSpec.getHttpClient());
return ctx.next(requestSpec, responseSpec);
}
}).expect().body("Accept-Encoding", contains("deflate")).when().get("/headersWithValues");
} finally {
RestAssured.reset();
}
assertThat(client1.getValue(), sameInstance(client2.getValue()));
}
use of io.restassured.filter.FilterContext in project rest-assured by rest-assured.
the class HttpClientConfigITest method httpClientIsConfigurableFromAStaticHttpClientConfigWithOtherConfigurations.
@Test
public void httpClientIsConfigurableFromAStaticHttpClientConfigWithOtherConfigurations() {
// Given
final MutableObject<HttpClient> client = new MutableObject<>();
RestAssured.config = RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().setParam(HANDLE_REDIRECTS, true).and().setParam(MAX_REDIRECTS, 0).and().httpClientFactory(SystemDefaultHttpClient::new));
// When
try {
given().param("url", "/hello").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client.setValue(requestSpec.getHttpClient());
return ctx.next(requestSpec, responseSpec);
}
}).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");
} finally {
RestAssured.reset();
}
// Then
assertThat(client.getValue(), instanceOf(SystemDefaultHttpClient.class));
}
use of io.restassured.filter.FilterContext in project rest-assured by rest-assured.
the class HttpClientConfigITest method httpClientIsConfigurableFromANonStaticHttpClientConfig.
@Test
public void httpClientIsConfigurableFromANonStaticHttpClientConfig() {
// Given
final MutableObject<HttpClient> client = new MutableObject<>();
// When
given().config(RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(SystemDefaultHttpClient::new))).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(SystemDefaultHttpClient.class));
}
use of io.restassured.filter.FilterContext in project rest-assured by rest-assured.
the class HttpClientConfigITest method local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse.
@Test
public void local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse() {
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().config(RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance())).header("name", "value").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client2.setValue(requestSpec.getHttpClient());
return ctx.next(requestSpec, responseSpec);
}
}).when().post("/reflect");
} finally {
RestAssured.reset();
}
assertThat(client1.getValue(), not(sameInstance(client2.getValue())));
}
Aggregations