Codearte / accurest

Accurest - Consumer Driven Contracts verifier for Java. Moved to:
https://github.com/spring-cloud/spring-cloud-contract
Apache License 2.0
99 stars 23 forks source link

Support top level arrays #266

Closed jkubrynski closed 8 years ago

jkubrynski commented 8 years ago

Extracted from #262

io.codearte.accurest.dsl.GroovyDsl.make {
    request {
        method 'GET'
        urlPath '/api/tags'
    }
    response {
        status 200
        body("""["Java", "Java8", "Spring", "SpringBoot", "Stream"]""")
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
}
making commented 8 years ago

Hi, I confirmed 4e95a90 fixes my testcases above and found another issue

io.codearte.accurest.dsl.GroovyDsl.make {
    request {
        method 'GET'
        urlPath '/api/categories'
    }
    response {
        status 200
        body([["Programming", "Java"], ["Programming", "Java", "Spring", "Boot"]])
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
}

generates

    @Test
    public void validate_getCategories_200() throws Exception {
        // given:
            MockMvcRequestSpecification request = given();

        // when:
            ResponseOptions response = given().spec(request)
                    .get("/api/categories");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).isEqualTo("application/json;charset=UTF-8");
        // and:
            DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
    }

No assertion

marcingrzejszczak commented 8 years ago

@making - can you check that with Accurest SNAPSHOT? You have to unfortunately build it yourself :/

making commented 8 years ago

Now I got:

    @Test
    public void validate_getCategories_200() throws Exception {
        // given:
            MockMvcRequestSpecification request = given();

        // when:
            ResponseOptions response = given().spec(request)
                    .get("/api/categories");

        // then:
            assertThat(response.statusCode()).isEqualTo(200);
            assertThat(response.header("Content-Type")).isEqualTo("application/json;charset=UTF-8");
        // and:
            DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
            assertThatJson(parsedJson).array().arrayField().isEqualTo("Boot").value();
            assertThatJson(parsedJson).array().arrayField().isEqualTo("Programming").value();
            assertThatJson(parsedJson).array().arrayField().isEqualTo("Java").value();
            assertThatJson(parsedJson).array().arrayField().isEqualTo("Spring").value();
    }

👍

Thanks!

marcingrzejszczak commented 8 years ago

Sweet!