0

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=[[ { &quot;protocol&quot;:&quot;http&quot;, &quot;host&quot;:&quot;0.0.0.0&quot;, &quot;port&quot;:&quot;8085&quot;, &quot;path&quot;:&quot;&quot;, &quot;operation&quot;:&quot;GET&quot; }, { &quot;protocol&quot;:&quot;https&quot;, &quot;host&quot;:&quot;0.0.0.0&quot;, &quot;port&quot;:&quot;8086&quot;, &quot;path&quot;:&quot;&quot;, &quot;operation&quot;:&quot;post&quot; } ]]]}"/>
        </munit:inbound-properties>
    </munit:set>
    <flow-ref name="httpInboundFlow" doc:name="httpInboundFlow"/>
    <munit:assert-on-equals expectedValue="[ { &quot;protocol&quot;:&quot;http&quot;, &quot;host&quot;:&quot;0.0.0.0&quot;, &quot;port&quot;:&quot;8085&quot;, &quot;path&quot;:&quot;&quot;, &quot;operation&quot;:&quot;GET&quot; }, { &quot;protocol&quot;:&quot;https&quot;, &quot;host&quot;:&quot;0.0.0.0&quot;, &quot;port&quot;:&quot;8086&quot;, &quot;path&quot;:&quot;&quot;, &quot;operation&quot;:&quot;post&quot; } ]" 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.

a.cayzer
  • 289
  • 4
  • 22
  • post your actual url? – star Jun 22 '16 at 10:59
  • I'm not using one during the test? When I run the main flow I use http://localhost:8081/?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" } ] – a.cayzer Jun 22 '16 at 11:10

1 Answers1

0

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.

David Whitehurst
  • 352
  • 4
  • 21
  • I don't think it's that because if I run the project and use postman to send the request it decodes it fine. I think it is something more specific with MUnit. I think it is maybe that messages can't be processed in a MUnit test because it is more functional than unit testing? perhaps I'm way off but that's how it seems – a.cayzer Jun 23 '16 at 08:24