在Mulesoft中为APIKit设置MUnit流参考的入站属性

时间:2016-05-18 18:27:32

标签: mule mule-studio anypoint-studio munit

我试图在MUnit中测试APIKit。最初我在MUnit中使用http请求来调用我的流,然后APIKit将请求路由到我的逻辑所在的正确子流。现在我想模拟子流的一个元素,所以我试图用对APIKit流的引用来替换http请求。这可行,但APIKit路由器抛出错误:

Cannot resolve request base path

因为没有设置任何入站属性。这是我的问题,我如何模仿我发送到流参考的入站属性,以便请求看起来像来自HTTP请求?或者,是否有另一种方法可以构造代码,以便我可以模拟逻辑的一个元素?

由于

2 个答案:

答案 0 :(得分:8)

您可以在模拟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>

希望这有帮助

答案 1 :(得分:2)

您可以在fow引用之前使用set message processor来设置有效负载和属性。请参考以下代码

    <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了解详情。 同样的方法你也可以配置mock。 希望这会有所帮助..

相关问题