ekino / jcv

JSON Content Validator (JCV) allows you to compare JSON contents with embedded validation.
https://ekino.github.io/jcv
MIT License
21 stars 0 forks source link

Add wiremock module #22

Closed MrAolen closed 3 years ago

MrAolen commented 3 years ago

Hi,

it could be cool to provide a wiremock module to validate request or response body json with JCV validators.

In wiremock, when we try to compare a json array with another one but not in the same order, the EqualToJsonPattern doesn't match. ( here is an issue in wiremock repository : https://github.com/tomakehurst/wiremock/issues/1230 ). If we use a JCV with wiremock it should fix this.

If you want to test the current EqualToJsonPattern error, here is a test :

@Test
  void reproduceFailingIgnoreArrayOrder() {
    var expected = "{ \"array\": [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"] }";
    var actual = "{ \"array\": [\"b\",\"a\",\"d\",\"c\",\"e\",\"f\",\"g\",\"h\"] }";
    var pattern = new EqualToJsonPattern(expected, true, false);
    var result = pattern.match(actual);
    var exact = result.isExactMatch();
    assertTrue(exact);
  }
clemstoquart commented 3 years ago

Hi,

I cant' reproduce the failing test with both JDK 11.0.9 and 15.

leomillon commented 3 years ago

@clemstoquart me neither, but anyway, this could still be an interesting feature

leomillon commented 3 years ago

Erratum: it's failing with WireMock version 2.25.1 but not anymore with the latest 2.27.2 version