使用mule在模拟活动中模拟数据库计数查询响应时遇到问题

问题描述 投票:0回答:1

我有mule中的db连接器,它有select查询来计算记录数,数据库的响应如下:

MULE CODE SNIPPET:

     <db:select config-ref="Oracle_Configuration" doc:name="FetchDetails">
            <db:parameterized-query><![CDATA[SELECT COUNT(1) AS COUNT from MAPPER_T where ST_NO=#[flowVars.fetchNO] and DATE=SYSDATE]]></db:parameterized-query>
        </db:select>

 <choice doc:name="EvaluateCount">
            <when expression="#[payload[0]['COUNT'] == 0]">
           <logger message="#[payload]" level="INFO" category="DO SOMETHING X" doc:name="Logger"/>
            </when>
 <otherwise>
                    <logger message="#[payload]" level="INFO" category="DO SOMETHING Y" doc:name="Logger"/>
            </otherwise>
        </choice>

使用带有mel#[message.payload]的记录器来响应数据库调用

[{COUNT=1}]

在munit实现中我试图模拟这个响应,我使用了MULE的MOCK组件,下面是我的代码:

 <munit:test name="api-Happy-Scenario-test-suiteTest" description="MUnit Test">
  	 <mock:when messageProcessor=".*:.*" doc:name="Mock - Evaluate Results">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#['FetchDetails']"/>
            </mock:with-attributes>
            <mock:then-return payload="#[{COUNT: 0}]"/>
        </mock:when>
               <munit:set payload="#[getResource('json/ResultsRequest.json').asString()]" mimeType="application/json" doc:name="Set Message">
	</munit:set>
        <flow-ref name="post:/results:api-config" doc:name="InvokeResultsService"/>
        <munit:assert-true message="The HTTP Status code is not correct!" condition="#[messageInboundProperty('http.status').is(eq(201))]" doc:name="assert that - http.status eq 201"/>
        <munit:assert-null doc:name="Assert Null Payload"/>
    </munit:test>

但在执行测试用例时,我得到以下异常:

Caused by: org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "payload[0]['COUNT']" failed.
Caused by: [Error: java.lang.Character cannot be cast to java.lang.Class]
[Near : {... payload[0]['COUNT'] ....}]
             ^
[Line: 1, Column: 1]

你能帮我解释一下如何模仿回应。谢谢 !!

mule mule-component mule-el munit
1个回答
0
投票

您在mock:then-return中的语法无效。

你错过了几件事:

  1. 缺少开始MEL表达的井号。你应该有这样的东西:#[...code goes here...]
  2. 未正确创建地图。你想要这样的东西:{COUNT: 1}

所以你的mock:then-return应该是这样的:

<mock:then-return payload="#[[{COUNT: 1}]]"/>

© www.soinside.com 2019 - 2024. All rights reserved.