sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Default Filters accumulate and are not merge when reusing request specs #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The filters in RestAssured.filter are used for each new RequestSpecification 
and are not merged but concatenated when reusing spec via "spec".
This way they accumulate and can lead to strange behaviour. Basicly 
RestAssured.filter can not be used in conjunction with reusing specs. A 
workaround is remove filters from reusable specs.
A bitter solution would be to let SpecificationMerger#mergeFilters remove 
duplicate (by equalTo) filters.

Here is a test to reproduce:

    @Test
    public void testDefaultfiltersAccumluate() {
        CountingFilter myFilter = new CountingFilter();
        RestAssured.config = RestAssuredConfig.newConfig();
        RestAssured.filters(myFilter);

        RequestSpecification spec = new RequestSpecBuilder().build();
        // Uncomment next line as workaround
        // spec.noFilters();

        given().get("www.google.com");
        assertThat (myFilter.counter, equalTo(1)); // works

        given().spec(spec).get("www.google.com");
        assertThat (myFilter.counter, equalTo(2));  // fails, got 3!
    }

    public static class CountingFilter implements Filter {
        public int counter = 0;
        @Override
        public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
            counter++;
            return ctx.next (requestSpec, responseSpec);
        }        
    }

I'm using RestAssured 1.6.2

Original issue reported on code.google.com by martinEi...@gmail.com on 29 Aug 2012 at 5:48

GoogleCodeExporter commented 9 years ago
Thanks for reporting. It would be really nice if you could help out if you want 
it included in the next release.

Original comment by johan.ha...@gmail.com on 29 Aug 2012 at 7:00

GoogleCodeExporter commented 9 years ago
I gave it a try: https://github.com/jayway/rest-assured/pull/11

Original comment by martinEi...@gmail.com on 3 Sep 2012 at 5:48

GoogleCodeExporter commented 9 years ago
Thank you very much. I've now pull it into the main branch.

Original comment by johan.ha...@gmail.com on 3 Sep 2012 at 5:53

GoogleCodeExporter commented 9 years ago
I've uploaded the latest snapshot (1.6.3-SNAPSHOT) to sonatype so you can try 
it out by adding the following repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

Original comment by johan.ha...@gmail.com on 3 Sep 2012 at 6:24