question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The hard-coded values of `ignoreArrayOrder` and `ignoreExtraElements` cause problems when recording

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MasonMcommented, Jul 4, 2017

@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.

0reactions
tomakehurstcommented, Jul 4, 2017

@MasonM yes, that’s exactly what I had in mind.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found