I've created a project using the apikit-with-munit example project.
I mavenized my project and now have 1 app file called api.xml and 1 api-test-suite.xml file. I'm trying to add a db reference in my test and I'm coming across the following error when launching my tests when launching the test from Maven only.
When launching my tests from Anypoint Studio, My MUnit works fine.
I dont't know what is wrong with my config... I suspect my problem is related to my namespaces Can someone point out what I'm doing wrong?
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]
[ERROR] Offending resource: URL [file:/C:/Workspaces/Coverage1/testing-apikit-with-munit_1.3.3-1/target/test-classes/api-test-suite.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 40 in XML document from class path resource [api.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 40; columnNumber: 101; cvc-complex-type.2.4.a: Invalid content was found starting with element '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)
my api.xml file:
<?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>
my api-test-suite.xml file:
<?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>