.fileBody("mybody.json", helloMap) //How 'helloMap' could be defined?

Hi,

I have an use case that require to attache on every post some variables.

If I create the Map directly inline, it works well as expected :

.exec(
http(“TemplateBody”)
.post("/someurl")
.fileBody(“mybody.json”,
Map(

"key1" → “${val1}”,
"key2" → "${val2}"
)
)
)

As I have to reuse exactly this map (or later with more value appended to this map), I’m trying to extract the creation of the map.

Naively, I tried this but with no success :

val helloMap : Map(

"key1" → “${val1}”,
"key2" → "${val2}"
)

//…

.exec(
http(“TemplateBody”)
.post("/someurl")
.fileBody(“mybody.json”,
myMap
)
)

Error is :

found : scala.collection.immutable.Map[java.lang.String,java.lang.String]
required: Map[String,com.excilys.ebi.gatling.core.session.Session => String]

Then I tried different thing to make it working (change signature, try to pass the session, …) but nothing was looking good.

Maybe someone can help on this?

Final goal is to avoid to copy/paste everywhere the Map(…) for every call.

Bonus question : is there a concept of ‘hook’ in Gatling, like “before every http request do…” ?

Thank you,
Maxence

Well we only need to declare the type.

val valuesToReplace = Map**[String,com.excilys.ebi.gatling.core.session.Session => String]**(
“key1” → “${val1}”,
“key2” → “${val2}”
);

or

val valuesToReplace : Map[String,com.excilys.ebi.gatling.core.session.Session => String] = Map(
“key1” → “${val1}”,
“key2” → “${val2}”

);

Pretty simple isn’t it?

Maybe this can help.

Max

Yep, there’s a implicit conversion happening, as long as the compiler can figure out that the types don’t match and that it has to apply this implicit conversion.
Note there’s a alias for com.excilys.ebi.gatling.core.session.Session => String named Expression.

Cheers,

Stéphane