Reputation: 1955
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>
Upvotes: 0
Views: 1515
Reputation: 1955
For a basic oracle example :
<?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>
Upvotes: 0
Reputation: 5128
I don't know which version of Mule you are using but I will assume is a recent one.
Often all the problem related to invalid content just when running Maven test are due to missing maven dependency.
In fact most of this module are provided, this means they are present on mule already so even if they are not in your POM the application will run on the standalone server and even if deployed. This is not true when running tests, the mule server used in maven tests is a lightweight one without batteries included so you need to specify really all the dependencies.
So the short answer is that you are probally missing this dependency on pom:
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-db</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
Anyway just for completeness please not that the oracle configuration has been deprecated and you should use instead the generic db configuration.
<db:generic-config name="Generic_Database_Configuration" doc:name="Generic Database Configuration" url="asdasdasd"/>
Anyway if you still want to use the deprecated configuration and you are running a Mule Enterprise Edition you should also note that in the latest version is part of the mule-transport-jdbc-ee module therefore in your pom you should have this dependency
<dependency>
<groupId>com.mulesoft.muleesb.transports</groupId>
<artifactId>mule-transport-jdbc-ee</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
</dependency>
and the xml conf will look like
<jdbc-ee:oracle-data-source name="Oracle_Data_Source" password="" url="jdbc:oracle:thin:@//localhost:1521/[instanceName]" transactionIsolation="UNSPECIFIED" doc:name="Oracle Data Source"/>
Hope this helps.
Upvotes: 1