I believe so.
So, what I ended up with was:
object HttpBodyJsonPPathCheckBuilder extends Logging {
val preparer: Preparer[Response, Any] = (response: Response) =>
try {
val resp = response.getResponseBody(configuration.core.encoding)
val i1 = resp.indexOf("(") + 1
val i2 = resp.lastIndexOf(")")
val json = resp.substring(i1, i2)
JsonPathExtractor.parse(json).success
} catch {
case e: Exception =>
val message = s"Could not parse response into a JSON object: ${e.getMessage}"
logger.info(message, e)
message.failure
}
def jsonPath[X](path: Expression[String])(implicit groupExtractor: JsonFilter[X]) =
new HttpMultipleCheckBuilder[Any, X](HttpCheckBuilders.bodyCheckFactory, preparer) {
def findExtractor(occurrence: Int) = new SingleJsonPathExtractor(path, occurrence)
def findAllExtractor = new MultipleJsonPathExtractor(path)
def countExtractor = new CountJsonPathExtractor(path)
}
}
Elsewhere, I defined:
def jsonPPath(path: String) = HttpBodyJsonPPathCheckBuilder.jsonPathString
And so now my checks for JSONP look like:
def checkJsonpAssetStructure(count: Int): Iterable[HttpCheck] = {
List(
regex("""(?:\w+.)\w+(.)""").count.is(1),
jsonPPath("$").count.is(1),
jsonPPath("$.status").find.is(“200”),
jsonPPath("$.body[]").count.is(count),
jsonPPath("$.body[].id").count.is(count),
jsonPPath("$.body[*].title").count.is(count),
jsonPPath("$.body[].description").count.is(count)//,
jsonPPath("$.body[].publishdate").count.is(count),
)
}
This seems to be working like a charm.
Might be worth it for other people to have this integrated more directly into gatling. If that were to happen, you’d probably want to incorporate the regex check into the HttpBodyJsonPPathCheckBuilder. Not real sure what that would look like though.
Anyhow - thanks for the help - I’ll be making heavy use of this.
–Spencer