I’m writing a performance test with the following steps :
- Upload a file, and from the response save the “fileID” in a separate JSON file to be used later to download the file
- Download the file by feeding the JSON created in the previous step as RawFileBody as body of the request and passing it in the download url
Both these have to be run in a sequence one after the other
Code as follows :
val uploadFile: ChainBuilder = exec(http("Upload a File to be downloaded later")
.post("/file") // end-point to be load tested
.header("username", "abc") // user-name header
.header("password", "xyz") // password header
.formUpload("file", testFile1MB) // body params ("key" , "path of the file/name")
.formParamSeq(Seq(("uploadByID", "1"), ("location", "meetings"), ("personID", "0"), (
"uploadTimeStamp", "2019-01-15 10:01:04.426"), ("md5Hash", md5Hash1Mb))) // other body params ("key", "value")
.check(status.is(200)) // check assertion for status code
.check(jsonPath("$.fileID").saveAs("guid")))
.exec { session =>
fileGuid = session("guid").as[String].trim
if (downlGuidJsonFile.exists()) {
downlGuidJsonFile.delete()
}
val guidWriter = new PrintWriter(new FileOutputStream(new File(downloadGuidFilePath), true))
guidWriter.write("{" + "\"" + "uuid" + "\"" + ":" + "\"" + fileGuid + "\"" + "}")
guidWriter.write("\n")
guidWriter.close()
session
}