我正试着用APIKit测试MUnit。最初,我在MUnit中使用一个http请求来调用我的流,然后APIKit会将请求路由到逻辑所在的适当子流。现在我想模拟子流的一个元素,所以我尝试用引用APIKit流来替换http请求。这是可行的,但是APIKit路由器抛出了一个错误:
Cannot resolve request base path因为没有设置任何入站属性。这是我的问题,我如何模拟发送到流引用的入站属性,使请求看起来像来自HTTP请求?或者,还有其他方法可以构造代码,以便模拟逻辑的一个元素吗?
谢谢
发布于 2016-05-19 01:06:46
您可以在模拟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>希望这能有所帮助
发布于 2016-05-19 06:04:19
可以在流引用之前使用set消息处理器来设置有效负载和属性。请参阅以下代码
<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>还可以查看这获得更多详细信息。同样的方式,你也可以配置模拟。希望这有帮助..。
https://stackoverflow.com/questions/37307478
复制相似问题