【问题标题】:Mule Munit Test cases not running from Maven command lineMule Munit 测试用例未从 Maven 命令行运行
【发布时间】:2016-01-25 08:20:15
【问题描述】:

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

谁能解决这个问题?

【问题讨论】:

    标签: maven mule munit


    【解决方案1】:

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

    【讨论】:

    • 我为 DB 连接器添加了模式以及 maven 依赖项,仍然是同样的问题。我添加了这个依赖。是必需的吗? com.mulesoft.muleesb.transportsmule-transport-jdbc-ee${mule.version}提供范围> 依赖>
    • 不,那是旧的 JDBC 传输,使用这个:&lt;dependency&gt; &lt;groupId&gt;org.mule.modules&lt;/groupId&gt; &lt;artifactId&gt;mule-module-db&lt;/artifactId&gt; &lt;version&gt;${mule.version}&lt;/version&gt; &lt;scope&gt;compile&lt;/scope&gt; &lt;/dependency&gt;
    • 在我添加了mule-module-db 依赖后,关于db:insert 的问题得到了解决。我又遇到了一个关于 dataweave 的问题(实际流程使用 dataweave 转换器),即dw:transform 是无效元素。我想我需要添加相关的依赖项。能否请您让我依赖?
    • 只是为了完成:这对我有用:&lt;dependency&gt;&lt;groupId&gt;com.mulesoft.weave&lt;/groupId&gt;&lt;artifactId&gt;mule-plugin-weave_2.11&lt;/artifactId&gt;&lt;/dependency&gt;
    猜你喜欢
    • 1970-01-01
    • 2016-05-02
    • 2020-10-30
    • 2017-12-18
    • 1970-01-01
    • 2016-10-12
    • 2014-04-23
    • 2011-01-15
    • 1970-01-01
    相关资源
    最近更新 更多