Mule Munit测试用例未从Maven命令行运行

时间:2015-10-26 09:25:35

标签: maven mule munit

我为我的一个流程写了一个Munit测试,其中有数据库插入。以下是流程:

<sub-flow name="AddCustomerSubFlow">
        <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>
        <set-variable variableName="originalPayload" value="#[payload]" doc:name="saveOriginalPayload" />
        <db:insert config-ref="MySQL_Configuration" doc:name="insertCustomer" autoGeneratedKeys="true" autoGeneratedKeysColumnIndexes="1">
            <db:parameterized-query>
            <![CDATA[INSERT INTO CUSTOMER (
                NAME,
                AGE,
                LINE1,
                LINE2,
                CITY,
                STATE,
                PINCODE 
            ) VALUES (
                #[payload.customer.name],
                #[payload.customer.age],
                #[payload.customer.address.line1],
                #[payload.customer.address.line2],
                #[payload.customer.address.city],
                #[payload.customer.address.state],
                #[payload.customer.address.pincode]
            )]]>
            </db:parameterized-query>
        </db:insert>
        <dw:transform-message doc:name="buildResponse">
            <dw:set-payload>
            <![CDATA[%dw 1.0
                %input payload application/java
                %output application/json
                ---
                {
                    "customer": {
                        "id": payload[0].generated_key,
                        "name": flowVars.originalPayload.customer.name,
                        "age": flowVars.originalPayload.customer.age,
                        "address": {
                            "line1": flowVars.originalPayload.customer.address.line1,
                            "line2": flowVars.originalPayload.customer.address.line2,
                            "city": flowVars.originalPayload.customer.address.city,
                            "state": flowVars.originalPayload.customer.address.state,
                            "pincode": flowVars.originalPayload.customer.address.pincode
                        }
                    }
                }]]>
            </dw:set-payload>
        </dw:transform-message>
        <logger message="#[payload]" level="INFO" doc:name="logPayload"/>
</sub-flow>

测试用例是:

<munit:config name="munit" doc:name="MUnit configuration" />
<spring:beans>
    <spring:import resource="classpath:AddCustomerSubFlow.xml" />
    <spring:import resource="classpath:GlobalElements.xml" />
</spring:beans>
<munit:test name="AddCustomerSubFlowTest" description="To test the creation new Customer">
    <mock:when messageProcessor=".*:.*" doc:name="mockDBInsert">
        <mock:with-attributes>
            <mock:with-attribute name="doc:name" whereValue="#['insertCustomer']" />
        </mock:with-attributes>
        <mock:then-return payload="#[[[&quot;generated_key&quot;: 1]]]" />
    </mock:when>
    <munit:set payload="#[getResource(&quot;examples/customer_post_request.json&quot;).asString()]" doc:name="setRequestMsg" />
    <flow-ref name="AddCustomerSubFlow" doc:name="invokeAddCustomerSubFlow" />
    <mock:verify-call messageProcessor=".*:.*" doc:name="verifyDBInsert">
        <mock:with-attributes>
            <mock:with-attribute name="doc:name" whereValue="#['insertCustomer']" />
        </mock:with-attributes>
    </mock:verify-call>
    <object-to-string-transformer doc:name="Object to String" />
    <json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object" />
    <munit:assert-on-equals expectedValue="#[1]" actualValue="#[payload.customer.id]" doc:name="assertId" />
</munit:test>

测试用例在Studio中正常运行。但是当我尝试使用mvn clean test从maven命令行运行此测试用例时,出现了错误:

Caused by: org.mule.api.config.ConfigurationException: Configuration problem: Failed to import bean definitions from URL location [classpath:AddCustomerSubFlow.xml]
Offending resource: URL [file:/D:/codebase/mule/sunguard-session/target/test-classes/AddCustomerSubFlowTest.xml]; nested exception is org.springframework.beans.factory.xm
l.XmlBeanDefinitionStoreException: Line 14 in XML document from class path resource [AddCustomerSubFlow.xml] is invalid; nested exception is org.xml.sax.SAXParseException
; lineNumber: 14; columnNumber: 133; cvc-complex-type.2.4.a: Invalid content was found starting with element 'db:insert'. One of '{"http://www.mulesoft.org/schema/mule/co
re":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-m
essage-processor}' is expected. (org.mule.api.lifecycle.InitialisationException)

有人可以解决问题吗?

1 个答案:

答案 0 :(得分:2)

有两个选项,或者您没有将DB连接器架构添加到您没有将DB连接器jar添加为Maven依赖项的测试配置中。