I am trying to set up an MUnit test to confirm that the set payload method is setting the payload to the right value. I am sending in a JSON file via a HTTP endpoint.
When running the flow normally setting the payload to:
#[message.inboundproperties.'http.query.params'.json]
works fine however when I run my test the assert equals fails.
I am setting the message with http.query.params=ParameterMap{[json=[[ { "protocol":"http", "host":"0.0.0.0", "port":"8085", "path":"", "operation":"GET" }, { "protocol":"https", "host":"0.0.0.0", "port":"8086", "path":"", "operation":"post" } ]]]}
My main flow is:
<flow name="httpInboundFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value="#[message.inboundProperties.'http.query.params'.json]" doc:name="Set Payload To Query Params"/>
</flow>
My test xml is:
<munit:test name="tddmunitdemo-test-suiteTest" description="MUnit Test">
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params" value="ParameterMap{[json=[[ { "protocol":"http", "host":"0.0.0.0", "port":"8085", "path":"", "operation":"GET" }, { "protocol":"https", "host":"0.0.0.0", "port":"8086", "path":"", "operation":"post" } ]]]}"/>
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow"/>
<munit:assert-on-equals expectedValue="[ { "protocol":"http", "host":"0.0.0.0", "port":"8085", "path":"", "operation":"GET" }, { "protocol":"https", "host":"0.0.0.0", "port":"8086", "path":"", "operation":"post" } ]" actualValue="#[payload]" doc:name="Assert Equals"/>
</munit:test>
The test fails with an failure message saying that the actual value was null.
I can fix it by mocking the set payload but then I aren't checking the the set payload is working as expected.
Take a look at RFC 1738 Uniform Resource Locators - https://www.ietf.org/rfc/rfc1738.txt
You should be encoding curly braces and maybe brackets. JSON as an http parameter is a little weird unless it's maybe 1 or 2 name/value pairs. I expect that you need to use codes in the URL e.g. localhost:8081/?json=%5B%7B%22protocol ...
Try encoding the URL and let us know.