在munit中设置parametermap

时间:2018-11-27 10:19:35

标签: mule munit

am难以在munit中设置ParameterMap。当我在munit中设置http.uri.params并正常工作时。但无法通过ParameterMap访问其值。请参考以下MUnit代码(当我访问#[message.inboundProperties.'http.uri.params'.serviceName]时运行良好)和Java代码

try{
    var gamer = '';//variable to capture json data
    var options = {
        uri: 'http://localhost:4000/gamers/'+gamer._id+'/find',
        json: true
    };

    RequestPromise(options)
        .then(function (data) {
            gamer = data;//capturing response 
            // here is the rigth place perofrm operations on the answer, as this part of the code gets executed after promise reolves. BTW. Then you don't need variable gamer.
        })
        .catch(function (err) {
            console.log("Error saving player data !");
        });
    // here is not the right place to do something with gamer as this is executed as soon as promise is initialized, not as it resolves. This means your variable will have initial value here
}catch(err){
    res.status(500).send({
            message: err.message || 'An error occurred generating player teams !'
    });
}

这就是我在我的代码中访问http.uri.params的方式

<munit:inbound-property key="http.uri.params" value="#[['serviceName': 'services','loanNumber':'1111']]"/>

因此,当我运行munit时,以上行会引发异常(java.util.HashMap无法转换为org.mule.module.http.internal.ParameterMap)

有什么方法可以在不更改我的代码的情况下在munit中设置参数映射?

1 个答案:

答案 0 :(得分:0)

如果您确实无法更改代码以不依赖ParameterMap。然后,您可以尝试在Munit代码中创建ParameterMap实例。它有一个重叠的构造函数,可以将映射传递给它:

<munit:inbound-property key="http.uri.params" value="#[new org.mule.module.http.internal.ParameterMap((['serviceName': 'services','loanNumber':'1111']))]"/>

Java文档:https://www.mulesoft.org/docs/site/3.7.0/apidocs/org/mule/module/http/internal/ParameterMap.html