Set Inbound Properties for MUnit Flow Reference in

2019-07-14 02:40发布

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

2条回答
放我归山
2楼-- · 2019-07-14 03:10

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

查看更多
萌系小妹纸
3楼-- · 2019-07-14 03:14

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

查看更多
登录 后发表回答