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

Mule Munit测试用例未从Maven命令行运行,maven,mule,munit,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="

我已经为我的一个流编写了一个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>

有人能解决这个问题吗?

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

我添加了DB连接器模式和Maven依赖项,仍然是相同的问题。我添加了这个依赖项。这是必需的吗?com.mulesoft.muleesb.transports mule transport jdbc ee${mule.version}没有提供,那就是对于旧的jdbc传输,使用这个:
org.mule.modules mule module db${mule.version}compile
在我添加
mule module db
依赖项之后,有关
db:insert
的问题得到了解决。最后,我又遇到了一个关于dataweave的问题(实际流使用dataweave transformer),即,
dw:transform
是无效元素。我想我需要添加相关的依赖项。你能告诉我依赖关系吗?只是为了完成:这对我来说很有帮助:
com.mulesoft.weave
mule-plugin-weave_2.11

<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>
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)