代码之家  ›  专栏  ›  技术社区  ›  Ratha

Munit4抛出“org.springframework.beans.factory.BeanCreationException:创建名为'(内部bean)#1679456e'的bean时出错”

  •  0
  • Ratha  · 技术社区  · 4 年前

    我试图在munit测试中模拟一个变量;

     <munit:behavior >
                <set-payload value='xxxxx' doc:name="Set Payload" doc:id="597412dc-64c7-45e0-87c5-2e8ce3dd967e" mimeType="application/json"/>
    
    
         <munit-tools:mock-when doc:name="Mock when" doc:id="fe3ee162-0a52-4b4d-a5bf-127b42b7f6b6" processor="set-variable">
                            <munit-tools:with-attributes >
                                <munit-tools:with-attribute whereValue="ClientId" attributeName="doc:name" />
                                <munit-tools:with-attribute whereValue="clientid" attributeName="variableName" />
                            </munit-tools:with-attributes>
                            <munit-tools:then-return >
                                <munit-tools:variables >
                                    <munit-tools:variable key="clientid" value="ss" />
                                </munit-tools:variables>
                            </munit-tools:then-return>
                        </munit-tools:mock-when>
        </munit:behavior>
        <munit:execution >
                    <flow-ref doc:name="Flow-ref to post:\raml-main" doc:id="de9bf3d4-cd3f-42e1-89cf-621c3852634e" name="raml-main"/>
                </munit:execution>
                <munit:validation >
                    <munit-tools:assert-that doc:name="Assert that" doc:id="292449c4-51e6-4135-afba-c56016b5ef7d" is="#[MunitTools::equalTo(200)]" expression="#[vars.httpStatus]" message="Different status code"/>
                </munit:validation>
    

    但当我运行测试时; 我明白了;

    caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1679456e': FactoryBean threw exception on object creation; nested exception is org.mule.runtime.core.api.config.ConfigurationException: Element 'ss' is not defined in the Mule Registry
        at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:185) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
        at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:137) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:302) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    
    ...........
    
    Caused by: org.mule.runtime.core.api.config.ConfigurationException: Element 'ss' is not defined in the Mule Registry
    

    为什么?我选择了一个流进行测试。我的测试有测试属性文件,它正在工作。 我定义为:;

    为什么我不能模拟变量?

    0 回复  |  直到 4 年前
        1
  •  1
  •   K. Aeschliman    4 年前

    我刚刚偶然发现了你的问题。我一直在研究同样的问题。我相信如果你使用value=“#[”ss“]”,它会奏效。我试图将200放入一个名为httpStatus的变量中,这似乎对我有效。

                    <munit-tools:variables >
                        <munit-tools:variable key="httpStatus" value="#[200]" />
                    </munit-tools:variables>    
    
        2
  •  1
  •   vennapu    4 年前

    以下方法对我有效。我使用mule 4.3和munit2。

    <munit-tools:variables >
      <munit-tools:variable key="clientid" value='#["ss"]' />
    </munit-tools:variables>