Home > Blockchain >  Gatling, saveAs using findAll - Problems with duplicates
Gatling, saveAs using findAll - Problems with duplicates

Time:08-09

I have a json response containing ID´s I want to save and reuse in subsequent call.

The json has a structure contains a part called "part 1" with ID´s and another part lets call it "part 2".

I use this expression to obtain the values:

  .check(jsonPath("$..treatmentId").findAll.saveAs("treatmentIds"))

The problem is that the expression picks up dupliacates, as in the ID´s in "part 1" also exist in "part 2". This gives me an structure with duplicates.

Is there a way to "remove duplicates" for this list or alternatively say that the findAll should start after "part 1".

I was thinking giving this json response:

 ],
  "disabledActions": [],
  "id": "f8911bcc-24e1-4a28-a5f5-08da75471ee9",
  "treatmentId": "a966ce85-6eb8-4745-4bc8-08da7547271c",
  "treatmentStart": "2022-06-24T00:00:00",
  "dssnText": "0,5 tablett morgen",
  "actionStatus": "Active",
  "treatmentStatus": "Active",
  "externalUpdate": "Handled",
  "approvalStatus": "NotEdited",
  "prescriberInitials": "MEA",
  "resepts": [
    {
      "localReseptState": "None",
      "rfReseptState": "AvailableForDispatch"
    }
  ],
  "diffPreviousValues": [],

Is it possible to state that it should save the id if it is proceeded by "disabledActions"? Something like:

   .check(jsonPath("$..disabledActions.treatmentId").findAll.saveAs("treatmentIds"))

CodePudding user response:

Here you are: $[?(@.disabledActions)].treatmentId


Another way:

    .exec { session =>
      val ids = session("treatmentIds")
        .as[Seq[String]]
        .distinct

      session.set("treatmentIds", ids)
    }
  • Related