模拟连接器会抛出类似 Element not defined in Mule Registry 的错误

Mocking a connector throws error like Element not defined in Mule Registery

我正在创建 Munit 测试并为查询模拟 salesforce 连接器。流中的查询响应 returns 有效负载 application/java 类型。所以下面是模拟设置

<munit:test name="salesforce-sys-implementation-test-suite-salesforce-Quote-create-flowTest" doc:id="40f70f6a-3453-4a8b-9ed8-673e4796c0be" description="Test">
    <munit:behavior>
        <munit-tools:mock-when doc:name="Mock when" doc:id="5bfeb53b-2da1-45f9-bad3-67cf4d658fc2" processor="salesforce:query">
            <munit-tools:with-attributes >
                <munit-tools:with-attribute whereValue="Query Existing Quote" attributeName="doc:name" />
                <munit-tools:with-attribute whereValue="19c396a3-8656-4600-beba-9e011e78d2b4" attributeName="doc:id" />
            </munit-tools:with-attributes>
            <munit-tools:then-return >
                <munit-tools:payload value="[{Product_Description__c=false, Shipment_Schedule__c=false, Executive_Summary_checkbox__c=false, type=Quote, Milestones_checkbox__c=false, Terms_and_Conditions__c=true, Timeline_Tool__c=false, Signature__c=false, Executive_Summary__c=null, Quote_Sent_To__r=null, Contact_Information__c=true, Gantt_Chart__c=false, Animal_Health_Policy__c=true, Opportunity={RecordTypeId=012U0000000QtmpIAC, Id=null, type=Opportunity}, Materials_and_Pricing__c=false, Cancelation_Policy__c=true, To_accept_this_statement_of_work__c=true, Customer_Signature__c=false, Id=0Q02D0000005vu7SAA, Fees_and_Invoicing__c=true}]" mediaType="application/java" encoding="UTF-8" />
            </munit-tools:then-return>          
    </munit:behavior>
    <munit:execution>
        <munit:set-event doc:name="Set Event" doc:id="b09dba54-76cc-401b-85aa-5657849861c4">
            <munit:payload value="#[MunitTools::getResourceAsString('samples/quote.json')]" encoding="UTF-8" mediaType="application/json" />
        </munit:set-event>
        <flow-ref doc:name="Flow Reference" doc:id="875fa5b7-290d-4d3f-abfe-3098bf6c7ce1" name="salesforce-Quote-create-flow"/>
    </munit:execution>
    <munit:validation >
        <set-variable value="#[output application/json --- readUrl('classpath://samples/quoteResponse.json', 'application/json')]" doc:name="Set Variable" doc:id="6fd61167-5025-4da3-8277-c9303ba9da57" variableName="expectedPayload"/>
        <munit-tools:assert-that doc:name="Assert that Not Null Response" doc:id="dc4d4008-83bd-4da6-8773-fc4aa0285d0c" is="#[MunitTools::notNullValue()]" expression="#[vars.expectedPayload.Id]"/>
    </munit:validation>
</munit:test>

当我运行测试

时它抛出错误
Element '[{Product_Description__c=false,....., Opportunity={RecordTypeId=012U0000000QtmpIAC, Id=null, type=Opportunity}}]' is not defined in the Mule Registry

如何在 Mock 上设置响应负载,这里是 Query 响应是哪个应用程序 /java 类型

您似乎错过了值括号前的 #,表示它是一个表达式。我猜想在不考虑表达式的情况下,MUnit 会尝试使用该值作为文字 id 在 Mule Registry 中进行搜索,但这不是您需要关心的事情。只需添加缺少的 # 并重试。

示例:

<munit-tools:payload value="#[output application/java
 --- {Product_Description__c:false,...}]" />