jsonPath and array

189 views
Skip to first unread message

E. Ulrich Kriegel

unread,
Apr 23, 2014, 8:49:09 AM4/23/14
to gat...@googlegroups.com
Hi there,
my REST-Service returns

{"index":[{"provider_id":"foo","etag":"f77d14f2549485c4e087d3d7b1250cbd77b7da24"},{"provider_id":"baz","etag":"7de32bc8c614165c0c3a62dfda238cec0d7a5139"}]}

The expression $.index[*].provider_id should return (and the expression checker http://jsonpath.curiousconcept.com does)
[
   "foo",
   "baz"
]

bat returns "baz" only

--Ulrich

Nicolas Rémond

unread,
Apr 23, 2014, 9:06:14 AM4/23/14
to gat...@googlegroups.com
Which version of Gatling are you using ?


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

E. Ulrich Kriegel

unread,
Apr 23, 2014, 9:08:06 AM4/23/14
to gat...@googlegroups.com
Sorry, 
Gatling2 Snapshot checked out April, 12th

Nicolas Rémond

unread,
Apr 23, 2014, 9:15:48 AM4/23/14
to gat...@googlegroups.com
  "Mailing-list test case" should "work"  in {
    val json= parseJson( """{"index":[{"provider_id":"foo","etag":"f77d14f2549485c4e087d3d7b1250cbd77b7da24"},{"provider_id":"baz","etag":"7de32bc8c614165c0c3a62dfda238cec0d7a5139"}]}""")
    JsonPath.query( "$.index[*].provider_id", json) should findElements(text("foo"), text("baz"))
  }

With the last JsonPath engine, the following unit test is working fine.
Can you 



Nicolas Rémond

unread,
Apr 23, 2014, 9:17:17 AM4/23/14
to gat...@googlegroups.com
  "Mailing-list test case" should "work"  in {
    val json= parseJson( """{"index":[{"provider_id":"foo","etag":"f77d14f2549485c4e087d3d7b1250cbd77b7da24"},{"provider_id":"baz","etag":"7de32bc8c614165c0c3a62dfda238cec0d7a5139"}]}""")
    JsonPath.query( "$.index[*].provider_id", json) should findElements(text("foo"), text("baz"))
  }

With the last JsonPath engine, the following unit test is working fine.
Can you show me the associated Gatling script? 
How do you come to the conclusion that the jsonPath() check isn't working as expected ?


Regards
Nicolas

E. Ulrich Kriegel

unread,
Apr 23, 2014, 9:28:08 AM4/23/14
to gat...@googlegroups.com
Hi Nicolas,

here comes the scenario definition:

val scn = scenario("get service areas")

.feed(ssv("gabriel/devices.ssv").circular)

.exec(

http("get service_areas")

    .get("/service_areas")

    .headers(Headers.default)

.header("X-KWRN-Device-ID","${deviceId}")

.check(jsonPath("$.index[*].provider_id")

  .saveAs("providerIdList"))

.check(header("Etag").saveAs("Etag"))

.check(status.saveAs("status"), status.is(200)))

.exec(session=>{println(session)

  session})


I simply printed the session, and providerIdList is in any case "foo", the first element of the array

Nicolas Rémond

unread,
Apr 23, 2014, 9:30:54 AM4/23/14
to gat...@googlegroups.com
Would you mind trying again with the extra ".findAll":

.check(jsonPath("$.index[*].provider_id").findAll.saveAs("providerIdList"))

Thanks
Nicolas

E. Ulrich Kriegel

unread,
Apr 23, 2014, 9:33:07 AM4/23/14
to gat...@googlegroups.com
Thanks
Reply all
Reply to author
Forward
0 new messages