Skip to content

Instantly share code, notes, and snippets.

@DiegoRam
Created January 13, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoRam/4377f97859cb9141ed37 to your computer and use it in GitHub Desktop.
Save DiegoRam/4377f97859cb9141ed37 to your computer and use it in GitHub Desktop.
Gatling DSL example
package com.capture.api.users
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import Settings._
class OrganizationSimulation extends BaseSimulation{
val upsertPayload = StringBody(
"""
{
"id": "${organizationId}",
"name": "${organizationId}",
"addresses": [
"address1",
"address2"
],
"phone_numbers": [
"13323",
"21212"
],
"icons": [
"icon"
],
"users": [
"diegoR"
],
"admin_users": [
"diegoR"
]
}
""")
val scn = scenario("Simulation over a single endpoint on Organizations").repeat(repeatSimulation) {
val organizationId = "org" + r.nextInt.toString
exec(session =>
session.setAll(("organizationId", organizationId))
)
.exec(
http("Login")
.post("/v1/oauth2/access_token")
.queryParam("grant_type","password")
.queryParam("client_id","12")
.queryParam("client_sercret","24")
.queryParam("username","diegoR")
.queryParam("password", "$2a$05$Cgt3hjvRzpekFMSu2/PNse6ozMr1ZoGh/sbhaiwysAo25OClFmjSC")
.check(status is 200)
.check(jsonPath("$.access_token").saveAs("token")))
.exec(
http("Create Organization")
.post("/v1/organization/")
.header("Authorization","Bearer ${token}" )
.header("Content-Type", "application/json")
.body(upsertPayload).asJSON
.check(status is 201)
.check(jsonPath("$.id").saveAs("id")))
.exec(
http( session => "Get by Organization ID")
.get("/v1/organization/${organizationId}")
.header("Authorization","Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 200)
.check(regex(organizationId).find(1).exists))
.exec(
http("update the same organization")
.put("/v1/organization/")
.body(upsertPayload).asJSON
.header("Authorization", "Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 201))
.exec(
http("update addressses field for the same organization")
.put("/v1/organization/${organizationId}/addresses")
.body(StringBody(
"""
{
"elements": ["Avenue1", "Avenue2", "Avenue3"]
}
""")).asJSON
.header("Authorization","Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 200))
.exec(
http("update Phone Numbers field for the same organization")
.put("/v1/organization/${organizationId}/phones")
.body(StringBody(
"""
{
"elements": ["2323", "3232", "1"]
}
""")).asJSON
.header("Authorization","Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 200))
.exec(
http("update users field for the same organization")
.put("/v1/organization/${organizationId}/users")
.body(StringBody(
"""
{
"elements": ["Bobby", "bo", "Max"]
}
""")).asJSON
.header("Authorization","Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 200))
.exec(
http("update admin users field for the same organization")
.put("/v1/organization/${organizationId}/adminusers")
.body(StringBody(
"""
{
"elements": ["admin"]
}
""")).asJSON
.header("Authorization","Bearer ${token}")
.header("Content-Type", "application/json")
.check(status is 200))
}
setUp(
scn.inject(atOnceUsers(users))
).protocols(httpConf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment