I am trying to test a feature that sends an excel file (.xlsx) through a REST response. I already tried the endpoint using postman and I know that the excel is downloaded (so it works) but still I can't make the test work.
This is what I have tried so far (using wslite to read the response in the test):
@Subject(ExcelController)
class ExcelFuncSpec {
RESTClient http
void setup() {
http = new RESTClient("http://localhost:33089")
}
void "It generates an excel"() {
given:
int randomId = 23
when:
def res = http.get([
path : "/$randomId/excel",
])
then: "The response is OK"
res?.statusCode == OK.value()
res.response.data //this kinda works because it returns an array of bytes
}
}
As you can see in my comment:
res.response.data //this kinda works because it returns an array of bytes
I can get an array of bytes but what I need is a java File or InputStream that I can use to read the content of the excel file.
¿How can I get the response as an InputStream using wslite?
I can get an array of bytes but what I need is a java File or InputStream that I can use to read the content of the excel file.
If res.response.data
evalutes to the array of bytes and you want an InputStream
associated with those bytes then new ByteArrayInputStream(res.response.data)
will create an InputStream
from which you can read those bytes.