Setting payload to http.query.params.variable_name during an MUnit test

ⅰ亾dé卋堺 提交于 2019-12-12 00:08:48

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37964654/setting-payload-to-http-query-params-variable-name-during-an-munit-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!