I have a function that given a string, returns a boolean based on the contents
I want to get bodyString and pass it to this function and use it in check, so I get a fail if the function return false.
What is the easiest way to do this? I say easiest as I know there are many ways to do anything in Scala.
Linked to this, the next step would be calling a function that returns Option[String], Some[String] is there’s an error, and None if its ok.,
Thanks.
Excilys
2
Sorry, but you asked the same question 2 weeks ago, so the answer would still be the same.
I explained how to build custom check in this thread: https://groups.google.com/d/msg/gatling/U6tAsD0xGI4/7YWii2AT7T4J
Yes, and the answer was pretty complicated and made no sense to me.
So I put forward my question again in a more concrete fashion.
Never mind,
Dino.
Well, I found a solution.
Probably not the prettiest, but its short and doesn’t require tonnes of legwork.
I have a validate method
def validate(xml: String): String
returns empty string if ok, otherwise its an error (Guidance as to the proper use of Option[String] here would be appreciated)
I use a transform based on the above function, e.g.
.check(bodyString.transform(_.map(validate)).is(""))
So in fact I’m just doing a string comparison.
Dino.
Excilys
5
It’s very simple actually.
The check method in the HTTP DSL takes HttpChecks. Those have two attributes:
-
order that tells how to sort them when you apply several of them. In your case, the value you have to pass is Body.
-
wrapped which is the actual Check[Response].
Implementing the check method is pretty straightforward, Response is an extension of the AsyncHttpClient Response interface.
Get it?