【问题标题】:Set Inbound Properties for MUnit Flow Reference in Mulesoft for APIKit在 Mulesoft for APIKit 中为 MUnit 流参考设置入站属性
【发布时间】:2016-09-15 09:42:26
【问题描述】:
我正在尝试在 MUnit 中测试 APIKit。最初我在 MUnit 中使用 http 请求来调用我的流程,然后 APIKit 会将请求路由到我的逻辑所在的正确子流程。现在我想模拟子流的元素之一,所以我试图用对 APIKit 流的引用替换 http 请求。这可行,但 APIKit 路由器会引发错误:
Cannot resolve request base path
因为没有设置任何入站属性。这是我的问题,我如何模仿我发送到流引用的入站属性,以使请求看起来像是来自 HTTP 请求?或者,是否有另一种方法可以构建代码以便模拟我的逻辑元素?
谢谢
【问题讨论】:
标签:
mule
mule-studio
anypoint-studio
munit
【解决方案1】:
您可以在模拟 http 响应中添加属性。请参阅下面的示例:
<mock:when messageProcessor=".*:.*" doc:name="Queue Message">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Queue Message']"/>
</mock:with-attributes>
<mock:then-return payload="#['Sample response']">
<mock:inbound-properties>
<mock:inbound-property key="prop1" value="val1"/>
<mock:inbound-property key="prop2" value="val2"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
希望对你有帮助
【解决方案2】:
您可以在流引用之前使用设置消息处理器来设置有效负载和属性。请参考以下代码
<munit:before-suite name="twitter_munit_testBefore_Suite" description="MUnit Test">
<scripting:component doc:name="Script">
<scripting:script name="groovyScriptPayloadGenerator" engine="Groovy"><![CDATA[
import groovy.json.JsonSlurper
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText '''
{ "positive": 15,
"negative": 5,
"neutral": 0
}''']]></scripting:script>
</scripting:component>
</munit:before-suite>
<munit:test name="new-test-suite-tetsFlowTest" description="Test">
<munit:set payload="#[resultOfScript('groovyScriptPayloadGenerator')]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params" value="#[['query':'value']]"/>
</munit:inbound-properties>
</munit:set>
<flow-ref name="tetsFlow" doc:name="Flow-ref to tetsFlow"/>
</munit:test>
请查看this 了解更多详情。
同样的方式你也可以配置模拟。
希望这会有所帮助..