如何让 MUnit 数据库服务器从 CSV 文件创建 table
How to get MUnit DB Server to create table from CSV file
尝试使用 MUnit 的数据库服务器通过 CSV 文件模拟数据库 table。
问题是我收到 table not found 错误。
我正在关注这两篇文章:
- https://docs.mulesoft.com/munit/2.2/db-util
- https://help.mulesoft.com/s/article/How-to-use-Munit-2-x-and-mock-a-DB-server-in-Mule4
运行 help.mulesoft.com 文章中的示例出现了同样的错误。
如何让 MUnit 数据库服务器从 CSV 文件创建 table?
这里是测试和配置
<dbserver:config name="MUnit_DB_Server_Config" doc:name="MUnit DB Server Config" doc:id="c861f371-037e-4c90-92ab-d8affc693bb6" >
<dbserver:connection csv="EP0001F1.csv" database="DEV" connectionStringParameters="MODE=DB2" />
</dbserver:config>
<db:config name="Test_Database_Config" doc:name="Database Config" doc:id="7b8b820d-f517-498e-8d3c-92ee7a09fe35" >
<db:generic-connection url="${db.url}" driverClassName="${db.driver}" />
</db:config>
<munit:test name="get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config-200-application\json-FlowTest" description="Verifying functionality of [get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config-200-application\json]">
<munit:enable-flow-sources>
<munit:enable-flow-source value="associate-workforce-link-sapi-main" />
<munit:enable-flow-source value="get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config" />
</munit:enable-flow-sources>
<munit:behavior>
<set-variable variableName="country" value="#['US']" doc:name="country" />
</munit:behavior>
<munit:execution>
<http:request config-ref="HTTP_Request_Configuration" method="GET" path="#['/$(vars.country)/associates/workforce/links']" responseTimeout="30000">
<http:headers><![CDATA[#[{"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_{country}_associates_workforce_links_application_json.json'))]" message="The response payload is not correct!" doc:name="Assert That - Payload is Expected" />
</munit:validation>
</munit:test>
属性
db:
url: "jdbc:h2:mem:DEV;DB_CLOSE_DELAY=-1"
driver: "org.h2.Driver"
db-config:
name: "Test_Database_Config"
我得到的错误是
ERROR 2019-12-26 09:58:48,394 [[MuleRuntime].io.09: [associate-workforce-link-sapi].GetLinks.BLOCKING @4d5314c4] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : Table "EP0001F1" not found; SQL statement:
select * from EP0001F1 order by EPDRC desc [42102-166].
Error type : DB:QUERY_EXECUTION
Element : GetLinks/processors/1 @ associate-workforce-link-sapi:implementation.xml:11 (Select)
Element XML : <db:select doc:name="Select" doc:id="9b7e9a39-10bf-44ca-a7af-eaa5b0189ece" config-ref="${db-config.name}" maxRows="100">
<db:sql>select * from EP0001F1 order by EPDRC desc</db:sql>
</db:select>
CSV 文件被复制到 test-类 文件夹
而且我知道正在使用 h2 驱动程序(而不是实际驱动程序),因为异常原因来自 org.h2.jdbc。
你是 运行 Mule 4.2.2 吗? 运行 时间的那个补丁版本中有一个问题导致了这个问题。如果你运行你的测试与 Mule 4.2.1 它应该工作,你可以改变 mule-artificat.json 要求 4.2.1 作为 minMuleVersion 并且在 MUnit 运行 配置中也设置运行时间版本为4.2.1。其余的似乎都是正确的。
尝试使用 MUnit 的数据库服务器通过 CSV 文件模拟数据库 table。 问题是我收到 table not found 错误。
我正在关注这两篇文章:
- https://docs.mulesoft.com/munit/2.2/db-util
- https://help.mulesoft.com/s/article/How-to-use-Munit-2-x-and-mock-a-DB-server-in-Mule4
运行 help.mulesoft.com 文章中的示例出现了同样的错误。
如何让 MUnit 数据库服务器从 CSV 文件创建 table?
这里是测试和配置
<dbserver:config name="MUnit_DB_Server_Config" doc:name="MUnit DB Server Config" doc:id="c861f371-037e-4c90-92ab-d8affc693bb6" >
<dbserver:connection csv="EP0001F1.csv" database="DEV" connectionStringParameters="MODE=DB2" />
</dbserver:config>
<db:config name="Test_Database_Config" doc:name="Database Config" doc:id="7b8b820d-f517-498e-8d3c-92ee7a09fe35" >
<db:generic-connection url="${db.url}" driverClassName="${db.driver}" />
</db:config>
<munit:test name="get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config-200-application\json-FlowTest" description="Verifying functionality of [get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config-200-application\json]">
<munit:enable-flow-sources>
<munit:enable-flow-source value="associate-workforce-link-sapi-main" />
<munit:enable-flow-source value="get:\(country)\associates\workforce\links:associate-workforce-link-sapi-config" />
</munit:enable-flow-sources>
<munit:behavior>
<set-variable variableName="country" value="#['US']" doc:name="country" />
</munit:behavior>
<munit:execution>
<http:request config-ref="HTTP_Request_Configuration" method="GET" path="#['/$(vars.country)/associates/workforce/links']" responseTimeout="30000">
<http:headers><![CDATA[#[{"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_{country}_associates_workforce_links_application_json.json'))]" message="The response payload is not correct!" doc:name="Assert That - Payload is Expected" />
</munit:validation>
</munit:test>
属性
db:
url: "jdbc:h2:mem:DEV;DB_CLOSE_DELAY=-1"
driver: "org.h2.Driver"
db-config:
name: "Test_Database_Config"
我得到的错误是
ERROR 2019-12-26 09:58:48,394 [[MuleRuntime].io.09: [associate-workforce-link-sapi].GetLinks.BLOCKING @4d5314c4] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message : Table "EP0001F1" not found; SQL statement:
select * from EP0001F1 order by EPDRC desc [42102-166].
Error type : DB:QUERY_EXECUTION
Element : GetLinks/processors/1 @ associate-workforce-link-sapi:implementation.xml:11 (Select)
Element XML : <db:select doc:name="Select" doc:id="9b7e9a39-10bf-44ca-a7af-eaa5b0189ece" config-ref="${db-config.name}" maxRows="100">
<db:sql>select * from EP0001F1 order by EPDRC desc</db:sql>
</db:select>
CSV 文件被复制到 test-类 文件夹
而且我知道正在使用 h2 驱动程序(而不是实际驱动程序),因为异常原因来自 org.h2.jdbc。
你是 运行 Mule 4.2.2 吗? 运行 时间的那个补丁版本中有一个问题导致了这个问题。如果你运行你的测试与 Mule 4.2.1 它应该工作,你可以改变 mule-artificat.json 要求 4.2.1 作为 minMuleVersion 并且在 MUnit 运行 配置中也设置运行时间版本为4.2.1。其余的似乎都是正确的。