Right now I am using the JSON path function to get the JSON response values like placeid, profileid and then am declaring that as static, because I need to use those variables in clickProfile() and clickPlace() functions. Going forward I will have a lot of values like placeid, profileid, contentid etc and I want to avoid those declaring as static String at the beginning. Instead I want to use the Maps concept here going forward and want to use it from framework Utility.
I am new to HashMaps. Can someone help me here in implementing the Maps concept here?
public static String placeid;
public static String profileid;
public void extractplaceId()
{
placeid = getJsonPath("results.place_id");
System.out.println(placeid);
}
public void extractpleId()
{
profileid = getJsonPath("results.profile_id");
System.out.println(profileid);
}
public Response clickProfile() throws IOException
{
config.setProperty("APIendPoints.properties");
PROFILE_URL = config.getConfig().getProperty("CLICK_PROFILE") + profileid + ".json";
response = requestSpec.when().get(PROFILE_URL);
return response;
}
public Response clickPlace() throws IOException
{
config.setProperty("APIendPoints.properties");
PLACE_URL = config.getConfig().getProperty("CLICK_PLACE") + placeid + ".json";
response = requestSpec.when().get(PLACE_URL);
return response;
}
Framework Utility:
public String getJsonPath(String key)
{
String resp = response.asString();
JsonPath js = new JsonPath(resp);
return js.get(key).toString();
}
I assume that you want something like a pack of all variables that you want to save and retrieve later. My POC below just work correctly for single thread, not sure about multiple threads.
extract
orextractAndSave
Because I want my map can save any object, so that I use
Map<String,Object>
. It requires casting to get value from the map, likeint key2_number = (Integer) ExtractUtils.extractFrom(res, "data.key2.number");