Set Inbound Properties for MUnit Flow Reference in Mulesoft for APIKit

ぃ、小莉子 提交于 2019-12-11 00:08:10

问题


I'm trying to test APIKit in MUnit. Originally I was using an http request within MUnit to call my flow and then APIKit would route the request to the proper subflow where my logic lives. Now I want to mock one of the elements of the subflow, so I'm trying to replace the http request with a reference to the APIKit flow. This works, but the APIKit router throws an error:

Cannot resolve request base path

Because none of the inbound properties are set. And this is my problem, how do I mimic the inbound properties that I send to a flow reference so that the request looks like it came from an HTTP request? Alternatively, is there another way I can structure the code so that I can mock an element of my logic?

Thanks


回答1:


You can add properties on your mock http response. See sample below:

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

Hope this helps




回答2:


You can use set message processor before fow reference to set payload and properties. Please refer following code

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

Also check this for more details. Same way you can configure mock also. Hope this helps..



来源:https://stackoverflow.com/questions/37307478/set-inbound-properties-for-munit-flow-reference-in-mulesoft-for-apikit

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