Reputation: 5730
I'm just a newbie in Scala and gatling.
When I define
Object A{
val asset_sort = exec(http("Sort by Displays")
.get("/data/analytics/reports/")
.queryParamMap(asset_details_map)
.queryParam("""sort""", """video_starts""")
.check(status.is(200)))
.pause(1)
val device_sort = and so on ... variables.
}
Now I want to create a Scala function which return me different variable by passing certain params.
I tried something like this
val asset_sort = generateWebRequest("Sort by Displays", "video_starts", asset_details_map)
def generateWebRequest(requestName:String, sort:String, queryParamMap:HashMap):ChainBuilder = {
return exec(http(requestName)
.get("/data/analytics/reports/")
.queryParamMap(queryParamMap)
.queryParam("""sort""", sort)
.check(status.is(200)))
.pause(1)
}
But it throws error
i_ui\lib\AssetDetail.scala:47: class HashMap takes type parameters
12:50:36.708 [ERROR] i.g.a.ZincCompiler$ - def generateWebRequest(requestName:String, sort:String, qu
eryParamMap:HashMap):ChainBuilder = {
12:50:36.710 [ERROR] i.g.a.ZincCompiler$ -
Upvotes: 3
Views: 5024
Reputation: 12563
No need to specify precisely HashMap, use the generic parent interface. Also, no need (perhaps) to specify the type of generateWebRequest, let the compiler infer it. And you usually don't have to use return
in Scala.
val asset_sort = generateWebRequest("Sort by Displays", "video_starts", asset_details_map)
def generateWebRequest(requestName:String, sort:String, queryParamMap:Map[String,String]) = {
exec(http(requestName)
.get("/data/analytics/reports/")
.queryParamMap(queryParamMap)
.queryParam("""sort""", sort)
.check(status.is(200)))
.pause(1)
}
Upvotes: 2
Reputation: 7038
The "class HashMap takes type parameters" is very explicit. HashMap is a generic type, that takes 2 type parameters, one for the key type, one for the value type. Try HashMap[String, String].
Upvotes: 1