Using Mule 4 and have a GET endpoint : getEmployee
The API I am trying to MUNIT is an experience api and its expected response is :
{
"correlationId": correlationId ( Mule correlation id ),
"empDetails" : {
"ename": "John",
"eid": "100"
}
}
In the above response, data received from process api is set against empDetails
.The experience api is adding correlationId in response.
The problem I am encountering is when trying to Munit this endpoint . I am mocking the process api response
So the mocked response is a static json file :
{
"ename": "John",
"eid": "100"
}
Once this mocked response ( from process api ) is received back in experience api , we append correlation id before sending response back.
So in My Munit I am trying to compare results from runtime with a static response from a json file. My static response in json file is as below :
{
"correlationId": "abcd",
"empDetails" : {
"ename": "John",
"eid": "100"
}
}
Notice that above in static json file the correlation id is expected to be abcd
So in my munit I am trying to set correlation id with abcd
:
<munit:set-event doc:name="Set Event">
<munit:attributes value="#[{ method : 'GET', requestPath: '/employee', headers : { 'X-
CORRELATION-ID' : 'abcd'}}]" />
...
...
However inspite of setting the correlationid header value to a fixed static value abcd
, mule runtime is dynamically generating the value and as a result rather than having abcd
in response we are getting a dynamic value causing munit to fail ...
Note - when I run the api and invoke this endpoint via postman , then whatever value i send in header X-Correlation-Id
is being set against correlationid ( expected behaviour )
However in case of munit this is not happening .
I think the difference between the two is - in actual run - the HTTP listener is invoked Vs in case of Munit the specific flow is being tested ( after http listener and api kit router ) , so I am suspecting this is why mule is already setting correlation id in case of munit.
So really I need some way to control the value of correlationid in Munit , how do we achieve the same ?