WSO2:7.0.0
WSO2 MI:1.1.0
我已经定义了与Validation Mediator进行序列测试的单元测试套件。验证者介体使用注册表中的json模式(conf:schema / PostQuestionsJSONSchema.json):
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="ValidateUpdateQuestion" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<validate cache-schema="true">
<schema key="conf:schema/PostQuestionsJSONSchema.json"/>
<on-fail>
<propertyGroup description="Set Error Info">
<property name="httpErrorCode" scope="default" type="STRING" value="400"/>
<property name="httpErrorMessage" scope="default" type="STRING" value="Bad Request"/>
</propertyGroup>
<sequence key="DefaultFaultHandler"/>
</on-fail>
</validate>
</sequence>
在单元测试套件中,我定义了注册表资源(PostQuestionsJSONSchema.json):
<unit-test>
<artifacts>
<test-artifact>
<artifact>/TestProject/src/main/synapse-config/sequences/ValidateUpdateQuestion.xml</artifact>
</test-artifact>
<supportive-artifacts>
<artifact>/TestProject/src/main/synapse-config/sequences/DefaultFaultHandler.xml</artifact>
</supportive-artifacts>
<registry-resources>
<registry-resource>
<file-name>PostQuestionsJSONSchema.json</file-name>
<artifact>\TestProjectRegistry\PostQuestionsJSONSchema.json</artifact>
<registry-path>/_system/config/schema</registry-path>
<media-type>application/json</media-type>
</registry-resource>
</registry-resources>
<connector-resources/>
</artifacts>
<test-cases>
<test-case name="valid">
<input>
<payload><![CDATA[<body></body>]]></payload>
<properties>
<property name="Content-Type" scope="transport" value="application/json"/>
</properties>
</input>
<assertions>
<assertNotNull>
<actual>$body</actual>
<message>Body is NULL</message>
</assertNotNull>
</assertions>
</test-case>
</test-cases>
<mock-services/>
</unit-test>
但是当我开始测试时,我有:
[INFO] +-------------------+----------------+---------------+---------------+
[INFO] | TEST CASE | DEPLOYMENT | MEDIATION | ASSERTION |
[INFO] +===================+================+===============+===============+
[INFO] | Test Case - Suite | PASSED | FAILED | SKIPPED |
[INFO] +-------------------+----------------+---------------+---------------+
[INFO]
[INFO] Failed Test Case(s):
[INFO] +-------------------+-------------------+-------------------------------------------------------------------------------------------+
[INFO] | TEST CASE | FAILURE STATE | EXCEPTION / ERROR MESSAGE |
[INFO] +===================+===================+===========================================================================================+
[INFO] | Test Case - valid | MEDIATION | No Schema is available with the key : conf:schema/PostQuestionsJSONSchema.json |
[INFO] | | | org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:413) |
如何为单元测试套件定义正确的注册表资源?
答案 0 :(得分:0)
您是否在最新的WSO2 MI 1.2.0运行时中尝试了此操作?他们为单元测试框架做了一些修复。它为我提供了具有注册表和连接器资源的单元测试套件。