Good day community,
My Gatling simulation is defined below:
class GatlingSpec extends Simulation {
val user = “markus”
val password = “Cn3%Vkao0xiY3v”
val postWithJSON = “postWithJSON”
def getJSONStr(uuid: String, obj: String, objType: String) =
StringBody(s"""{
“uuid”:"${uuid}",“objectid”:"${obj}",“objecttype”:"${objType}",
“user”:"${user}",“password”:"${password}"
}"""
)
val postWithJSONStr = getJSONStr(java.util.UUID.randomUUID.toString, “MyObject”, “MyObjectID”)
val httpProtocol = http
.baseURL(“https://id-38ih9fiw.google.com:444/MyServer/”)
.disableCaching
.disableClientSharing
val scn = scenario(“oxGatlingTest”).repeat(2) {
exec(
http(session => “Post with JSON”)
.post(postWithJSON)
.body(postWithJSONStr)
.asJSON
)
}
setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)
}
My Scala Play app receives request as below:
def postWithJSON = Action { implicit request =>
val jsonRequest = request.body.asJson.get
/* other code */
}
If I run the above scenario, it fails with “failed: but actually found 400” error so no communication happens with the server on which my app is hosted.
If I remove .asJSON from the test, communication happens (and I can successfully send GET requests without any JSON to my app using Gatling) in the following way:
request is of type play.api.mvc.Request, it is not null
request.body is of type play.api.mvc.AnyContent, it is not null
request.body.asJson is of type Option[AAA] but applying get on it afterwards throws a runtime exception: “java.util.NoSuchElementException: None.get”
Could you please tell me what is the right way to create and send JSON to my app? Love your tool, it is super cool.
Best wishes,
Markus