在MUnit测试期间将有效负载设置为http.query.params.variable_name [英] Setting payload to http.query.params.variable_name during an MUnit test

查看:83
本文介绍了在MUnit测试期间将有效负载设置为http.query.params.variable_name的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置MUnit测试,以确认设置的有效负载方法将有效负载设置为正确的值.我正在通过HTTP端点发送JSON文件.

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.

在运行流时,通常将有效负载设置为:
#[message.inboundproperties.'http.query.params'.json]
工作正常,但是当我运行测试时,断言等于失败.

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.

我正在使用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:","操作:"发布}]]]}

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" } ]]]}

我的主要流程是:

<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>

我的测试xml是:

<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.

推荐答案

看看RFC 1738统一资源定位符- https://www.ietf.org/rfc/rfc1738.txt

Take a look at RFC 1738 Uniform Resource Locators - https://www.ietf.org/rfc/rfc1738.txt

您应该对花括号和方括号进行编码. JSON作为http参数有点奇怪,除非它是1或2个名称/值对.我希望您需要在网址中使用代码,例如本地主机:8081/?json =%5B%7B%22protocol ...

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 ...

尝试对URL进行编码,然后告知我们.

Try encoding the URL and let us know.

这篇关于在MUnit测试期间将有效负载设置为http.query.params.variable_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆