我使用apikit-with-munit示例项目创建了一个项目。
我对我的项目进行了编组,现在有一个名为api.xml和1个api-test-suite.xml文件的app文件。我尝试在测试中添加数据库引用,并且在启动测试时遇到以下错误仅从Maven启动测试时。
从Anypoint Studio启动我的测试时,My MUnit工作正常。
我不知道我的配置有什么问题...我怀疑我的问题与我的命名空间有关有人能指出我做错了吗?
Failed to execute goal com.mulesoft.munit.tools:munit-maven-plugin:1.1.0:test (test) on project testing-apikit-with-munit_1.3.3-1:
Execution test of goal com.mulesoft.munit.tools:munit-maven-plugin:1.1.0:test failed: org.mule.api.config.ConfigurationException:
Configuration problem: Failed to import bean definitions from URL location [classpath:api.xml]
[错误]违规资源:网址[文件:/ C:/Workspaces/Coverage1/testing-apikit-with-munit_1.3.3-1/target/test-classes/api-test-suite.xml] ; 嵌套异常是org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源[api.xml]的XML文档中的第40行无效; 嵌套异常是org.xml.sax.SAXParseException; lineNumber:40; columnNumber:101; cvc-complex-type.2.4.a:从元素' db:oracle-config'开始发现无效内容。
One of '{"http://www.springframework.org/schema/beans":beans, "http://www.springframework.org/schema/beans":bean, "http://www.springframework.org/schema/context":property-placeholder,
"http://www.springframework.org/schema/beans":ref, "http://www.mulesoft.org/schema/mule/core":global-property, "http://www.mulesoft.org/schema/mule/core":configuration,
"http://www.mulesoft.org/schema/mule/core":notifications, "http://www.mulesoft.org/schema/mule/core":abstract-extension,
"http://www.mulesoft.org/schema/mule/core":abstract-shared-extension,
"http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-extension,
"http://www.mulesoft.org/schema/mule/core":abstract-agent, "http://www.mulesoft.org/schema/mule/core":abstract-security-manager,
"http://www.mulesoft.org/schema/mule/core":abstract-transaction-manager, "http://www.mulesoft.org/schema/mule/core":abstract-shared-transaction-manager,
"http://www.mulesoft.org/schema/mule/core":abstract-connector, "http://www.mulesoft.org/schema/mule/core":abstract-shared-connector,
"http://www.mulesoft.org/schema/mule/core":abstract-global-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-exception-strategy,
"http://www.mulesoft.org/schema/mule/core":abstract-flow-construct, "http://www.mulesoft.org/schema/mule/core":flow, "http://www.mulesoft.org/schema/mule/core":sub-flow,
"http://www.mulesoft.org/schema/mule/core":abstract-model, "http://www.mulesoft.org/schema/mule/core":abstract-interceptor-stack, "http://www.mulesoft.org/schema/mule/core":abstract-filter,
"http://www.mulesoft.org/schema/mule/core":abstract-transformer, "http://www.mulesoft.org/schema/mule/core":processor-chain, "http://www.mulesoft.org/schema/mule/core":custom-processor,
"http://www.mulesoft.org/schema/mule/core":abstract-empty-processor, "http://www.mulesoft.org/schema/mule/core":invoke,
"http://www.mulesoft.org/schema/mule/core":set-payload, "http://www.mulesoft.org/schema/mule/core":abstract-global-intercepting-message-processor,
"http://www.mulesoft.org/schema/mule/core":custom-queue-store, "http://www.mulesoft.org/schema/mule/core":abstract-processing-strategy}' is expected. (org.mule.api.lifecycle.InitialisationException)
我的api.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
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/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<apikit:config consoleEnabled="true" consolePath="console" doc:name="Router" name="api-config" raml="api.raml">
<apikit:flow-mapping action="get" flow-ref="get:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="post" flow-ref="post:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="put" flow-ref="put:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="delete" flow-ref="delete:/munit:api-config" resource="/munit"/>
</apikit:config>
<!-- Configure the data source bean -->
<spring:beans>
<spring:bean id="dbwebDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<spring:property name="url" value="jdbc:oracle:thin:@server:1111:DB"/>
<spring:property name="username" value="xxxx"/>
<spring:property name="password" value="xxxx"/>
<spring:property name="initialSize" value="1"/>
<spring:property name="maxActive" value="3"/>
</spring:bean>
</spring:beans>
<db:oracle-config name="dbweb" dataSource-ref="dbwebDataSource" doc:name="dbweb configuration"/>
<http:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="9090"/>
<apikit:mapping-exception-strategy name="api-apiKitGlobalExceptionMapping">
<apikit:mapping statusCode="404">
<apikit:exception value="org.mule.module.apikit.exception.NotFoundException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Resource not found" }"/>
</apikit:mapping>
<apikit:mapping statusCode="405">
<apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Method not allowed" }"/>
</apikit:mapping>
<apikit:mapping statusCode="415">
<apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Unsupported media type" }"/>
</apikit:mapping>
<apikit:mapping statusCode="406">
<apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Not acceptable" }"/>
</apikit:mapping>
<apikit:mapping statusCode="400">
<apikit:exception value="org.mule.module.apikit.exception.BadRequestException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Bad request" }"/>
</apikit:mapping>
</apikit:mapping-exception-strategy>
<flow name="api-main">
<http:listener config-ref="HTTP_Listener_Configuration" doc:name="HTTP" path="api/*"/>
<apikit:router config-ref="api-config" doc:name="APIkit Router"/>
<exception-strategy doc:name="Reference Exception Strategy" ref="api-apiKitGlobalExceptionMapping"/>
</flow>
<flow name="put:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['PUT RESPONSE']"/>
</flow>
<flow name="delete:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['DELETE RESPONSE']"/>
</flow>
<flow name="post:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['POST RESPONSE']"/>
</flow>
<flow name="get:/munit:api-config">
<vm:inbound-endpoint exchange-pattern="request-response" path="serviceA" doc:name="Service A"/>
<db:select config-ref="dbweb" doc:name="select items">
<db:parameterized-query><![CDATA[${sql.dbweb.select.items}]]></db:parameterized-query>
</db:select>
</flow>
我的api-test-suite.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:core="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<munit:config doc:name="Munit configuration" mock-connectors="false" mock-inbounds="false"/>
<spring:beans>
<spring:import resource="classpath:api.xml"/>
</spring:beans>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="9090" basePath="api" doc:name="HTTP Request Configuration">
</http:request-config>
<munit:test name="api-test-get" description="Test">
<munit:set payload="#['']" doc:name="Set Message"/>
<http:request config-ref="HTTP_Request_Configuration" path="/munit" method="GET" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<munit:assert-on-equals message="The HTTP Status code is not correct!" expectedValue="#[200]" actualValue="#[message.inboundProperties['http.status']]" doc:name="Assert Equals"/>
<munit:assert-payload-equals message="The response payload is not correct!" expectedValue=""GET RESPONSE"" doc:name="Assert Payload"/>
</munit:test>
<munit:test name="api-test-post" description="Test">
<munit:set payload="#['']" doc:name="Set Message"/>
<http:request config-ref="HTTP_Request_Configuration" path="/munit" method="POST" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<munit:assert-on-equals message="The HTTP Status code is not correct!" expectedValue="#[201]" actualValue="#[message.inboundProperties['http.status']]" doc:name="Assert Equals"/>
<munit:assert-payload-equals message="The response payload is not correct!" expectedValue=""POST RESPONSE"" doc:name="Assert Payload"/>
</munit:test>
<munit:test name="api-test-put" description="Test">
<munit:set payload="#['']" doc:name="Set Message"/>
<http:request config-ref="HTTP_Request_Configuration" path="/munit" method="PUT" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<munit:assert-on-equals message="The HTTP Status code is not correct!" expectedValue="#[201]" actualValue="#[message.inboundProperties['http.status']]" doc:name="Assert Equals"/>
<munit:assert-payload-equals message="The response payload is not correct!" expectedValue=""PUT RESPONSE"" doc:name="Assert Payload"/>
</munit:test>
<munit:test name="api-test-delete" description="Test">
<munit:set payload="#['']" doc:name="Set Message"/>
<http:request config-ref="HTTP_Request_Configuration" path="/munit" method="DELETE" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<munit:assert-on-equals message="The HTTP Status code is not correct!" expectedValue="#[200]" actualValue="#[message.inboundProperties['http.status']]" doc:name="Assert Equals"/>
<munit:assert-payload-equals message="The response payload is not correct!" expectedValue=""DELETE RESPONSE"" doc:name="Assert Payload"/>
</munit:test>
答案 0 :(得分:1)
我不知道您使用的是哪种版本的Mule,但我认为这是最近的版本。
通常,在运行Maven测试时与无效内容相关的所有问题都是由于缺少maven依赖。
事实上,这个模块的大部分都已提供,这意味着它们已经存在于mule中,即使它们不在您的POM中,应用程序也将在独立服务器上运行,即使已部署。 运行测试时不是这样,maven测试中使用的mule服务器是轻量级的,没有包含电池,因此您需要指定所有依赖项。
所以简短回答是你在pom上遗漏了这种依赖:
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-db</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
无论如何只是为了完整性,请不要弃用oracle配置,而应该使用通用的db配置。
<db:generic-config name="Generic_Database_Configuration" doc:name="Generic Database Configuration" url="asdasdasd"/>
无论如何,如果您仍想使用已弃用的配置,并且您正在运行Mule企业版,您还应注意,最新版本是 mule-transport-jdbc-ee 模块的一部分,因此在你的pom中你应该有这种依赖
<dependency>
<groupId>com.mulesoft.muleesb.transports</groupId>
<artifactId>mule-transport-jdbc-ee</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
并且xml conf看起来像
<jdbc-ee:oracle-data-source name="Oracle_Data_Source" password="" url="jdbc:oracle:thin:@//localhost:1521/[instanceName]" transactionIsolation="UNSPECIFIED" doc:name="Oracle Data Source"/>
希望这有帮助。
答案 1 :(得分:0)
对于基本的oracle示例:
<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
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/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<apikit:config consoleEnabled="true" consolePath="console" doc:name="Router" name="api-config" raml="api.raml">
<apikit:flow-mapping action="get" flow-ref="get:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="post" flow-ref="post:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="put" flow-ref="put:/munit:api-config" resource="/munit"/>
<apikit:flow-mapping action="delete" flow-ref="delete:/munit:api-config" resource="/munit"/>
</apikit:config>
<!-- Configure the data source bean -->
<spring:beans>
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<spring:property name="url" value="jdbc:oracle:thin:@server:1521:DBNAME"/>
<spring:property name="username" value="user"/>
<spring:property name="password" value="passwd"/>
<spring:property name="removeAbandoned" value="true"/>
<spring:property name="initialSize" value="1"/>
<spring:property name="maxActive" value="5"/>
</spring:bean>
</spring:beans>
<db:generic-config name="dbweb" dataSource-ref="dataSource" doc:name="Generic Database Configuration" />
<http:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="9090"/>
<apikit:mapping-exception-strategy name="api-apiKitGlobalExceptionMapping">
<apikit:mapping statusCode="404">
<apikit:exception value="org.mule.module.apikit.exception.NotFoundException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Resource not found" }"/>
</apikit:mapping>
<apikit:mapping statusCode="405">
<apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Method not allowed" }"/>
</apikit:mapping>
<apikit:mapping statusCode="415">
<apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Unsupported media type" }"/>
</apikit:mapping>
<apikit:mapping statusCode="406">
<apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Not acceptable" }"/>
</apikit:mapping>
<apikit:mapping statusCode="400">
<apikit:exception value="org.mule.module.apikit.exception.BadRequestException"/>
<set-property doc:name="Property" propertyName="Content-Type" value="application/json"/>
<set-payload doc:name="Set Payload" value="{ "message": "Bad request" }"/>
</apikit:mapping>
</apikit:mapping-exception-strategy>
<flow name="api-main">
<http:listener config-ref="HTTP_Listener_Configuration" doc:name="HTTP" path="api/*"/>
<apikit:router config-ref="api-config" doc:name="APIkit Router"/>
<exception-strategy doc:name="Reference Exception Strategy" ref="api-apiKitGlobalExceptionMapping"/>
</flow>
<flow name="put:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['PUT RESPONSE']"/>
</flow>
<flow name="delete:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['DELETE RESPONSE']"/>
</flow>
<flow name="post:/munit:api-config">
<set-payload doc:name="Set Payload" value="#['POST RESPONSE']"/>
</flow>
<flow name="get:/munit:api-config">
<vm:inbound-endpoint exchange-pattern="request-response" path="path" doc:name="service name"/>
/////////////////////
CODE HERE
<db:select config-ref="dbweb" doc:name="select items">
<db:parameterized-query><![CDATA[SELECT A, B, C FROM TABLE]]></db:parameterized-query>
</db:select>
/////////////////////
<set-payload doc:name="Set Payload" value="#['GET RESPONSE']"/>
</flow>