Search in sources :

Example 1 with OrderedFilter

use of io.restassured.filter.OrderedFilter 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"));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) FilterContext(io.restassured.filter.FilterContext) List(java.util.List) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) Response(io.restassured.response.Response) Matchers.contains(org.hamcrest.Matchers.contains) OrderedFilter(io.restassured.filter.OrderedFilter) Test(org.junit.Test) RestAssured.given(io.restassured.RestAssured.given) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) WithJetty(io.restassured.itest.java.support.WithJetty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Response(io.restassured.response.Response) FilterableResponseSpecification(io.restassured.specification.FilterableResponseSpecification) OrderedFilter(io.restassured.filter.OrderedFilter) FilterableRequestSpecification(io.restassured.specification.FilterableRequestSpecification) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FilterContext(io.restassured.filter.FilterContext) Test(org.junit.Test)

Aggregations

RestAssured.given (io.restassured.RestAssured.given)1 FilterContext (io.restassured.filter.FilterContext)1 OrderedFilter (io.restassured.filter.OrderedFilter)1 WithJetty (io.restassured.itest.java.support.WithJetty)1 Response (io.restassured.response.Response)1 FilterableRequestSpecification (io.restassured.specification.FilterableRequestSpecification)1 FilterableResponseSpecification (io.restassured.specification.FilterableResponseSpecification)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Assert.assertThat (org.junit.Assert.assertThat)1 Test (org.junit.Test)1