Search in sources :

Example 1 with MatchResult

use of com.github.tomakehurst.wiremock.matching.MatchResult in project spring-cloud-netflix by spring-cloud.

the class WireMockRestAssuredRequestAdapter method filter.

@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext context) {
    Map<String, Object> configuration = getConfiguration(requestSpec, context);
    configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
    Response response = context.next(requestSpec, responseSpec);
    if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
        String actual = new String((byte[]) requestSpec.getBody());
        for (JsonPath jsonPath : this.jsonPaths.values()) {
            new JsonPathValue(jsonPath, actual).assertHasValue(Object.class, "an object");
        }
    }
    if (this.builder != null) {
        this.builder.willReturn(getResponseDefinition(response));
        StubMapping stubMapping = this.builder.build();
        MatchResult match = stubMapping.getRequest().match(new WireMockRestAssuredRequestAdapter(requestSpec));
        assertThat(match.isExactMatch()).as("wiremock did not match request").isTrue();
        configuration.put("contract.stubMapping", stubMapping);
    }
    return response;
}
Also used : Response(io.restassured.response.Response) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) JsonPath(com.jayway.jsonpath.JsonPath) MatchResult(com.github.tomakehurst.wiremock.matching.MatchResult)

Aggregations

MatchResult (com.github.tomakehurst.wiremock.matching.MatchResult)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 JsonPath (com.jayway.jsonpath.JsonPath)1 Response (io.restassured.response.Response)1