The hard-coded values of `ignoreArrayOrder` and `ignoreExtraElements` cause problems when recording
See original GitHub issueI discovered this while investigating #691 and consider it to be another bug.
StubbingMappingJsonRecorder.valuePatternForContentType
contains the code return equalToJson(request.getBodyAsString(), true, true);
This leads to only one recording being made for these requests:
request[0] = "{\"columns\": [{\"name\": \"x\",\"y\": 3},{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"agreementstatus\",\"b\": 2}]}";
request[1] = "{\"columns\": [{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"agreementstatus\",\"b\": 2}]}";
And these:
request[0] = "{\"columns\": [1, 2, 3]}";
request[1] = "{\"columns\": [2, 1, 3]}";
With the following test code:
public class Buggtest {
public static final String URL = "/post";
public static final String PROXYBASEURL = "http://httpbin.org";
public static void main(String[] args) {
WireMockServer wireMockServer=null;
try {
wireMockServer = new WireMockServer(options()
.port(8099)
.notifier(new ConsoleNotifier(true)));
wireMockServer.start();
FileUtils.cleanDirectory(new File("/tmp/mappings"));
FileUtils.cleanDirectory(new File("/tmp/__files"));
wireMockServer.enableRecordMappings(new SingleRootFileSource("/tmp/mappings"), new SingleRootFileSource("/tmp/__files"));
configureFor("localhost", 8099);
stubFor(post(urlEqualTo(URL)).willReturn(aResponse().proxiedFrom(PROXYBASEURL)));
call();
wireMockServer.stop();
}
catch (Exception e){
e.printStackTrace();
}
finally {
if (wireMockServer!=null && wireMockServer.isRunning()) {
wireMockServer.stop();
}
}
}
private static void call() {
String[] request = new String[2];
request[0] = "{\"columns\": [{\"name\": \"x\",\"y\": 3},{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"agreementstatus\",\"b\": 2}]}";
request[1] = "{\"columns\": [{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"agreementstatus\",\"b\": 2}]}";
for (int i = 0; i < request.length; i++) {
System.out.println("Doing request: " + request[i]);
Response r = given().contentType("application/json").body(request[i]).when().post("http://localhost:8099"+ Buggtest.URL);
String body = r.getBody().asString();
System.out.println("Request response:\n------8<----------------------------" );
System.out.println(body);
System.out.println("--------------------------------------->8-------");
}
}
}
Expected behavior: Two files should be recorded, one for each request. Actual behavior: Only one file is recorded.
Caused by: return equalToJson(request.getBodyAsString(), true, true);
Possible fix: Make it possible somehow to inject values for ignoreArrayOrder
and ignoreExtraElements
for the EqualToJsonPattern
when recording.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
The hard-coded values of ignoreArrayOrder and ... - GitHub
Actual behavior: Only one file is recorded. Caused by: return equalToJson(request.getBodyAsString(), true, true);. Possible fix: Make it ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Zomis The new recorder in PR #674 is an API endpoint (
/__admin/recordings/snapshot
) that accepts a JSON string with various options, so I’m proposing a new option here. These options aren’t persisted to the mapping files, they’re just for customizing the recording process.The API is also available as an extension: wiremock-snapshot.
@MasonM yes, that’s exactly what I had in mind.