I have the db connector in mule, which has the select query to count the number of records and the response from the database is as below:
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>
Response from the database call using logger with mel #[message.payload]
[{COUNT=1}]
In the munit implementation i am trying to mock this response and i have used the MOCK component of the MULE and below is my code:
<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>
But while executing the test case's i am getting the below exception:
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]
Could you please help me how i can mock the response. Thanks !!