I’m new to Gatling and initially used Scala for the load test but now want to go ahead with Java as the compiler is much faster. And therefore I want to convert the below Scala code that I had written earlier to Java.
Scenarios in Loop
import io.gatling.http.Predef.*
import io.gatling.core.Predef.*
import io.gatling.core.structure.PopulationBuilder
import scala.collection.immutable.ArraySeq
import scala.collection.mutable
import scala.concurrent.duration.*
import scala.language.postfixOps
class personalDetails extends Simulation {
// Protocol
val httpProtocol = http.baseUrl("https://morpheus.uat.creditsaison.xyz")
.contentTypeHeader("application/json")
.header("requestingSub", "5317f163-448d-48f2-8f30-900cdd669288")
.authorizationHeader("Basic QGRNMU46UEAkJFcwckQ=")
var users = 100
var i = 0
// Scenario
def scnList() = {
var scnList = List.empty[PopulationBuilder]
for (_ <- 0 to 2) yield {
val injectionProfile = users match {
case 100 => rampUsers(5).during(1)
case 200 => rampUsers(10).during(1)
case 300 => rampUsers(15).during(1)
}
val scn = scenario(s"Personal Details ${users} Users")
.exec(
http("Personal Details API")
.post("/api/v1/appForm")
.check(status.is(424))
.body(RawFileBody("./src/test/resources/requestBody/personaldetails.json")).asJson
)
.inject(injectionProfile)
scnList :+= scn
users += 100
}
scnList
}
// Setup
setUp(
scnList(): _*
).protocols(httpProtocol)
}