0

我在 Anypoint 平台上有一个 API,它的重要规格是:

  1. http方案
  2. 请求端点=“检索信息”
  3. queryParams = {"key": "value", isAllow: true}

我使用具有上述规格的 RAML v1.0 构建了 Mule 流程,并且所有功能都运行良好。现在,我正在尝试为 mule 流开发 mUnit。对于测试用例,我设置了以下事件并将 flowReference 调用到 Mule 流。

#[{
    headers: {
        'client_space': 'ABCD-1234',
        'client_code': 'XYZ-0001'
    },
    'queryParams': {
        'key': '12345678',
        'isAllow': true
    },
    'requestPath': '/api/retrieveInformation',
    'rawRequestPath': '/api/retrieveInformation',
    'requestUri': '',
    'listenerPath': '/api/*',
    'relativePath': '/retrieveInformation',
    'method': 'GET',
    'scheme': 'HTTP',
    'version': 'HTTP/1.1',
    'localAddress': '/127.0.0.1:8091',
    'remoteAddress': ''
} as Object {
    class: 'org.mule.extension.http.api.HttpRequestAttributes' 
}]

现在运行单元,APIKit:Router 抛出错误,即不能将大小写从布尔值转换为字符串。如果我更改为“'isAllow': 'true'”,那么 APIKit:Router 会抛出有效错误 APIKIT:NOT_IMPLEMENTED。

谁能帮助如何在不更改 API 规范的情况下实现这种情况?

4

1 回答 1

1

连接器 ( ) 中的内部类class: 'org.mule.extension.http.api.HttpRequestAttributes'并不意味着直接在测试中使用。这不是实施测试的好主意。最好尝试解决您最初在创建测试时遇到的错误。请务必使用最新版本的 Studio。

API 可能有问题。如果仍然失败,您可以为更简单的 API 创建一个测试套件,然后将其用作示例,说明如何使用 HTTP 请求器手动构建测试用例,而不是尝试模拟请求。例子:

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd ">
    <munit:config name="simple-api-spec-apikit-test.xml" />
    <http:request-config name="HTTP_Request_Configuration" basePath="/api">
        <http:request-connection host="localhost" port="8081" />
    </http:request-config>
    <munit:test name="get:\ping:simple-api-spec-config-200-application\json-FlowTest" description="Verifying functionality of [get:\ping:simple-api-spec-config-200-application\json]">
        <munit:enable-flow-sources>
            <munit:enable-flow-source value="simple-api-spec-main" />
            <munit:enable-flow-source value="get:\ping:simple-api-spec-config" />
        </munit:enable-flow-sources>
        <munit:execution>
            <http:request config-ref="HTTP_Request_Configuration" method="GET" path="/ping">
                <http:headers>#[{"Accept":"application/json"}]</http:headers>
            </http:request>
        </munit:execution>
        <munit:validation>
            <munit-tools:assert-that expression="#[attributes.statusCode]" is="#[MunitTools::equalTo(200)]" message="The HTTP Status code is not correct!" doc:name="Assert That Status Code is 200" />
            <munit-tools:assert-that expression="#[output application/java ---write(payload, 'application/json') as String]" is="#[MunitTools::equalTo(MunitTools::getResourceAsString('scaffolder/response/get_200_ping_application_json.json'))]" message="The response payload is not correct!" doc:name="Assert That - Payload is Expected" />
        </munit:validation>
    </munit:test>
</mule>
于 2021-10-05T15:35:23.803 回答