using a feeder in a custom validation function

Hi,

I use the next scenario

`
def getPath(id: String): String = s"/content/prod${id}"

def getRequestBody(currentId: String): String = {
buildJson(currentId)
}

def getCheck(expected: String): HttpCheck =
bodyString.validate(_ => buildMatcher(expected))

val feeder = Iterator.continually(Map(“idR” → random))

scenario(“Test”)
.feed(feeder)
.exec(
http(“PUT ${idR}”)
.put(getPath("${idR}"))
.headers(headersJson)
.body(StringBody(getRequestBody("${idR}")))
.asJSON
.check(
status is 200
)
)
.pause(1 seconds)
.exec(
http(“GET ${idR}”)
.get(getPath("${idR}"))
.headers(headersJson)
.check(getCheck("${idR}")
)
}
`

with the custom functions for request body, url, checks. For body and url it works fine as the results are the strings, but for check it doesn’t work. I understand why(Warning This Expression Language only works on the final value that is passed to the DSL method when the Simulation is instantiated.) but I dont understand the way for use this with a custom validation function. Could you help me?
P.S. sorry for my english.

First, make getCheck take an Expression[String] instead of a String, so implicit EL conversion gets triggered.
Then, instead of discarding (underscore) the session input of the lambda you pass to validate, use it :slight_smile:

def getCheck(expected: Expression[String]): HttpCheck =
bodyString.validate(session => expected(session).map(resolvedExpected => buildMatcher(resolvedExpected))

Thank you, it works fine.

Have a nice day!

Great :slight_smile:
Have fun