Hi all, I’m having a hard time passing a variable from my GET call to my DELETE call for some reason. I’ve done this a million times but in this case it does not work for me. Any help would be appreciated!!
public static final ChainBuilder getListOfStuff =
exec(http("Get List of Stuff")
.get("/example/api/v1/stuffs")
.headers(getSessionHeaders())
.check(status().is(200))
.check(jsonPath("$..id").exists().saveAs("stuffsId"))
);
public static final ChainBuilder deleteStuffIfCurrentUserIsOwnerOfStuff;
static {
try {
deleteStuffIfCurrentUserIsOwnerOfStuff =
exec(http("Delete Stuff If Current User Is Owner")
.delete("/example/api/v1/stuffs")
.headers(getStuffSessionHeaders("#{stuffsId}"))
.check(status().is(204))
);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Map<String, String> getStuffSessionHeaders(String stuffsId) throws IOException {
System.out.println("stuffsId=========" + stuffsId);
...................
}
The result I get from trying to pass #{stuffsId} to a java method is
“stuffId=========#{stuffsId}” instead of the actual stuff ID i’m saving in GET from previous call.
I’m trying to pass a variable to a method call which builds out the headers, including calculating the bearer token, but the stuff ID i’m passing to the method does not send the value, it sends “#{stuffId}” as the actual string
public static final ChainBuilder deleteStuffIfCurrentUserIsOwnerOfStuff;
static {
try {
deleteStuffIfCurrentUserIsOwnerOfStuff =
exec(http("Delete Stuff If Current User Is Owner")
.delete("/example/api/v1/stuffs")
.headers(getStuffSessionHeaders("#{stuffsId}"))
.check(status().is(204))
);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Map<String, String> getStuffSessionHeaders(String stuffsId) throws IOException {
System.out.println("stuffsId=========" + stuffsId);
STUFF_HELPER = new STUFFHelper(context);
String stuffAccessToken = STUFF_HELPER.getSwitchStuffToken(stuffsId, getUserTokens());
Map<String, String> stuffsSessionHeaders = new HashMap<String, String>();
stuffsSessionHeaders.put("content-Type", "application/json");
stuffsIdSessionHeaders.put("accept", "application/json");
stuffsIdSessionHeaders.put("authorization", "Bearer " + accountAccessToken);
return accountSessionHeaders;
}
As stated in the first alert box of the Concepts page:
The components of this DSL are mere definitions of the desired effect. They don’t generate the desired effect where you invoke them in your own code. Only when chained with other components so they are ultimately passed to the setUp, can the Gatling engine interpret them and produce the desired effect.
So, the call to your getStuffSessionHeaders is executed during the initialization phase. Way before the first virtual user is created.
I’m trying to change tokens mid test - user needs a space specific token after they sign up to become an owner of some space. I need to get a new token for the user to be able to work within their specific space (including deleting their space after they are done with it. Any thought on how I can do this within gatling?