Parameterize Assertion HTTP Header Values in Script Assertion?
Hey!
Ok - I queried the forum to find posts about asserting the values on HTTP headers using script assertions and found yet more code nmrao had put together to assert on custom header values
//all Rao's work def expectedHTTPResponse = ['HTTP/1.1 200 OK'] def headers = messageExchange.response.responseHeaders def actualHTTPResponse = headers['#status#'] assert expectedHTTPResponse == actualHTTPResponse
I am trying to assert a couple of custom headers have the appropriate values - but I want to parameterize the values if possible.
I have a GET request with the following URI:
/api/1/{namespace}/{dataset}?_format=csv
I have a Content-Disposition header with the following expected value
attachment; {namespace}_{dataset}.csv
So for my request
GET --> /api/1/authorised-establishments/sector?_format=csv
I'm expecting the Content-Disposition header will display
attachment; authorised-establishments_sector.csv
I am trying to use the script assertion Rao put together to parameterize the header value - but it's not working
I tried the following:
def expectedHTTPResponse = ['attachment; filename='${REST Request#namespace}'_'${REST Request#dataset}'.csv'] def headers = messageExchange.response.responseHeaders def actualHTTPResponse = headers['Content-Disposition'] assert expectedHTTPResponse == actualHTTPResponse
and I also tried several variations using the 'context.expand' as follows:
def expectedHTTPResponse = ['attachment; filename=context.expand( '${REST Request#namespace}' )_context.expand( '${REST Request#dataset}' ).csv'] def headers = messageExchange.response.responseHeaders def actualHTTPResponse = headers['Content-Disposition'] assert expectedHTTPResponse == actualHTTPResponse
Would anyone be able to point me in the right direction as to how I can successfully parameterize this script assertion?
I think I can see why its not working - but I don't know how to fix it.
Thanks to all!
richie :)
- richie,
What does below shows if you add at the start of the script?
def ns = context.expand('${REST Request#namespace}')
def ds = context.expand('${REST Request#dataset}')
def value = "attachment; ${ns}_${ds}.csv" as String
log.info value