I am trying to declare a map in a Gatling Java simulation class and fill the map with values. I seem to be able to declare the map itself without an issue, however when I try adding lines such as
map.put("authToken","token")
Then I get errors such as Identifier expected and illegal start to type.
Could somebody please explain how I could declare a map at the top of the file (eg before 'teacherFeeder') and then add values to it lower down the file?
import lombok.extern.slf4j.Slf4j;
import java.util.*;
import java.util.stream.Stream;
import java.util.function.Supplier;
import java.net.*;
//import static com.hmhco.assignments.performance.simulations.config.Constants.*;
import static com.hmhco.assignments.performance.config.Constants.*;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;
@Slf4j
public class BaseSimulation extends Simulation {
HttpProtocolBuilder httpProtocol = http
.baseUrl(BASE_URL) // Here is the root for all relative URLs
.shareConnections();
public String teachers = "data/teachers.csv";
FeederBuilder<String> teacherFeeder = csv(teachers).random();
HashMap<String, String> map = new HashMap<>();
map.put("authToken", "token");
ScenarioBuilder scn1 = scenario("auth-flow").repeat(AUTH_FLOW_REPEAT).on(
feed(teacherFeeder)
.exec(http("Get Token from IDS")
.post(IDS_LOGIN_URL)
.header("Content-Type", "application/json")
.body(StringBody(
"""
{
"username":"#{username}",
"password":"#{password}",
"tenantPid":"#{connection}"
}
"""
))
.check(status().is(200))
.check(jsonPath("$.sifToken").saveAs("token"))
)
SetUp testSetup = setUp(
scn1.injectOpen(rampUsers(NUMBER_OF_USERS).during(RAMP_UP))
).maxDuration(MAX_DURATION);
}