0

I have the following JSON and I need to check if the value of total is 10 using JSONPath:

{
  "total": 10,
  "parkingSlots": [
    {
      "type": "MOTORCYCLE",
      "empty": true,
      "spaceId": "1m60"
    },
    {
      "type": "MOTORCYCLE",
      "empty": true,
      "spaceId": "1m61"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "1c62"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "1c63"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "1c64"
    },
    {
      "type": "MOTORCYCLE",
      "empty": true,
      "spaceId": "2m65"
    },
    {
      "type": "MOTORCYCLE",
      "empty": true,
      "spaceId": "2m66"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "2c67"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "2c68"
    },
    {
      "type": "CAR",
      "empty": true,
      "spaceId": "2c69"
    }
  ]
}

I am trying to use

mockMvc.perform(get("/garage/equalParkingSpaces?levels=2&mSpaces=2&cSpaces=3"))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.total", is(10)));

But it does not work and my test fails. Please tell me how else I could check for the value of total.

  • 1
    Why you test failed? Do you have any log? stacktrace? On the other hand, your test checks that total value is 30, not 10. – Mateusz Korwel Jul 07 '16 at 15:16
  • Sorry for that I copied the wrong code, I am checking for 10 and the stack trace for test failure is : java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException at org.springframework.test.web.servlet.result.JsonPathResultMatchers.(JsonPathResultMatchers.java:52) at org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath(MockMvcResultMatchers.java:192) at task.garage.controller.GarageControllerTest.createParkingSpaces(GarageControllerTest.java:85) – Abhilash Mishra Jul 07 '16 at 15:21
  • Could you copy your pom.xml or build.gradle file? Probably you haven't some dependencies, for example: https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path/2.2.0 – Mateusz Korwel Jul 07 '16 at 15:29
  • Please [edit] your post to add any additional information you have to your question. Avoid adding this in the comments, as they are harder to read and can be deleted easier. – Scott Weldon Jul 07 '16 at 15:44

0 Answers0