API level testing

I need some help putting together a Gatling to test stress my API. I am still new to Gatliong so any help would be appreciated.

so I have this new service API called “getDriver” using the “Advanced rest client” on chrome I pass in header and a body and it returns result.

example:
POST
https://Myserver-service…mycompany.com/uservice/http/driver/json

Header is context: {“uID”:0,“gId”:0,“drId”:159577,“cId”:0,"__isset_bitfield":4,“optionals”:[“CLIENT”]}

Body is [1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}]

My question is how do I take this and convert it to a Gatling test ?

this is what I have so far, which I know is not correct!!!

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class Test extends Simulation {

val httpProtocol = http
.baseURL(“https://myserver-uservice.mycompany.com”)
.inferHtmlResources()
.acceptHeader("""/""")
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-US,en;q=0.5"”")
.connection(""“keep-alive”"")
.contentTypeHeader(""“application/x-www-form-urlencoded; charset=UTF-8"”")
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"”")

val headers_0 = Map(
//""“context”""-> “”"{“uId”:0,“gId”:0,“dId”:159577,“cId”:0,"__isset_bitfield":4,“optionals”:[“CLIENT”]}""",
“”“Content-Type”"" → “”“text/json; charset=UTF-8"”"
)

val scn = scenario(“addonestop”)
.exec(http(“API”)
.post("""/userservice/http/driver/json""")
.headers(headers_0)
.body(StringBody(""""[1,“getDriver”,1,1,{“1"”: “{“rec”:{“1”:{“i64”:0},“4”:{“i64”:159577},“5”:{“i64”:0}}}}]” }""")).asJSON
)
.pause(4)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

What’s the problem exactly?

The problem is I don’t know to create a Gatling test that will test my API. Given the information below, I am not sure how to translate taht into a Gatling script.

POST
https://Myserver-service…mycompany.com/uservice/http/driver/json

Header is context: {“uID”:0,“gId”:0,“drId”:
159577,“cId”:0,"__isset_bitfield":4,“optionals”:[“CLIENT”]}

Body is [1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}]

It sounds like you are trying to stress/load test json response. You probably want to parametrize the script and want to stress with multiple users.

Gatling will be able to handle the tasks. Why not start with the tutorial? http://gatling.io/docs/2.1.2/quickstart.html and http://gatling.io/docs/2.1.2/advanced_tutorial.html

It covers the basic and you will be able to simple scripts in no time.

no, all I want is an example of how to test a REST API

http://ivanursul.com/2015/01/testing-restful-web-service-gatling-integration-tool/

I keep on geting a 406 error

package addonestop

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class addonestop extends Simulation {

val httpProtocol = http
.baseURL(“http://myserver-uservice.mycompany.com”)

.inferHtmlResources()
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”)
.doNotTrackHeader(“1”)
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-US,en;q=0.5"”")
.connection(""“keep-alive”"")
.contentTypeHeader(""“application/x-www-form-urlencoded; charset=UTF-8"”")
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"”")

val headers_0 = Map(
“”“Accept”"" → “”“application/json, text/javascript, /; q=0.01"”",
“”“Cache-Control”"" → “”“no-cache”"",
“”“Content-Type”"" → “”“application/json; charset=UTF-8"”",
“”“Pragma”"" → “”“no-cache”"",
“”“X-Requested-With”"" → “”“XMLHttpRequest”"")

val scn = scenario(“addonestop”)
.exec(http(“API”)
.post("""/userservice/http/driver/json""")
.headers(headers_0)
.body(StringBody(""“context:{“userId”:0,“groupId”:0,“driverId”:12345,“companyId”:0,”__isset_bitfield":4,“optionals”:[“CLIENT”]}""")).asJSON
)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

so let me try to explain what I am trying to achieve… I am usikng this tool from googl ecalled “Advanced Rest
Client”, to test my API with this tool I supply a raw format header (context:{“uId”:0,“gId”:0,“dId”:12345,“companyId”:0,"__isset_bitfield":4,“optionals”:[“CLIENT”]}) and a body

[1,“getDriver”,1,1,{“1”:{“rec”:{“1”:{“i64”:0},“4”:{“i64”:12345},“5”:{“i64”:0}}}}].

so now I want to do the same test in gatling, but I am bnot sure how to build the gatling script.