Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore specific JSON keys in mockserver body expectation #1878

Open
sdaus opened this issue May 30, 2024 · 0 comments
Open

Ignore specific JSON keys in mockserver body expectation #1878

sdaus opened this issue May 30, 2024 · 0 comments

Comments

@sdaus
Copy link

sdaus commented May 30, 2024

Describe the feature request
I'd like to request a feature to ignore certain JSON keys when using the .withBody(JsonBody.json(...)) request expectation matcher.

What you are trying to do
I have JSON bodies where the value of a particular key keeps changing with every single test run, making it impossible for me to use the .withBody() matcher.

Example
In this example, I have two JSON keys that change with each test run that I want to ignore: current-time' and random-id'.

        mockServerClient
                .when(request("/example").withMethod("POST")
                        .withHeader(EXAMPLE_HEADER)
                        .withBody(JsonBody.json("{\"example\": \"example data\",\"current-time\":\"1717078245\",\"random-id\": \"A98DB3\"}")), Times.once())
                .respond(response().withStatusCode(Integer.valueOf(200)));

The solution you'd like
Introduce an option to specify one or more JSON keys to be ignored when matching the JSON body.

Describe alternatives you've considered
I'm currently using a temporary workaround using EasyMock.anyString() to match any JSON body:

        mockServerClient
                .when(request("/example").withMethod("POST")
                        .withHeader(EXAMPLE_HEADER)
                        .withBody(EasyMock.anyString()), Times.once())
                .respond(response().withStatusCode(Integer.valueOf(200)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant