如何为使用通用 HTTP 请求连接器调用系统层的 5 个不同资源的集成编写 Munit 测试用例?

How to write a Munit test case for an integration that is using a common HTTP request connector for calling 5 different resources of the system layer?

我从进程层调用一个系统层作为

首先得到:/abc 得到:/xyz post: /efg 通过在调用此 http 请求程序之前设置路径、方法和主机,使用通用 http 请求程序对所有这 3 个调用进行调用。

如何为每个给我不同响应的调用模拟此 http 请求程序?

您只需将 3 个 mock when's 添加到您的 Munit。他们每个人都有处理器 'http:request',但具有特定于调用的属性。因此,在每个模拟中,您将提供 AttributeName="method" 和 AttributeName="path",其中值对应于您要模拟的特定调用。请参阅下面的两个模拟示例。

<munit-tools:mock-when doc:name="Mock when POST" doc:id="8e3b66fe-b5bb-4f96-97b5-8970c1635b12" processor="http:request">
    <munit-tools:with-attributes >
        <munit-tools:with-attribute whereValue="POST" attributeName="method" />
        <munit-tools:with-attribute whereValue="/post" attributeName="path" />
    </munit-tools:with-attributes>
    <munit-tools:then-return >
        <munit-tools:payload value='#[{"data": "post"}]' mediaType="application/json" />
    </munit-tools:then-return>
</munit-tools:mock-when>
<munit-tools:mock-when doc:name="Mock when GET" doc:id="4797dd50-8bc2-428a-9aba-7d03692fc1a2" processor="http:request" >
    <munit-tools:with-attributes >
        <munit-tools:with-attribute whereValue="GET" attributeName="method" />
        <munit-tools:with-attribute whereValue="/get" attributeName="path" />
    </munit-tools:with-attributes>
    <munit-tools:then-return >
        <munit-tools:payload value='#[{"data": "get"}]' mediaType="application/json" />
    </munit-tools:then-return>
</munit-tools:mock-when>