Put jsonPaths into request matchers (not response)
The correct WireMock JSON stubs should be available after this change. Otherwise the json paths that were applied to the request in the RESTdocs test were being translated into response matchers in the contract (which doesn't even do anything in WireMock).
This commit is contained in:
@@ -77,10 +77,6 @@ public class ContractDslSnippet extends TemplatedSnippet {
|
||||
filterHeaders(headers);
|
||||
model.put("response_headers_present", !headers.isEmpty());
|
||||
model.put("response_headers", headers.entrySet());
|
||||
@SuppressWarnings("unchecked") Set<String> jsonPaths = (Set<String>) operation.getAttributes()
|
||||
.get("contract.jsonPaths");
|
||||
model.put("response_json_paths_present", jsonPaths != null && !jsonPaths.isEmpty());
|
||||
model.put("response_json_paths", jsonPaths(jsonPaths));
|
||||
}
|
||||
|
||||
private Set<JsonPaths> jsonPaths(Set<String> jsonPaths) {
|
||||
@@ -104,6 +100,10 @@ public class ContractDslSnippet extends TemplatedSnippet {
|
||||
filterHeaders(headers);
|
||||
model.put("request_headers_present", !headers.isEmpty());
|
||||
model.put("request_headers", headers.entrySet());
|
||||
@SuppressWarnings("unchecked") Set<String> jsonPaths = (Set<String>) operation.getAttributes()
|
||||
.get("contract.jsonPaths");
|
||||
model.put("request_json_paths_present", jsonPaths != null && !jsonPaths.isEmpty());
|
||||
model.put("request_json_paths", jsonPaths(jsonPaths));
|
||||
}
|
||||
|
||||
private void filterHeaders(Map<String, String> headers) {
|
||||
|
||||
@@ -16,6 +16,13 @@ Contract.make {
|
||||
{{/request_headers}}
|
||||
}
|
||||
{{/request_headers_present}}
|
||||
{{#request_json_paths_present}}
|
||||
stubMatchers {
|
||||
{{#request_json_paths}}
|
||||
jsonPath('''{{jsonPath}}''', byEquality())
|
||||
{{/request_json_paths}}
|
||||
}
|
||||
{{/request_json_paths_present}}
|
||||
}
|
||||
response {
|
||||
status {{response_status}}
|
||||
@@ -31,12 +38,5 @@ Contract.make {
|
||||
{{/response_headers}}
|
||||
}
|
||||
{{/response_headers_present}}
|
||||
{{#response_json_paths_present}}
|
||||
testMatchers {
|
||||
{{#response_json_paths}}
|
||||
jsonPath('''{{jsonPath}}''', byType())
|
||||
{{/response_json_paths}}
|
||||
}
|
||||
{{/response_json_paths_present}}
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ public class ContractDslSnippetTests {
|
||||
then(parsedContract.getRequest().getUrl().getClientValue()).isNotNull();
|
||||
then(parsedContract.getRequest().getUrl().getClientValue().toString()).startsWith("/");
|
||||
then(parsedContract.getRequest().getBody().getClientValue()).isNotNull();
|
||||
then(parsedContract.getRequest().getMatchers().hasMatchers()).isTrue();
|
||||
then(parsedContract.getResponse().getStatus().getClientValue()).isNotNull();
|
||||
then(parsedContract.getResponse().getHeaders().getEntries()).isNotEmpty();
|
||||
then(parsedContract.getResponse().getBody().getClientValue()).isNotNull();
|
||||
then(parsedContract.getResponse().getMatchers().hasMatchers()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user