JsonPath assertions type JSONArray

709 views Asked by At

I'm trying to make a test validating one json using JsonPath, I could create the test, but when I validate what I got is probably a type error Expected: <[4]> but: was <[4]> my test is this:

mockmvc.perform(get("/client/rating"))
    .andExpect(status().isOk())
    .andExpect(jsonPath("$", hasSize(3)))
    .andExpect(jsonPath("$[?(@.id == prod1)].rate", equalTo(new JSONArray("[4]"))));

I don't have the Json tested here, but the value is right, the only problem is its type...

I appreciate any help!

1

There are 1 answers

0
Marcos Nunes On BEST ANSWER

you can do this test this way:

mockmvc.perform(get("/client/rating"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$", hasSize(3)))
                .andExpect(jsonPath("$[?(@.id == prod1)].rate").value(4));